Each Answer to this Q is separated by one/two green lines.
saver=tf.train.Saver() to save the model that I trained, and I get three kinds of files named:
And a file called:
What is the connection with the .ckpt file?
I saw someone saved model with only .ckpt file, I don’t know how to make it.
How can I save model as a .pb file?
the .ckpt file is the old version output of
saver.save(sess), which is the equivalent of your
the “checkpoint” file is only here to tell some TF functions which is the latest checkpoint file.
.ckpt-metacontains the metagraph, i.e. the structure of your computation graph, without the values of the variables (basically what you can see in tensorboard/graph).
.ckpt-datacontains the values for all the variables, without the structure. To restore a model in python, you’ll usually use the meta and data files with (but you can also use the
saver = tf.train.import_meta_graph(path_to_ckpt_meta) saver.restore(sess, path_to_ckpt_data)
I don’t know exactly for
.ckpt-index, I guess it’s some kind of index needed internally to map the two previous files correctly. Anyway it’s not really necessary usually, you can restore a model with only
.pbfile can save your whole graph (meta + data). To load and use (but not train) a graph in c++ you’ll usually use it, created with
freeze_graph, which creates the
.pbfile from the meta and data. Be careful, (at least in previous TF versions and for some people) the py function provided by
freeze_graphdid not work properly, so you’d have to use the script version. Tensorflow also provides a
tf.train.Saver.to_proto()method, but I don’t know what it does exactly.
There are a lot of questions here about how to save and restore a graph. See the answer here for instance, but be careful that the two cited tutorials, though really helpful, are far from perfect, and a lot of people still seem to struggle to import a model in c++.
it looks like you can also use the .ckpt files in c++ now, so I guess you don’t necessarily need the .pb file any more.