(saved_model_dir, input_shapes,
                                       representative_dataset,
                                       calibrated_tflite_file)
Convert SavedModel to int8 quantized TF Lite format.

  Args:
    saved_model_dir: str, path to the SavedModel directory.
    input_shapes: dict, input shapes of the SavedModel.
    representative_dataset: function, generator function to feed to
      TFLiteConverter
    calibrated_tflite_file: str, path to export the full int8 quantized TF Lite
      model.
  Returns: (str, str) Path to the exported style predict and style transform
    SavedModel.
Convert SavedModel to int8 quantized TF Lite format.
Convert SavedModel to int8 quantized TF Lite format .
def convert_saved_model_to_int8_tflite(saved_model_dir, input_shapes,
                                       representative_dataset,
                                       calibrated_tflite_file):
  """Convert SavedModel to int8 quantized TF Lite format.

  Args:
    saved_model_dir: str, path to the SavedModel directory.
    input_shapes: dict, input shapes of the SavedModel.
    representative_dataset: function, generator function to feed to
      TFLiteConverter
    calibrated_tflite_file: str, path to export the full int8 quantized TF Lite
      model.
  Returns: (str, str) Path to the exported style predict and style transform
    SavedModel.
  """

  converter = tf.lite.TFLiteConverter.from_saved_model(
      saved_model_dir=saved_model_dir, input_shapes=input_shapes)

  converter.optimizations = [tf.lite.Optimize.DEFAULT]
  converter.representative_dataset = representative_dataset

  tflite_full_int8_quantize_model = converter.convert()
  with tf.gfile.GFile(calibrated_tflite_file, 'wb') as f:
    f.write(tflite_full_int8_quantize_model)

  tf.logging.info(
      'Converted to TF Lite full integer quantized model: %s; Size: %d KB.' %
      (calibrated_tflite_file, len(tflite_full_int8_quantize_model) / 1024))
def convert_saved_model_to_int8_tflite ( saved_model_dir , input_shapes , representative_dataset , calibrated_tflite_file ) : converter = tf . lite . TFLiteConverter . from_saved_model ( saved_model_dir = saved_model_dir , input_shapes = input_shapes ) converter . optimizations = [ tf . lite . Optimize . DEFAULT ] converter . representative_dataset = representative_dataset tflite_full_int8_quantize_model = converter . convert ( ) with tf . gfile . GFile ( calibrated_tflite_file , 'wb' ) as f : f . write ( tflite_full_int8_quantize_model ) tf . logging . info ( 'Converted to TF Lite full integer quantized model: %s; Size: %d KB.' % ( calibrated_tflite_file , len ( tflite_full_int8_quantize_model ) / 1024 ) )