STT-tensorflow/tf/tensorflow/python/saved_model
2021-01-21 15:40:33 -08:00
..
model_utils initial 2021-01-21 09:06:36 -08:00
BUILD initial 2021-01-21 09:06:36 -08:00
builder_impl.py initial 2021-01-21 09:06:36 -08:00
builder.py initial 2021-01-21 09:06:36 -08:00
constants.py initial 2021-01-21 09:06:36 -08:00
function_deserialization.py initial 2021-01-21 09:06:36 -08:00
function_serialization.py initial 2021-01-21 09:06:36 -08:00
load_options.py initial 2021-01-21 09:06:36 -08:00
load_test.py sync to master 2021-01-21 15:40:33 -08:00
load_v1_in_v2_test.py initial 2021-01-21 09:06:36 -08:00
load_v1_in_v2.py initial 2021-01-21 09:06:36 -08:00
load.py initial 2021-01-21 09:06:36 -08:00
loader_impl.py initial 2021-01-21 09:06:36 -08:00
loader_test.py initial 2021-01-21 09:06:36 -08:00
loader.py initial 2021-01-21 09:06:36 -08:00
main_op_impl.py initial 2021-01-21 09:06:36 -08:00
main_op.py initial 2021-01-21 09:06:36 -08:00
method_name_updater_test.py initial 2021-01-21 09:06:36 -08:00
method_name_updater.py initial 2021-01-21 09:06:36 -08:00
nested_structure_coder_test.py initial 2021-01-21 09:06:36 -08:00
nested_structure_coder.py initial 2021-01-21 09:06:36 -08:00
README.md initial 2021-01-21 09:06:36 -08:00
revived_types_test.py initial 2021-01-21 09:06:36 -08:00
revived_types.py initial 2021-01-21 09:06:36 -08:00
save_context_test.py initial 2021-01-21 09:06:36 -08:00
save_context.py initial 2021-01-21 09:06:36 -08:00
save_options.py initial 2021-01-21 09:06:36 -08:00
save_test.py initial 2021-01-21 09:06:36 -08:00
save.py initial 2021-01-21 09:06:36 -08:00
saved_model_test.py initial 2021-01-21 09:06:36 -08:00
saved_model.py initial 2021-01-21 09:06:36 -08:00
signature_constants.py initial 2021-01-21 09:06:36 -08:00
signature_def_utils_impl.py initial 2021-01-21 09:06:36 -08:00
signature_def_utils_test.py initial 2021-01-21 09:06:36 -08:00
signature_def_utils.py initial 2021-01-21 09:06:36 -08:00
signature_serialization.py initial 2021-01-21 09:06:36 -08:00
simple_save_test.py initial 2021-01-21 09:06:36 -08:00
simple_save.py initial 2021-01-21 09:06:36 -08:00
tag_constants.py initial 2021-01-21 09:06:36 -08:00
utils_impl.py initial 2021-01-21 09:06:36 -08:00
utils_test.py initial 2021-01-21 09:06:36 -08:00
utils.py initial 2021-01-21 09:06:36 -08:00

TensorFlow SavedModel

[TOC]

Overview

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.

Guides

Public API

The SavedModel Format

A SavedModel directory has the following structure:

assets/
assets.extra/
variables/
    variables.data-?????-of-?????
    variables.index
saved_model.pb
  • SavedModel protocol buffer
    • saved_model.pb or saved_model.pbtxt
    • Includes the graph definitions as MetaGraphDef protocol buffers.
  • Assets
    • Subfolder called assets.
    • Contains auxiliary files such as vocabularies, etc.
  • Extra assets
    • Subfolder where higher-level libraries and users can add their own assets that co-exist with the model, but are not loaded by the graph.
    • This subfolder is not managed by the SavedModel libraries.
  • Variables
    • Subfolder called variables.
      • variables.data-?????-of-?????
      • variables.index

Stripping Default valued attributes

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:

  • An existing Op (Foo) is updated to include a new attribute (T) with a default (bool) at version 101.
  • A model producer (such as a Trainer) binary picks up this change (version 101) to the OpDef and re-exports an existing model that uses Op Foo.
  • A model consumer (such as Tensorflow Serving) running an older binary (version 100) doesn't have attribute 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.