Question:
Tensorflow Saver ,Exporter, SavedModelBuilder can all be used for save models. According to https://stackoverflow.com/questions/41740101/tensorflow-difference-between-saving-model-via-exporter-and-tf-train-write-graph, and tensor flow serving, I understand that Saver is used for saving training checkpoints and Exporter and SavedModelBuilder are used for serving.
However,I don't know the differences of their outputs. Are variable.data-???-of--??? and variable.index files generated by SavedModelBuilder the same as cpkt-xxx.index and cpkt-xxx.data-???-of-??? generated by Saver?
I still feel confused about the meaning of the model files of tensorflow. I've read http://cv-tricks.com/tensorflow-tutorial/save-restore-tensorflow-models-quick-complete-tutorial/ and Tensorflow: how to save/restore a model? which makes me feel more confused.
There are 4 files in the model directory:
File 2 and 4 store the weights of variables. File 3 stores the graph. Then what does 1 store?
How can I convert the outputs of Saver to SavedModelBuilder. I have the checkpoints directory and want to export the model for serving. According to https://github.com/tensorflow/tensorflow/tree/master/tensorflow/python/saved_model
it should be like this
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,
[tf.saved_model.tag_constants.TRAINING],
signature_def_map=foo_signatures,
assets_collection=foo_assets)
...
with tf.Session(graph=tf.Graph()) as sess:
...
builder.add_meta_graph(["bar-tag", "baz-tag"])
...
builder.save()
So, I first need to load the checkpoints with :
saver = tf.train.import_meta_graph('model-number.meta')
saver.restore(sess, tf.train.latest_checkpoint('./'))
And then use this sess
for builder.
Am I right?
SavedModel is the format used for serving, created via SavedModelBuilder. The best practice is to have your training code invoke SavedModelBuilder, and to feed the resulting output files to TF-Serving. If you do that you don't need to understand the details of what files are produced :)
The document at [1] talks about the structure of the files inside a SavedModel directory.
[1] https://www.tensorflow.org/programmers_guide/saved_model
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With