SavedModel is the universal serialization format for TensorFlow models.
SavedModel provides a language-neutral format to save machine-learning models that is recoverable and hermetic. It enables higher-level systems and tools to produce, consume and transform TensorFlow models.
tf.saved_model.save
tf.saved_model.load
tf.saved_model.SaveOptions
tf.saved_model.LoadOptions
tf.saved_model.Asset
tf.saved_model.contains_saved_model
A SavedModel directory has the following structure:
assets/ assets.extra/ variables/ variables.data-?????-of-????? variables.index saved_model.pb
saved_model.pb
or saved_model.pbtxt
MetaGraphDef
protocol buffers.assets
.variables
.variables.data-?????-of-?????
variables.index
The SavedModelBuilder class allows users to control whether default-valued attributes must be stripped from the NodeDefs while adding a meta graph to the SavedModel bundle. Both SavedModelBuilder.add_meta_graph_and_variables
and SavedModelBuilder.add_meta_graph
methods accept a Boolean flag strip_default_attrs
that controls this behavior.
If strip_default_attrs
is False
, the exported MetaGraphDef will have the default valued attributes in all it's NodeDef instances. This can break forward compatibility with a sequence of events such as the following:
Foo
) is updated to include a new attribute (T
) with a default (bool
) at version 101.Foo
.T
for Op Foo
, but tries to import this model. The model consumer doesn’t recognize attribute T
in a NodeDef that uses Op Foo
and therefore fails to load the model.By setting strip_default_attrs
to True
, the model producers can strip away any default valued attributes in the NodeDefs. This helps ensure that newly added attributes with defaults don't cause older model consumers to fail loading models regenerated with newer training binaries.
TIP: If you care about forward compatibility, then set strip_default_attrs
to True
while using SavedModelBuilder.add_meta_graph_and_variables
and SavedModelBuilder.add_meta_graph
.