Join us at TensorFlow World, Oct 28-31. Use code TF20 for 20% off select passes. Register now

tf.keras.models.save_model

TensorFlow 2.0 version View source on GitHub

Saves a model as a TensorFlow SavedModel or HDF5 file.

Aliases:

  • tf.compat.v1.keras.models.save_model
  • tf.compat.v2.keras.models.save_model
tf.keras.models.save_model(
    model,
    filepath,
    overwrite=True,
    include_optimizer=True,
    save_format=None
)

The saved model contains: - the model's configuration (topology) - the model's weights - the model's optimizer's state (if any)

Thus the saved model can be reinstantiated in the exact same state, without any of the code used for model definition or training.

Arguments:

  • model: Keras model instance to be saved.
  • filepath: One of the following:
    • String, path where to save the model
    • h5py.File object where to save the model
  • overwrite: Whether we should overwrite any existing model at the target location, or instead ask the user with a manual prompt.
  • include_optimizer: If True, save optimizer's state together.
  • save_format: Either 'tf' or 'h5', indicating whether to save the model to Tensorflow SavedModel or HDF5. The 'tf' option is currently disabled, and will be enabled when Keras SavedModel export is no longer experimental. (The experimental function is tf.keras.experimental.export_saved_model).

Raises:

  • ImportError: If save format is hdf5, and h5py is not available.