C.W.K.
Stream
Lesson 02 of 05 · published

SavedModel Format In Depth

~11 min · savedmodel, deployment, signatures

Level 0Level 0
0 XP0/78 lessons0/17 achievements
0/100 XP to next level100 XP to go0% complete

The format your production servers love

SavedModel is TensorFlow's universal deployment format. When you export, TF traces your @tf.function-decorated code and saves a concrete TF graph alongside trained weights. This makes the model language-agnostic and framework-independent for inference — TF Serving, TFLite, TF.js, and Vertex AI all consume SavedModels.

On disk, a SavedModel is a directory:

saved_model_dir/
├── saved_model.pb           # graph + signature defs + metadata
├── fingerprint.pb           # content fingerprint
├── variables/
│   ├── variables.index
│   └── variables.data-00000-of-00001  # actual weights
└── assets/                  # external files (vocabularies, etc.)

For TF Serving, the directory layout must include a version number: /models/my_classifier/1/saved_model.pb. This is how Serving auto-detects new model versions and hot-swaps without restart.

Code

Version-stamped SavedModel + signatures·python
import tensorflow as tf

# Save with version directory for TF Serving
tf.saved_model.save(model, '/models/my_classifier/1/')

# Inspect signatures (callable endpoints)
loaded = tf.saved_model.load('/models/my_classifier/1/')
print(list(loaded.signatures.keys()))    # ['serving_default']

# Run inference via signature
infer = loaded.signatures['serving_default']
result = infer(tf.constant(x_test[:5].astype('float32')))
print(result.keys())
CLI inspection — 코드 안 짜고 검증·bash
# Show all info about the SavedModel
saved_model_cli show --dir my_saved_model/ --all

# Show input/output specs for the serving signature
saved_model_cli show --dir my_saved_model/ \
    --tag_set serve --signature_def serving_default

# Run inference from the CLI
saved_model_cli run --dir my_saved_model/ \
    --tag_set serve --signature_def serving_default \
    --input_exprs 'keras_tensor=[[1.0, 2.0, 3.0]]' 

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.