问题
I have a trained model (Faster R-CNN) which I exported using export_inference_graph.py
to use for inference. I'm trying to understand the difference between the created frozen_inference_graph.pb
and saved_model.pb
and also model.ckpt*
files. I've also seen .pbtxt
representations.
I tried reading through this but couldn't really find the answers: https://www.tensorflow.org/extend/tool_developers/
What do each of these files contain? Which ones can be converted to which other ones? What is the ideal purpose of each?
回答1:
frozen_inference_graph.pb, is a frozen graph that cannot be trained anymore, it defines the graphdef and is actually a serialized graph and can be loaded with this code:
def load_graph(frozen_graph_filename):
with tf.gfile.GFile(frozen_graph_filename, "rb") as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
return graph_def
tf.import_graph_def(load_graph("frozen_inference_graph.pb"))
the saved model is a model generated by tf.saved_model.builder and is has to be imported into a session, this file contains the full graph with all training weights (just like the frozen graph) but here can be trained upon, and this one is not serialized and needs to be loaded by this snippet. The [] are tagconstants which can be read by the saved_model_cli. This model is also often served to predict on, like google ml engine par example:
with tf.Session() as sess:
tf.saved_model.loader.load(sess, [], "foldername to saved_model.pb, only folder")
model.ckpt files are checkpoints, generated during training, this is used to resume training or to have a back up when something goes wrong after along training. If you have a saved model and a frozen graph, then you can ignore this.
.pbtxt files are basically the same as previous discussed models, but then human readable, not binary. These can be ignored as well.
To answer your conversion question: saved models can be transformed into a frozen graph and vice versa, although a saved_model extracted from a frozen graph is also no trainable, but the way it is stored is in saved model format. Checkpoints can be read in and loaded into a session, and there you can build a saved model from them.
Hope I helped, any questions, ask away!
回答2:
Like to add, frozen_graph.pb includes two things: 1. Graph definition 2. Trained parameters
Whereas save_model.pb, just have graph definition.
That's why if you check the size of both the .pb files, frozen_graph.pb always be larger in size.
来源:https://stackoverflow.com/questions/52934795/what-is-difference-frozen-inference-graph-pb-and-saved-model-pb