nas-search/search_main.py
def export(est, export_dir, post_quantize=True):
  """Export graph to SavedModel and TensorFlow Lite.

  Args:
    est: estimator instance.
    export_dir: string, exporting directory.
    post_quantize: boolean, whether to quantize model checkpoint after training.

  Raises:
    ValueError: the export directory path is not specified.
  """
  if not export_dir:
    raise ValueError('The export directory path is not specified.')
  # The guide to serve a exported TensorFlow model is at:
  #    https://www.tensorflow.org/serving/serving_basic
  def lite_image_serving_input_fn():
    """serving input fn for raw images."""
    input_shape = [1, FLAGS.input_image_size, FLAGS.input_image_size, 3]
    images = tf.placeholder(shape=input_shape, dtype=tf.float32)
    return tf.estimator.export.ServingInputReceiver(images, {'images': images})

  tf.logging.info('Starting to export model.')
  est.export_saved_model(
      export_dir_base=export_dir,
      serving_input_receiver_fn=lite_image_serving_input_fn)

  subfolder = sorted(tf.gfile.ListDirectory(export_dir), reverse=True)[0]
  tf.logging.info('Starting to export TFLite.')
  converter = tf.lite.TFLiteConverter.from_saved_model(
      os.path.join(export_dir, subfolder),
      input_arrays=['truediv'],
      output_arrays=['logits'])
  tflite_model = converter.convert()
  tflite_file = os.path.join(export_dir, FLAGS.model_name + '.tflite')
  tf.gfile.GFile(tflite_file, 'wb').write(tflite_model)

  if post_quantize:
    tf.logging.info('Starting to export quantized TFLite.')
    converter = tf.lite.TFLiteConverter.from_saved_model(
        os.path.join(export_dir, subfolder),
        input_arrays=['truediv'],
        output_arrays=['logits'])
    converter.post_training_quantize = True
    quant_tflite_model = converter.convert()
    quant_tflite_file = os.path.join(export_dir,
                                     FLAGS.model_name + '_postquant.tflite')
    tf.gfile.GFile(quant_tflite_file, 'wb').write(quant_tflite_model)
Export graph to SavedModel and TensorFlow Lite.

  Args:
    est: estimator instance.
    export_dir: string, exporting directory.
    post_quantize: boolean, whether to quantize model checkpoint after training.

  Raises:
    ValueError: the export directory path is not specified.
  
Export graph to SavedModel and TensorFlow Lite.
Export graph to SavedModel and TensorFlow Lite .
def export(est, export_dir, post_quantize=True):
  if not export_dir:
    raise ValueError('The export directory path is not specified.')
  def lite_image_serving_input_fn():
    input_shape = [1, FLAGS.input_image_size, FLAGS.input_image_size, 3]
    images = tf.placeholder(shape=input_shape, dtype=tf.float32)
    return tf.estimator.export.ServingInputReceiver(images, {'images': images})
  tf.logging.info('Starting to export model.')
  est.export_saved_model(
      export_dir_base=export_dir,
      serving_input_receiver_fn=lite_image_serving_input_fn)
  subfolder = sorted(tf.gfile.ListDirectory(export_dir), reverse=True)[0]
  tf.logging.info('Starting to export TFLite.')
  converter = tf.lite.TFLiteConverter.from_saved_model(
      os.path.join(export_dir, subfolder),
      input_arrays=['truediv'],
      output_arrays=['logits'])
  tflite_model = converter.convert()
  tflite_file = os.path.join(export_dir, FLAGS.model_name + '.tflite')
  tf.gfile.GFile(tflite_file, 'wb').write(tflite_model)
  if post_quantize:
    tf.logging.info('Starting to export quantized TFLite.')
    converter = tf.lite.TFLiteConverter.from_saved_model(
        os.path.join(export_dir, subfolder),
        input_arrays=['truediv'],
        output_arrays=['logits'])
    converter.post_training_quantize = True
    quant_tflite_model = converter.convert()
    quant_tflite_file = os.path.join(export_dir,
                                     FLAGS.model_name + '_postquant.tflite')
    tf.gfile.GFile(quant_tflite_file, 'wb').write(quant_tflite_model)
def export ( est , export_dir , post_quantize = True ) : if not export_dir : raise ValueError ( 'The export directory path is not specified.' ) def lite_image_serving_input_fn ( ) : """serving input fn for raw images.""" input_shape = [ 1 , FLAGS . input_image_size , FLAGS . input_image_size , 3 ] images = tf . placeholder ( shape = input_shape , dtype = tf . float32 ) return tf . estimator . export . ServingInputReceiver ( images , { 'images' : images } ) tf . logging . info ( 'Starting to export model.' ) est . export_saved_model ( export_dir_base = export_dir , serving_input_receiver_fn = lite_image_serving_input_fn ) subfolder = sorted ( tf . gfile . ListDirectory ( export_dir ) , reverse = True ) [ 0 ] tf . logging . info ( 'Starting to export TFLite.' ) converter = tf . lite . TFLiteConverter . from_saved_model ( os . path . join ( export_dir , subfolder ) , input_arrays = [ 'truediv' ] , output_arrays = [ 'logits' ] ) tflite_model = converter . convert ( ) tflite_file = os . path . join ( export_dir , FLAGS . model_name + '.tflite' ) tf . gfile . GFile ( tflite_file , 'wb' ) . write ( tflite_model ) if post_quantize : tf . logging . info ( 'Starting to export quantized TFLite.' ) converter = tf . lite . TFLiteConverter . from_saved_model ( os . path . join ( export_dir , subfolder ) , input_arrays = [ 'truediv' ] , output_arrays = [ 'logits' ] ) converter . post_training_quantize = True quant_tflite_model = converter . convert ( ) quant_tflite_file = os . path . join ( export_dir , FLAGS . model_name + '_postquant.tflite' ) tf . gfile . GFile ( quant_tflite_file , 'wb' ) . write ( quant_tflite_model )
Export graph to SavedModel and TensorFlow Lite.
Export graph to SavedModel and TensorFlow Lite .
"""Export graph to SavedModel and TensorFlow Lite.

  Args:
    est: estimator instance.
    export_dir: string, exporting directory.
    post_quantize: boolean, whether to quantize model checkpoint after training.

  Raises:
    ValueError: the export directory path is not specified.
  """ # The guide to serve a exported TensorFlow model is at: #    https://www.tensorflow.org/serving/serving_basic """serving input fn for raw images."""
the export directory path is not specified.
the export directory path is not specified .
ValueError
est
None
export_dir
string, exporting directory.
string exporting directory .
post_quantize
boolean, whether to quantize model checkpoint after training.
boolean whether to quantize model checkpoint after training .