MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / save

Function save

tensorflow/python/saved_model/save.py:675–880  ·  view source on GitHub ↗

Exports the Trackable object `obj` to [SavedModel format](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/saved_model/README.md). Example usage: ```python class Adder(tf.Module): @tf.function(input_signature=[tf.TensorSpec(shape=None, dtype=tf.float32)]) def a

(obj, export_dir, signatures=None)

Source from the content-addressed store, hash-verified

673@tf_export("saved_model.save",
674 v1=["saved_model.save", "saved_model.experimental.save"])
675def save(obj, export_dir, signatures=None):
676 # pylint: disable=line-too-long
677 """Exports the Trackable object `obj` to [SavedModel format](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/saved_model/README.md).
678
679 Example usage:
680
681 ```python
682 class Adder(tf.Module):
683
684 @tf.function(input_signature=[tf.TensorSpec(shape=None, dtype=tf.float32)])
685 def add(self, x):
686 return x + x + 1.
687
688 to_export = Adder()
689 tf.saved_model.save(to_export, '/tmp/adder')
690 ```
691
692 The resulting SavedModel is then servable with an input named "x", its value
693 having any shape and dtype float32.
694
695 The optional `signatures` argument controls which methods in `obj` will be
696 available to programs which consume `SavedModel`s, for example serving
697 APIs. Python functions may be decorated with
698 `@tf.function(input_signature=...)` and passed as signatures directly, or
699 lazily with a call to `get_concrete_function` on the method decorated with
700 `@tf.function`.
701
702 If the `signatures` argument is omitted, `obj` will be searched for
703 `@tf.function`-decorated methods. If exactly one `@tf.function` is found, that
704 method will be used as the default signature for the SavedModel. This behavior
705 is expected to change in the future, when a corresponding
706 `tf.saved_model.load` symbol is added. At that point signatures will be
707 completely optional, and any `@tf.function` attached to `obj` or its
708 dependencies will be exported for use with `load`.
709
710 When invoking a signature in an exported SavedModel, `Tensor` arguments are
711 identified by name. These names will come from the Python function's argument
712 names by default. They may be overridden by specifying a `name=...` argument
713 in the corresponding `tf.TensorSpec` object. Explicit naming is required if
714 multiple `Tensor`s are passed through a single argument to the Python
715 function.
716
717 The outputs of functions used as `signatures` must either be flat lists, in
718 which case outputs will be numbered, or a dictionary mapping string keys to
719 `Tensor`, in which case the keys will be used to name outputs.
720
721 Signatures are available in objects returned by `tf.saved_model.load` as a
722 `.signatures` attribute. This is a reserved attribute: `tf.saved_model.save`
723 on an object with a custom `.signatures` attribute will raise an exception.
724
725 Since `tf.keras.Model` objects are also Trackable, this function can be
726 used to export Keras models. For example, exporting with a signature
727 specified:
728
729 ```python
730 class Model(tf.keras.Model):
731
732 @tf.function(input_signature=[tf.TensorSpec(shape=[None], dtype=tf.string)])

Callers 9

testConstSavedModelMethod · 0.90
testConstModelMethod · 0.90
testVariableModelMethod · 0.90
testSignaturesMethod · 0.90
testGraphDebugInfoMethod · 0.90

Calls 11

saveMethod · 0.95
_AugmentedGraphViewClass · 0.85
_SaveableViewClass · 0.85
_fill_meta_graph_defFunction · 0.85
_serialize_object_graphFunction · 0.85
add_objectMethod · 0.80
formatMethod · 0.45
addMethod · 0.45
joinMethod · 0.45
CopyFromMethod · 0.45
SerializeToStringMethod · 0.45

Tested by 9

testConstSavedModelMethod · 0.72
testConstModelMethod · 0.72
testVariableModelMethod · 0.72
testSignaturesMethod · 0.72
testGraphDebugInfoMethod · 0.72