Persist a complete model
Checkpoint a trained model for later inference or fine-tuning.
Keras · Module
model.save() stores a complete Keras model in the native .keras format. It preserves architecture, weights, and optimizer state when present, so the model can later be reconstructed.
Calling model.save() serializes the model to the native Keras format, preserving its configuration, weights, and optimizer state when available. The destination can be a .keras archive or, with zipped=False, an unzipped directory; the method can optionally overwrite an existing destination.
Model.save(filepath, overwrite=True, zipped=None, **kwargs)| Name | Type | Description |
|---|---|---|
filepath | str or pathlib.Path | String or pathlib.Path destination for the model. It must end in .keras unless zipped=False is used for an unzipped directory. |
overwrite | bool | Controls whether an existing destination is replaced or an interactive prompt is used. |
zipped | bool or None | Controls archive form: a zipped .keras archive or an unzipped directory. The default is context-dependent: zipped locally and unzipped on the Hugging Face Hub. |
**kwargs | keyword arguments | Additional keyword arguments accepted by the saving implementation. |
.keras model file..keras suffix; omit it only when deliberately saving an unzipped directory.overwrite controls replacement versus an interactive confirmation prompt.import keras
model = keras.Sequential([
keras.layers.Dense(8, activation="relu"),
keras.layers.Dense(1),
])
model.build((None, 4))
model.save("model.keras")
This creates a built model and saves its architecture, weights, and optimizer state, when present, in the native Keras format.
Checkpoint a trained model for later inference or fine-tuning.
Move a model between processes or environments while retaining its configuration and learned state.
Choose an uncompressed directory representation when an archive is unsuitable.
model.save() preserve?model.save() writes a complete model rather than weights alone: its configuration, weights, and optimizer state, if present. This allows the model to be reinstantiated in the same state.
Follow-up: How would you save only parameters? Use model.save_weights(), which is a separate API and is not whole-model serialization.
The signature is Model.save(filepath, overwrite=True, zipped=None, **kwargs). filepath is a string or pathlib.Path; local saves default to a zipped .keras archive, while zipped=False selects an unzipped directory.
Follow-up: What happens if the path has no .keras suffix? For a regular save, the path must end in .keras; an unzipped directory is the documented exception.
model.save() relate to other saving APIs?model.save() is an alias for keras.saving.save_model(). For a native Keras save, call model.save("model.keras"); use model.export() instead when the goal is exporting a TensorFlow SavedModel for serving or related tooling.
Follow-up: Why not use model.save() for SavedModel export in Keras 3? Keras 3 no longer supports that format through model.save(); model.export() is the designated API.
keras.saving.save_modelkeras.saving.load_modelModel.save_weightsModel.export