tensorflow difference between saving model via exp

2019-04-08 04:36发布

问题:

What is difference between saving a model by

  1. using exporter as specified in tensorflow serving:

eg:

from tensorflow.contrib.session_bundle import exporter
#from tensorflow_serving.session_bundle import exporter
saver = tf.train.Saver(sharded=True)
model_exporter = exporter.Exporter(saver)
model_exporter.init(
        sess.graph.as_graph_def(),
        named_graph_signatures={
            'inputs': exporter.generic_signature({'images': x}),
            'outputs': exporter.generic_signature({'scores': y})})
model_exporter.export(export_path, tf.constant(FLAGS.export_version), sess) 
  1. Using tf.train.write_graph() and tf.train.Saver() directly:

eg:

with sess.graph.as_default():
    saver = tf.train.Saver()
    saver.save(sess, path, meta_graph_suffix='meta', write_meta_graph=True)

Question is in continuation of TensorFlow saving into/loading a graph from a file

回答1:

Given the Exporter is now officially deprecated, the new protocol for saving graph and data is to use Saver. Here is an excellent blog with sample code: https://blog.metaflow.fr/tensorflow-how-to-freeze-a-model-and-serve-it-with-a-python-api-d4f3596b3adc.



回答2:

Exporter is used after you train a model and want to serve it (use it for inference).

Saver is used for checkpointing when you train a model.