Type Builder
Namespace tensorflow.saved_model
Parent _SavedModelBuilder
Interfaces IBuilder
Builds the `SavedModel` protocol buffer and saves variables and assets. The `SavedModelBuilder` class provides functionality to build a `SavedModel`
protocol buffer. Specifically, this allows multiple meta graphs to be saved as
part of a single language-neutral `SavedModel`, while sharing variables and
assets. To build a SavedModel, the first meta graph must be saved with variables.
Subsequent meta graphs will simply be saved with their graph definitions. If
assets need to be saved and written or copied to disk, they can be provided
when the meta graph def is added. If multiple meta graph defs are associated
an asset of the same name, only the first version is retained. Each meta graph added to the SavedModel must be annotated with tags. The tags
provide a means to identify the specific meta graph to load and restore, along
with the shared set of variables and assets. Typical usage for the `SavedModelBuilder`:
Note: This function will only be available through the v1 compatibility
library as tf.compat.v1.saved_model.builder.SavedModelBuilder or
tf.compat.v1.saved_model.Builder. Tensorflow 2.0 will introduce a new
object-based method of creating SavedModels.
Show Example
... builder = tf.compat.v1.saved_model.Builder(export_dir) with tf.compat.v1.Session(graph=tf.Graph()) as sess: ... builder.add_meta_graph_and_variables(sess, ["foo-tag"], signature_def_map=foo_signatures, assets_collection=foo_assets) ... with tf.compat.v1.Session(graph=tf.Graph()) as sess: ... builder.add_meta_graph(["bar-tag", "baz-tag"]) ... builder.save()
Methods
- add_meta_graph
- add_meta_graph
- add_meta_graph
- add_meta_graph
- add_meta_graph_and_variables
- add_meta_graph_and_variables
- add_meta_graph_and_variables
- add_meta_graph_and_variables_dyn
- add_meta_graph_and_variables_dyn
- add_meta_graph_dyn
- add_meta_graph_dyn
- save
- save_dyn
Properties
Public instance methods
void add_meta_graph(IEnumerable<string> tags, IDictionary<object, object> signature_def_map, object assets_collection, object legacy_init_op, bool clear_devices, IGraphNodeBase main_op, bool strip_default_attrs, object saver)
Adds the current meta graph to the SavedModel. Creates a Saver in the current scope and uses the Saver to export the meta
graph def. Invoking this API requires the `add_meta_graph_and_variables()`
API to have been invoked before.
Parameters
-
IEnumerable<string>
tags - The set of tags to annotate the meta graph def with.
-
IDictionary<object, object>
signature_def_map - The map of signature defs to be added to the meta graph def.
-
object
assets_collection - Assets to be saved with SavedModel. Note that this list should be a subset of the assets saved as part of the first meta graph in the SavedModel.
-
object
legacy_init_op -
bool
clear_devices - Set to true if the device info on the default graph should be cleared.
-
IGraphNodeBase
main_op -
bool
strip_default_attrs -
object
saver - An instance of tf.compat.v1.train.Saver that will be used to export the metagraph. If None, a sharded Saver that restores all variables will be used.
void add_meta_graph(IEnumerable<string> tags, IDictionary<object, object> signature_def_map, object assets_collection, object legacy_init_op, bool clear_devices, IGraphNodeBase main_op, Saver strip_default_attrs, object saver)
Adds the current meta graph to the SavedModel. Creates a Saver in the current scope and uses the Saver to export the meta
graph def. Invoking this API requires the `add_meta_graph_and_variables()`
API to have been invoked before.
Parameters
-
IEnumerable<string>
tags - The set of tags to annotate the meta graph def with.
-
IDictionary<object, object>
signature_def_map - The map of signature defs to be added to the meta graph def.
-
object
assets_collection - Assets to be saved with SavedModel. Note that this list should be a subset of the assets saved as part of the first meta graph in the SavedModel.
-
object
legacy_init_op -
bool
clear_devices - Set to true if the device info on the default graph should be cleared.
-
IGraphNodeBase
main_op -
Saver
strip_default_attrs -
object
saver - An instance of tf.compat.v1.train.Saver that will be used to export the metagraph. If None, a sharded Saver that restores all variables will be used.
void add_meta_graph(IEnumerable<string> tags, IDictionary<object, object> signature_def_map, object assets_list, bool clear_devices, object init_op, IGraphNodeBase train_op, bool saver)
void add_meta_graph(IEnumerable<string> tags, IDictionary<object, object> signature_def_map, object assets_list, bool clear_devices, object init_op, IGraphNodeBase train_op, Saver saver)
void add_meta_graph_and_variables(Session sess, IEnumerable<string> tags, IDictionary<object, object> signature_def_map, IEnumerable<object> assets_collection, Nullable<bool> legacy_init_op, Nullable<bool> clear_devices, Operation main_op, bool strip_default_attrs, Saver saver)
Adds the current meta graph to the SavedModel and saves variables. Creates a Saver to save the variables from the provided session. Exports the
corresponding meta graph def. This function assumes that the variables to be
saved have been initialized. For a given `SavedModelBuilder`, this API must
be called exactly once and for the first meta graph to save. For subsequent
meta graph defs to be added, the `add_meta_graph()` API must be used.
Parameters
-
Session
sess - The TensorFlow session from which to save the meta graph and variables.
-
IEnumerable<string>
tags - The set of tags with which to save the meta graph.
-
IDictionary<object, object>
signature_def_map - The map of signature def map to add to the meta graph def.
-
IEnumerable<object>
assets_collection - Assets to be saved with SavedModel.
-
Nullable<bool>
legacy_init_op -
Nullable<bool>
clear_devices - Set to true if the device info on the default graph should be cleared.
-
Operation
main_op -
bool
strip_default_attrs - Boolean. If `True`, default-valued attributes will be removed from the NodeDefs. For a detailed guide, see [Stripping Default-Valued Attributes](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/saved_model/README.md#stripping-default-valued-attributes).
-
Saver
saver - An instance of tf.compat.v1.train.Saver that will be used to export the metagraph and save variables. If None, a sharded Saver that restores all variables will be used.
void add_meta_graph_and_variables(Session sess, IEnumerable<string> tags, IDictionary<object, object> signature_def_map, IEnumerable<object> assets_collection, Nullable<bool> legacy_init_op, Nullable<bool> clear_devices, IGraphNodeBase main_op, bool strip_default_attrs, Saver saver)
Adds the current meta graph to the SavedModel and saves variables. Creates a Saver to save the variables from the provided session. Exports the
corresponding meta graph def. This function assumes that the variables to be
saved have been initialized. For a given `SavedModelBuilder`, this API must
be called exactly once and for the first meta graph to save. For subsequent
meta graph defs to be added, the `add_meta_graph()` API must be used.
Parameters
-
Session
sess - The TensorFlow session from which to save the meta graph and variables.
-
IEnumerable<string>
tags - The set of tags with which to save the meta graph.
-
IDictionary<object, object>
signature_def_map - The map of signature def map to add to the meta graph def.
-
IEnumerable<object>
assets_collection - Assets to be saved with SavedModel.
-
Nullable<bool>
legacy_init_op -
Nullable<bool>
clear_devices - Set to true if the device info on the default graph should be cleared.
-
IGraphNodeBase
main_op -
bool
strip_default_attrs - Boolean. If `True`, default-valued attributes will be removed from the NodeDefs. For a detailed guide, see [Stripping Default-Valued Attributes](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/saved_model/README.md#stripping-default-valued-attributes).
-
Saver
saver - An instance of tf.compat.v1.train.Saver that will be used to export the metagraph and save variables. If None, a sharded Saver that restores all variables will be used.
void add_meta_graph_and_variables(Session sess, IEnumerable<string> tags, IDictionary<object, object> signature_def_map, IEnumerable<object> assets_collection, Nullable<bool> legacy_init_op, Nullable<bool> clear_devices, object main_op, bool strip_default_attrs, Saver saver)
Adds the current meta graph to the SavedModel and saves variables. Creates a Saver to save the variables from the provided session. Exports the
corresponding meta graph def. This function assumes that the variables to be
saved have been initialized. For a given `SavedModelBuilder`, this API must
be called exactly once and for the first meta graph to save. For subsequent
meta graph defs to be added, the `add_meta_graph()` API must be used.
Parameters
-
Session
sess - The TensorFlow session from which to save the meta graph and variables.
-
IEnumerable<string>
tags - The set of tags with which to save the meta graph.
-
IDictionary<object, object>
signature_def_map - The map of signature def map to add to the meta graph def.
-
IEnumerable<object>
assets_collection - Assets to be saved with SavedModel.
-
Nullable<bool>
legacy_init_op -
Nullable<bool>
clear_devices - Set to true if the device info on the default graph should be cleared.
-
object
main_op -
bool
strip_default_attrs - Boolean. If `True`, default-valued attributes will be removed from the NodeDefs. For a detailed guide, see [Stripping Default-Valued Attributes](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/saved_model/README.md#stripping-default-valued-attributes).
-
Saver
saver - An instance of tf.compat.v1.train.Saver that will be used to export the metagraph and save variables. If None, a sharded Saver that restores all variables will be used.
object add_meta_graph_and_variables_dyn(object sess, object tags, object signature_def_map, object assets_collection, object legacy_init_op, ImplicitContainer<T> clear_devices, object main_op, ImplicitContainer<T> strip_default_attrs, object saver)
Adds the current meta graph to the SavedModel and saves variables. Creates a Saver to save the variables from the provided session. Exports the
corresponding meta graph def. This function assumes that the variables to be
saved have been initialized. For a given `SavedModelBuilder`, this API must
be called exactly once and for the first meta graph to save. For subsequent
meta graph defs to be added, the `add_meta_graph()` API must be used.
Parameters
-
object
sess - The TensorFlow session from which to save the meta graph and variables.
-
object
tags - The set of tags with which to save the meta graph.
-
object
signature_def_map - The map of signature def map to add to the meta graph def.
-
object
assets_collection - Assets to be saved with SavedModel.
-
object
legacy_init_op -
ImplicitContainer<T>
clear_devices - Set to true if the device info on the default graph should be cleared.
-
object
main_op -
ImplicitContainer<T>
strip_default_attrs - Boolean. If `True`, default-valued attributes will be removed from the NodeDefs. For a detailed guide, see [Stripping Default-Valued Attributes](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/saved_model/README.md#stripping-default-valued-attributes).
-
object
saver - An instance of tf.compat.v1.train.Saver that will be used to export the metagraph and save variables. If None, a sharded Saver that restores all variables will be used.
object add_meta_graph_and_variables_dyn(object sess, object tags, object signature_def_map, object assets_list, ImplicitContainer<T> clear_devices, object init_op, object train_op, ImplicitContainer<T> strip_default_attrs, object saver)
object add_meta_graph_dyn(object tags, object signature_def_map, object assets_collection, object legacy_init_op, ImplicitContainer<T> clear_devices, object main_op, ImplicitContainer<T> strip_default_attrs, object saver)
Adds the current meta graph to the SavedModel. Creates a Saver in the current scope and uses the Saver to export the meta
graph def. Invoking this API requires the `add_meta_graph_and_variables()`
API to have been invoked before.
Parameters
-
object
tags - The set of tags to annotate the meta graph def with.
-
object
signature_def_map - The map of signature defs to be added to the meta graph def.
-
object
assets_collection - Assets to be saved with SavedModel. Note that this list should be a subset of the assets saved as part of the first meta graph in the SavedModel.
-
object
legacy_init_op -
ImplicitContainer<T>
clear_devices - Set to true if the device info on the default graph should be cleared.
-
object
main_op -
ImplicitContainer<T>
strip_default_attrs -
object
saver - An instance of tf.compat.v1.train.Saver that will be used to export the metagraph. If None, a sharded Saver that restores all variables will be used.