(saved_model_dir, input_shapes,
                                  float_tflite_file, quantized_tflite_file)
Convert SavedModel to TF Lite format.

  Also apply weight quantization to generate quantized model

  Args:
    saved_model_dir: str, path to the SavedModel directory.
    input_shapes: dict, input shapes of the SavedModel.
    float_tflite_file: str, path to export the float TF Lite model.
    quantized_tflite_file: str, path to export the weight quantized TF Lite
      model.
  Returns: (str, str) Path to the exported style predict and style transform
    SavedModel.
Convert SavedModel to TF Lite format.
Convert SavedModel to TF Lite format .
def convert_saved_model_to_tflite(saved_model_dir, input_shapes,
                                  float_tflite_file, quantized_tflite_file):
  """Convert SavedModel to TF Lite format.

  Also apply weight quantization to generate quantized model

  Args:
    saved_model_dir: str, path to the SavedModel directory.
    input_shapes: dict, input shapes of the SavedModel.
    float_tflite_file: str, path to export the float TF Lite model.
    quantized_tflite_file: str, path to export the weight 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)

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

  tf.logging.info('Converted to TF Lite float model: %s; Size: %d KB.' %
                  (float_tflite_file, len(tflite_float_model) / 1024))

  converter.optimizations = [tf.lite.Optimize.DEFAULT]
  tflite_quantize_model = converter.convert()
  with tf.gfile.GFile(quantized_tflite_file, 'wb') as f:
    f.write(tflite_quantize_model)

  tf.logging.info(
      'Converted to TF Lite weight quantized model: %s; Size: %d KB.' %
      (quantized_tflite_file, len(tflite_quantize_model) / 1024))
def convert_saved_model_to_tflite ( saved_model_dir , input_shapes , float_tflite_file , quantized_tflite_file ) : converter = tf . lite . TFLiteConverter . from_saved_model ( saved_model_dir = saved_model_dir , input_shapes = input_shapes ) tflite_float_model = converter . convert ( ) with tf . gfile . GFile ( float_tflite_file , 'wb' ) as f : f . write ( tflite_float_model ) tf . logging . info ( 'Converted to TF Lite float model: %s; Size: %d KB.' % ( float_tflite_file , len ( tflite_float_model ) / 1024 ) ) converter . optimizations = [ tf . lite . Optimize . DEFAULT ] tflite_quantize_model = converter . convert ( ) with tf . gfile . GFile ( quantized_tflite_file , 'wb' ) as f : f . write ( tflite_quantize_model ) tf . logging . info ( 'Converted to TF Lite weight quantized model: %s; Size: %d KB.' % ( quantized_tflite_file , len ( tflite_quantize_model ) / 1024 ) )