From SavedModel Docs,
SavedModel, the universal serialization format for TensorFlow models.
and
SavedModel wraps a TensorFlow Saver. The Saver is primarily used to generate the variable checkpoints.
From my understanding, SavedModel
is must if someone wants use TensorFlow Serving. However, I can deploy Tensorflow Model to service server without SavedModel
: Freeze graph and export it as GraphDef
, and load graph into Session using ReadBinaryProto
and Create in C++ or Import in Go.
What is the purpose of SavedModel? Should users prefer SavedModel over Checkpoint or GraphDef to aggregate more data related to the model?
A checkpoint contains the value of (some of the) variables in a TensorFlow model. It is created by a Saver
, which is either given specific Variable
s to save, or by default saves all (non-local) Variables.
To use a checkpoint, you need to have a compatible TensorFlow Graph
, whose Variable
s have the same names as the Variable
s in the checkpoint. (If you don't have a compatible Graph
, you can still load the values stored in a checkpoint into selected Variable
s using the init_from_checkpoint
utilities in contrib.)
SavedModel
is much more comprehensive: It contains a set of Graph
s (MetaGraph
s, in fact, saving collections and such), as well as a checkpoint which is supposed to be compatible with these Graph
s, and any asset files that are needed to run the model (e.g. Vocabulary files). For each MetaGraph
it contains, it also stores a set of signatures. Signatures define (named) input and output tensors.
This means that given only a SavedModel, you can write tools (such as tensorflow/serving
, or the new saved_model
command line utility that will appear in tools/
shortly) that interpret or execute the graphs inside. All you have to provide is the data.
If in doubt, I would always err on the side of writing a SavedModel
, not just a checkpoint. Not only does this allow you to use tensorflow/serving (and other neat utilities that will grow in number), it makes sure that you have all the information necessary to run the model. Nothing is more frustrating than a checkpoint you cannot use any more because you modified your model and now it is incompatible with checkpoint files and all you want to do is run some predictions through it for comparison.
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