View source on GitHub
|
Saves a model as a .keras file.
tf.keras.models.save_model(
model, filepath, overwrite=True, **kwargs
)
Used in the notebooks
| Used in the tutorials |
|---|
Example:
model = keras.Sequential(
[
keras.layers.Dense(5, input_shape=(3,)),
keras.layers.Softmax(),
],
)
model.save("model.keras")
loaded_model = keras.saving.load_model("model.keras")
x = keras.random.uniform((10, 3))
assert np.allclose(model.predict(x), loaded_model.predict(x))
Note that model.save() is an alias for keras.saving.save_model().
The saved .keras file contains:
- The model's configuration (architecture)
- The model's weights
- The model's optimizer's state (if any)
Thus models can be reinstantiated in the exact same state.
View source on GitHub