Name | Date | Size | #Lines | LOC | ||
---|---|---|---|---|---|---|
.. | - | - | ||||
model_utils/ | 03-May-2024 | - | 1,817 | 1,341 | ||
BUILD | D | 03-May-2024 | 17.8 KiB | 645 | 606 | |
README.md | D | 03-May-2024 | 4.3 KiB | 94 | 75 | |
builder.py | D | 03-May-2024 | 1.2 KiB | 30 | 9 | |
builder_impl.py | D | 03-May-2024 | 33.3 KiB | 798 | 528 | |
constants.py | D | 03-May-2024 | 4.6 KiB | 134 | 83 | |
function_deserialization.py | D | 03-May-2024 | 21.7 KiB | 541 | 360 | |
function_serialization.py | D | 03-May-2024 | 7.3 KiB | 177 | 125 | |
load.py | D | 03-May-2024 | 38.4 KiB | 921 | 696 | |
load_options.py | D | 03-May-2024 | 2.3 KiB | 58 | 31 | |
load_test.py | D | 03-May-2024 | 75.6 KiB | 2,201 | 1,689 | |
load_v1_in_v2.py | D | 03-May-2024 | 12.3 KiB | 281 | 216 | |
load_v1_in_v2_test.py | D | 03-May-2024 | 29.3 KiB | 701 | 618 | |
loader.py | D | 03-May-2024 | 2.5 KiB | 70 | 41 | |
loader_impl.py | D | 03-May-2024 | 17.9 KiB | 457 | 352 | |
loader_test.py | D | 03-May-2024 | 11.8 KiB | 296 | 210 | |
main_op.py | D | 03-May-2024 | 1.1 KiB | 29 | 9 | |
main_op_impl.py | D | 03-May-2024 | 2.8 KiB | 73 | 46 | |
method_name_updater.py | D | 03-May-2024 | 6 KiB | 150 | 110 | |
method_name_updater_test.py | D | 03-May-2024 | 10.2 KiB | 378 | 342 | |
nested_structure_coder.py | D | 03-May-2024 | 17 KiB | 560 | 391 | |
nested_structure_coder_test.py | D | 03-May-2024 | 13.9 KiB | 344 | 301 | |
revived_types.py | D | 03-May-2024 | 7.4 KiB | 182 | 133 | |
revived_types_test.py | D | 03-May-2024 | 4 KiB | 111 | 79 | |
save.py | D | 03-May-2024 | 57.5 KiB | 1,274 | 985 | |
save_context.py | D | 03-May-2024 | 1.9 KiB | 71 | 40 | |
save_context_test.py | D | 03-May-2024 | 3.2 KiB | 88 | 52 | |
save_options.py | D | 03-May-2024 | 7.6 KiB | 183 | 139 | |
save_test.py | D | 03-May-2024 | 38.2 KiB | 985 | 791 | |
saved_model.py | D | 03-May-2024 | 1.6 KiB | 39 | 17 | |
saved_model_test.py | D | 03-May-2024 | 65.2 KiB | 1,580 | 1,070 | |
signature_constants.py | D | 03-May-2024 | 4.9 KiB | 146 | 88 | |
signature_def_utils.py | D | 03-May-2024 | 1.8 KiB | 38 | 18 | |
signature_def_utils_impl.py | D | 03-May-2024 | 14 KiB | 396 | 302 | |
signature_def_utils_test.py | D | 03-May-2024 | 18.8 KiB | 479 | 349 | |
signature_serialization.py | D | 03-May-2024 | 13.2 KiB | 312 | 216 | |
simple_save.py | D | 03-May-2024 | 4.1 KiB | 92 | 68 | |
simple_save_test.py | D | 03-May-2024 | 4.8 KiB | 108 | 65 | |
tag_constants.py | D | 03-May-2024 | 1.8 KiB | 57 | 29 | |
utils.py | D | 03-May-2024 | 1.2 KiB | 28 | 9 | |
utils_impl.py | D | 03-May-2024 | 10.2 KiB | 281 | 207 | |
utils_test.py | D | 03-May-2024 | 8.2 KiB | 185 | 147 |
README.md
1# TensorFlow SavedModel 2 3[TOC] 4 5## Overview 6 7SavedModel is the universal serialization format for 8[TensorFlow](https://www.tensorflow.org/) models. 9 10SavedModel provides a language-neutral format to save machine-learning models 11that is recoverable and hermetic. It enables higher-level systems and tools to 12produce, consume and transform TensorFlow models. 13 14## Guides 15* [Using the SavedModel Format](https://www.tensorflow.org/guide/saved_model) 16* [Save and load Keras models](https://www.tensorflow.org/guide/keras/save_and_serialize) 17* [Save and load with checkpointing in Keras](https://www.tensorflow.org/tutorials/keras/save_and_load) 18* [Training checkpoints](https://www.tensorflow.org/guide/checkpoint) 19* [Save and load a model using a distribution strategy](https://www.tensorflow.org/tutorials/distribute/save_and_load) 20 21 22## [Public API](https://www.tensorflow.org/api_docs/python/tf/saved_model) 23* [`tf.saved_model.save`](https://www.tensorflow.org/api_docs/python/tf/saved_model/save) 24* [`tf.saved_model.load`](https://www.tensorflow.org/api_docs/python/tf/saved_model/load) 25* [`tf.saved_model.SaveOptions`](https://www.tensorflow.org/api_docs/python/tf/saved_model/SaveOptions) 26* [`tf.saved_model.LoadOptions`](https://www.tensorflow.org/api_docs/python/tf/saved_model/LoadOptions) 27* [`tf.saved_model.Asset`](https://www.tensorflow.org/api_docs/python/tf/saved_model/Asset) 28* [`tf.saved_model.contains_saved_model`](https://www.tensorflow.org/api_docs/python/tf/saved_model/contains_saved_model) 29 30### Related Modules and Functions 31* [`tf.keras.models.save_model`](https://www.tensorflow.org/api_docs/python/tf/keras/models/save_model) 32* [`tf.keras.models.load_model`](https://www.tensorflow.org/api_docs/python/tf/keras/models/load_model) 33* [`tf.train.Checkpoint`](https://www.tensorflow.org/api_docs/python/tf/train/Checkpoint) 34 35 36## The SavedModel Format 37A SavedModel directory has the following structure: 38 39``` 40assets/ 41assets.extra/ 42variables/ 43 variables.data-?????-of-????? 44 variables.index 45saved_model.pb 46``` 47 48* SavedModel protocol buffer 49 * [`saved_model.pb`](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/protobuf/saved_model.proto) 50 or `saved_model.pbtxt` 51 * Includes the graph definitions as `MetaGraphDef` protocol buffers. 52* Assets 53 * Subfolder called `assets`. 54 * Contains auxiliary files such as vocabularies, etc. 55* Extra assets 56 * Subfolder where higher-level libraries and users can add their own 57 assets that co-exist with the model, but are not loaded by the graph. 58 * This subfolder is not managed by the SavedModel libraries. 59* Variables 60 * Subfolder called `variables`. 61 * `variables.data-?????-of-?????` 62 * `variables.index` 63 64--- 65 66#### Stripping Default valued attributes 67The SavedModelBuilder class allows users to control whether default-valued 68attributes must be stripped from the NodeDefs while adding a meta graph to the 69SavedModel bundle. Both `SavedModelBuilder.add_meta_graph_and_variables` and 70`SavedModelBuilder.add_meta_graph` methods accept a Boolean flag 71`strip_default_attrs` that controls this behavior. 72 73If `strip_default_attrs` is `False`, the exported MetaGraphDef will have the 74default valued attributes in all it's NodeDef instances. This can break forward 75compatibility with a sequence of events such as the following: 76 77* An existing Op (`Foo`) is updated to include a new attribute (`T`) with a 78 default (`bool`) at version 101. 79* A model producer (such as a Trainer) binary picks up this change 80 (version 101) to the OpDef and re-exports an existing model that uses Op `Foo`. 81* A model consumer (such as Tensorflow Serving) running an older binary 82 (version 100) doesn't have attribute `T` for Op `Foo`, but tries to import 83 this model. The model consumer doesn't recognize attribute `T` in a NodeDef 84 that uses Op `Foo` and therefore fails to load the model. 85 86By setting `strip_default_attrs` to `True`, the model producers can strip away 87any default valued attributes in the NodeDefs. This helps ensure that newly 88added attributes with defaults don't cause older model consumers to fail loading 89models regenerated with newer training binaries. 90 91TIP: If you care about forward compatibility, then set `strip_default_attrs` 92to `True` while using `SavedModelBuilder.add_meta_graph_and_variables` and 93`SavedModelBuilder.add_meta_graph`. 94