disooqi
disooqi

Reputation: 682

how to use `tf.train.Saver` class to save and restore models in Tensorflow?

I have just trained a model using Tensorflow and I want to save it and restore it later. I read the Saving and Restoring page in official documentation of Tensorflow and I stumbled by the following code to save a model

export_dir = ...
...
builder = tf.saved_model_builder.SavedModelBuilder(export_dir)
with tf.Session(graph=tf.Graph()) as sess:
  ...
  builder.add_meta_graph_and_variables(sess,
                                       [tag_constants.TRAINING],
                                       signature_def_map=foo_signatures,
                                       assets_collection=foo_assets)
...
# Add a second MetaGraphDef for inference.
with tf.Session(graph=tf.Graph()) as sess:
  ...
  builder.add_meta_graph([tag_constants.SERVING])
...
builder.save()

but I couldn't understand what are [tag_constants.TRAINING] list and [tag_constants.SERVING] list.

Upvotes: 1

Views: 433

Answers (1)

Stephen
Stephen

Reputation: 824

They seem to just be used to identify which MetaGraphDef you want to restore. The existing tags are SERVING, TRAINING, and GPU, but you can define your own using something like tf.saved_model.tag_constants.MEOW = "kitty!".

Upvotes: 1

Related Questions