Introduction
SavedModel is the standard way to save a complete model in
TensorFlow. It is a
folder, not a single file: a
saved_model.pb file describing the model’s computation, beside folders
for its weights and any extra files it needs. Because it holds the graph as well as
the weights, it can be loaded and run without the Python code that built the model,
which is how TensorFlow Serving, the TensorFlow Lite converter and TensorFlow.js take
models in.
This page is saved_model.pb itself: one SavedModel
message of TensorFlow’s schema, stored as a
Protocol Buffers message with no header.
Its schema version has been 1 since SavedModel arrived in TensorFlow 1.0, and this site
treats the files of every TensorFlow version as one format. The older single-file form of a
TensorFlow model, the frozen graph, is a different top-level message and a separate
format: see TensorFlow GraphDef (frozen graph).
A saved_model.pb dropped on any page of this site opens in the
explorer, which shows each meta graph’s tags and TensorFlow version, every signature
with its inputs and outputs, and the nodes, ops and functions of the graph.
Structure
saved_model.pb is one SavedModel
message. Inside it everything is nested:
1saved_model_schema_version always 12 bytes2MetaGraphDef one or more, each with its tags (such asserve) and TensorFlow versionvaries…signatures named entry points such asserving_default, with the tensors a caller feeds and fetchesinside each meta graph…GraphDef the nodes and a library of functionsinside each meta graph
The weights are not in this file: they are in the variables/ folder
beside it, in the layout of a TensorFlow checkpoint. A
text version of the same message may be saved as saved_model.pbtxt.
A saved_model.pb that begins
version https://git-lfs.github.com/spec/v1 is a Git LFS pointer, not the
model: the repository was cloned without fetching its LFS files. The explorer turns it
down as text; see the SavedModel
folder.
Telling it apart
The file has no signature. The explorer takes it as Protocol Buffers when the name
ends .pb, .binpb or .onnx, the first field reads
cleanly and the first 512 bytes are not all printable text. After the three ONNX
parsers turn it down, the parser for this format checks:
- the top level has only SavedModel’s fields 1 and 2, each with its wire type;
- there is at least one MetaGraphDef;
- the nested MetaGraphDef, GraphDef, NodeDef and the rest follow their schemas, down to the first 20,000 fields, with every node’s name and op well formed;
- strings declared
stringare valid UTF-8 (checked up to 4 KB).
When the bytes stop reading as fields part-way, the parser also requires that
saved_model_schema_version came before the break, so that a damaged
message of another kind is not shown as a SavedModel. The field numbers are those of
TensorFlow’s master branch in November 2026. A later schema that adds a field is still
this format, but the parser turns such a file down until it learns the field, and the
file is then shown as a message without a schema. No real SavedModel was among the
files examined for this site; the parser was tested with files built for the
test.
Not described
Known, not yet covered
- Viewer: the HighwayHash values in the block and chunk headers of a
chunked SavedModel (
saved_model.cpb) are not checked, and the chunks are listed and decoded but not reassembled into the SavedModel they were split from. - Reference and viewer: Riegeli’s transposed chunks are decoded from the format as read in Riegeli’s C++ source (the file-format document only says “TODO: Document this”), described on the folder page and tested on chunks built to that description; no transposed chunk written by Riegeli itself has been opened. Riegeli’s field projection (reading some fields only) is not described.
- Reference and viewer: ops registered by add-on libraries other than
the eight the op registry covers, and
TensorFlow’s ops registered outside
tensorflow/core/opsand the XLA file (the DTensor ops, for example), are still called custom. The 24 removed ops are described from their last definition inops_history.v2.pbtxtwithout documentation. The summaries of the 390 ops that the Go wrappers leave out were written for this site and not all compared with TensorFlow’s sources.
Unknown
- Reference and viewer: ops that a user has written for their own model. Nothing public defines them; the viewer shows the name and the attributes the node sets.
Variants
- ONNX tensor (TensorProto) – one tensor, as in ONNX’s test data
- ONNX sequence or optional value – a list of tensors, or a value that may be absent
- ONNX model (ModelProto) – a whole model: graph, operators and weights
- TensorFlow SavedModel (saved_model.pb) – meta graphs, signatures and functions
- TensorFlow GraphDef (frozen graph) – nodes, with the weights as constants
- Protocol Buffers message – any message, read without its schema
Links
Software
- TensorFlow – the machine learning framework that writes and loads SavedModels; its
saved_model_clitool lists a model’s tags and signatures (Windows, macOS, Linux) - TensorFlow Serving – server that serves SavedModels over the network (Linux)
- Netron – viewer that draws the graph (Windows, macOS, Linux, web)
Developers
- TensorFlow –
tf.saved_model.saveandtf.saved_model.load, with a C++ loader (Python, C++)
Reference
- Using the SavedModel format – TensorFlow’s guide to the folder and its files
- tensorflow/core/protobuf – the schemas saved_model.proto, meta_graph.proto and saver.proto
- tensorflow/core/framework – the schemas of the graph, nodes, attributes, tensors and data types