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. The
archive and HDF5 layout page gives the entries,
groups and attributes in detail.
Not described
The archive page follows the Keras source for the .keras format.
Known, not yet covered
- Reference: the
get_configkeys of every individual Keras layer, loss, metric and optimiser class (each is defined by its own class; only the base classes andDenseare on the page), the legacy.h5model layer configs, and which saveables other than the lookup layers write assets. The config.json records, the weights layout, sharding and assets are now described. - Viewer: not re-audited in this pass.
Also used for
- Hierarchical Data Format version 5 – Groups and large numeric datasets, organised like a file system.
Links
Software
- Keras – the deep learning library that saves and loads these models (Windows, macOS, Linux)
- TensorFlow – machine learning framework with Keras built in (Windows, macOS, Linux)
- Netron – viewer that draws the network (Windows, macOS, Linux, web)
Developers
Reference
- Save, serialize, and export models – the Keras guide to its file formats