(saved_model_dir, num_styles, image_size, quantize,
                       output_model)
Convert a image stylization saved model to TensorFlow Lite format.
Convert a image stylization saved model to TensorFlow Lite format.
Convert a image stylization saved model to TensorFlow Lite format .
def _convert_to_tflite(saved_model_dir, num_styles, image_size, quantize,
                       output_model):
  """Convert a image stylization saved model to TensorFlow Lite format."""
  # Append filename if output_model is a directory name
  if tf.io.gfile.isdir(output_model):
    if quantize:
      filename = 'stylize_quantized.tflite'
    else:
      filename = 'stylize.tflite'
    output_model = os.path.join(output_model, filename)

  # Initialize TF Lite Converter
  converter = tf.lite.TFLiteConverter.from_saved_model(
      saved_model_dir=saved_model_dir,
      input_shapes={
          'input_image': [None, image_size, image_size, 3],
          'style_weights': num_styles
      })

  # Specify quantization option
  if quantize:
    converter.optimizations = [tf.lite.Optimize.DEFAULT]

  # Convert and save the TF Lite model
  tflite_model = converter.convert()
  with tf.io.gfile.GFile(output_model, 'wb') as f:
    f.write(tflite_model)
  tf.logging.info('Converted to TF Lite model: %s; Size: %d KB.' %
                  (output_model, len(tflite_model) / 1024))
def _convert_to_tflite ( saved_model_dir , num_styles , image_size , quantize , output_model ) : # Append filename if output_model is a directory name if tf . io . gfile . isdir ( output_model ) : if quantize : filename = 'stylize_quantized.tflite' else : filename = 'stylize.tflite' output_model = os . path . join ( output_model , filename ) # Initialize TF Lite Converter converter = tf . lite . TFLiteConverter . from_saved_model ( saved_model_dir = saved_model_dir , input_shapes = { 'input_image' : [ None , image_size , image_size , 3 ] , 'style_weights' : num_styles } ) # Specify quantization option if quantize : converter . optimizations = [ tf . lite . Optimize . DEFAULT ] # Convert and save the TF Lite model tflite_model = converter . convert ( ) with tf . io . gfile . GFile ( output_model , 'wb' ) as f : f . write ( tflite_model ) tf . logging . info ( 'Converted to TF Lite model: %s; Size: %d KB.' % ( output_model , len ( tflite_model ) / 1024 ) )