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

model.save() and load_model() — Three Formats

~10 min · save, load, keras-format

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

Choose the format before you need to deploy

Training a model is expensive. Saving lets you reuse it without retraining — for inference, continued training, deployment, sharing, publishing. TF provides multiple formats; the wrong choice creates deployment headaches.

The format is determined by the file extension you save with:

FormatArchitectureWeightsOptimizerBest for
.kerasDevelopment checkpoints, framework-agnostic Keras 3
SavedModel directoryProduction: TF Serving, TFLite, TF.js
.h5 (legacy)Avoid for new projects
weights only (.weights.h5)When you have the architecture code already

Save to .keras during development for maximum fidelity. Export to SavedModel for production serving / TFLite conversion / TF.js. Knowing the format differences before you need to deploy saves hours of debugging later.

Code

저장 + 불러오기 — 4 가지 패턴·python
import tensorflow as tf

# 1. Keras 3 native format (recommended for development)
model.save('model.keras')
loaded = tf.keras.models.load_model('model.keras')

# 2. SavedModel format (TF deployment ecosystem)
model.save('saved_model_dir/')          # creates a directory
# equivalent low-level API:
tf.saved_model.save(model, 'saved_model_dir/')
loaded = tf.keras.models.load_model('saved_model_dir/')

# 3. Legacy HDF5 (avoid for new code)
model.save('model.h5')
loaded = tf.keras.models.load_model('model.h5')

# 4. Weights only — needs same architecture to load
model.save_weights('weights.weights.h5')
model.load_weights('weights.weights.h5')

External links

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.