Introduction
A .keras file is a whole model saved by Keras,
the deep learning library that is also TensorFlow’s high-level interface. It holds the
model’s architecture, its weights and, if it was compiled, its training settings, so
keras.saving.load_model can rebuild it in one call. It became the default in
2023 and is the only full-model format in Keras 3.
Before that, Keras saved models as HDF5 files with
the extension .h5. These are still common in older tutorials and model
collections, and Keras can still read them.
Structure
A .keras file is a ZIP archive with three
entries:
config.json: the model’s architecture, layer by layer, with the class name and settings of eachmetadata.json: the Keras version and the date it was savedmodel.weights.h5: the weights, in HDF5
A legacy Keras .h5 file is a single HDF5 file. Its root carries the
architecture as a JSON string in the model_config attribute, with
keras_version and backend attributes beside it; the weights are
in a model_weights group with one subgroup per layer. A file saved with
save_weights holds only the weight groups.
Also used for
Links
Software
- Keras (Windows, macOS, Linux)
- TensorFlow (Windows, macOS, Linux)
- Netron, a viewer that draws the network (Windows, macOS, Linux, web)
Developers
Reference
- Save, serialize, and export models, Keras guide