Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Keras · Module

model.save

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.

How it works

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.

Syntax

Model.save(filepath, overwrite=True, zipped=None, **kwargs)

Parameters

NameTypeDescription
filepathstr or pathlib.PathString or pathlib.Path destination for the model. It must end in .keras unless zipped=False is used for an unzipped directory.
overwriteboolControls whether an existing destination is replaced or an interactive prompt is used.
zippedbool or NoneControls archive form: a zipped .keras archive or an unzipped directory. The default is context-dependent: zipped locally and unzipped on the Hugging Face Hub.
**kwargskeyword argumentsAdditional keyword arguments accepted by the saving implementation.

Key points

  • The standard operation creates a native .keras model file.
  • The native file stores more than numerical parameters: it includes the model definition and training state.
  • Architecture configuration is serialized so the model structure can be reconstructed.
  • Learned and other model weights are included in the saved artifact.
  • Optimizer state is included when the model has one, supporting continuation from the saved training state.
  • Loading the resulting artifact can recreate the model in the state represented by the save.

Common mistakes

  • A normal save path must use the .keras suffix; omit it only when deliberately saving an unzipped directory.
  • If the destination already exists, overwrite controls replacement versus an interactive confirmation prompt.

Example: Save a model

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.

When to use it

Persist a complete model

Checkpoint a trained model for later inference or fine-tuning.

Portable model artifact

Move a model between processes or environments while retaining its configuration and learned state.

Directory-based storage

Choose an uncompressed directory representation when an archive is unsuitable.

Interview questions

QWhat does 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.

QWhat are the important arguments and path requirements?

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.

QHow does 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_model
  • keras.saving.load_model
  • Model.save_weights
  • Model.export

Source: Keras documentation: Whole model saving & loading. Checked 2026-10-15.