C.W.K.
Stream
Lesson 07 of 07 · published

Practical: Save → Cross-Backend Load → Export

~9 min · serialize

Level 0Keras Apprentice
0 XP0/97 lessons0/20 achievements
0/120 XP to next level120 XP to go0% complete

The whole track in one run

This lesson stitches together everything the track introduced separately. The .keras format (lesson 1), cross-backend loading (lesson 4), and export (lesson 5) aren't three unrelated tricks — they're three stages of one pipeline that carries a model from a fast training engine to a stable serving runtime without ever retraining it.

Three stages, three contexts

Stage 1 — train where it's fastest. Set the JAX backend, build and fit the model, and write a single model.keras. The optimizer state rides along, so this checkpoint is fully resumable. Stage 2 — load where it's stable. In a separate process with the TensorFlow backend selected, load_model reads the same file; the backend-agnostic weights mean nothing is lost in the handoff. Stage 3 — export for production. Project the loaded model onto a serving format with export, and ship it through TF Serving, TFLite, or TF.js.

Why the backend switch happens between processes

Notice each stage is its own script with its own KERAS_BACKEND. The backend is locked once import keras runs, so you can't flip engines mid-program — the switch lives at the process boundary, and the .keras file is what carries the model across that boundary intact. That file is the contract; the backends on either side are interchangeable.

Code

Train (JAX) → save → load (TF) → export for production·python
# Step 1: Train on JAX
os.environ["KERAS_BACKEND"] = "jax"
import keras
model = build_model()
model.compile(optimizer="adam", loss="sparse_categorical_crossentropy")
model.fit(x_train, y_train, epochs=10)
model.save("model.keras")

# Step 2: Load on TensorFlow
# (In a new script with KERAS_BACKEND="tensorflow")
model = keras.models.load_model("model.keras")

# Step 3: Export for production
model.export("production_model", format="tf_saved_model")
# Deploy with TF Serving, TFLite, or TF.js

External links

Exercise

Take your CIFAR-10 model. Execute the full lifecycle: train (TF) → save .keras → load (PyTorch) → eval → load (JAX) → eval → export → TFLite. Document each step's working command in a runbook.

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.