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

Function simple_save

tensorflow/python/saved_model/simple_save.py:35–92  ·  view source on GitHub ↗

Convenience function to build a SavedModel suitable for serving. In many common cases, saving models for serving will be as simple as: simple_save(session, export_dir, inputs={"x": x, "y": y}, outputs={"z": z}) Although in many cases

(session, export_dir, inputs, outputs,
                legacy_init_op=None, save_incr_model=False)

Source from the content-addressed store, hash-verified

33 'This function will only be available through the v1 compatibility '
34 'library as tf.compat.v1.saved_model.simple_save.')
35def simple_save(session, export_dir, inputs, outputs,
36 legacy_init_op=None, save_incr_model=False):
37 """Convenience function to build a SavedModel suitable for serving.
38
39 In many common cases, saving models for serving will be as simple as:
40
41 simple_save(session,
42 export_dir,
43 inputs={"x": x, "y": y},
44 outputs={"z": z})
45
46 Although in many cases it's not necessary to understand all of the many ways
47 to configure a SavedModel, this method has a few practical implications:
48 - It will be treated as a graph for inference / serving (i.e. uses the tag
49 `saved_model.SERVING`)
50 - The SavedModel will load in TensorFlow Serving and supports the
51 [Predict
52 API](https://github.com/tensorflow/serving/blob/master/tensorflow_serving/apis/predict.proto).
53 To use the Classify, Regress, or MultiInference APIs, please
54 use either
55 [tf.Estimator](https://www.tensorflow.org/api_docs/python/tf/estimator/Estimator)
56 or the lower level
57 [SavedModel
58 APIs](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/saved_model/README.md).
59 - Some TensorFlow ops depend on information on disk or other information
60 called "assets". These are generally handled automatically by adding the
61 assets to the `GraphKeys.ASSET_FILEPATHS` collection. Only assets in that
62 collection are exported; if you need more custom behavior, you'll need to
63 use the
64 [SavedModelBuilder](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/saved_model/builder.py).
65
66 More information about SavedModel and signatures can be found here:
67 https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/saved_model/README.md.
68
69 Args:
70 session: The TensorFlow session from which to save the meta graph and
71 variables.
72 export_dir: The path to which the SavedModel will be stored.
73 inputs: dict mapping string input names to tensors. These are added
74 to the SignatureDef as the inputs.
75 outputs: dict mapping string output names to tensors. These are added
76 to the SignatureDef as the outputs.
77 legacy_init_op: Legacy support for op or group of ops to execute after the
78 restore op upon a load.
79 """
80 signature_def_map = {
81 signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY:
82 signature_def_utils.predict_signature_def(inputs, outputs)
83 }
84 b = builder.SavedModelBuilder(export_dir, save_incr_model=save_incr_model)
85 b.add_meta_graph_and_variables(
86 session,
87 tags=[tag_constants.SERVING],
88 signature_def_map=signature_def_map,
89 assets_collection=ops.get_collection(ops.GraphKeys.ASSET_FILEPATHS),
90 main_op=legacy_init_op,
91 clear_devices=True)
92 b.save()

Callers

nothing calls this directly

Calls 3

get_collectionMethod · 0.45
saveMethod · 0.45

Tested by

no test coverage detected