python-kerasHow do I save a Keras model in Python?
Keras models can be saved in Python using the model.save()
method. This method saves the architecture, weights, and training configuration of a model in a single HDF5
file.
Example code
from keras.models import load_model
model.save('model.h5')
This will create a single HDF5
file called model.h5
in the current working directory. The model can be reinstantiated at any time by calling the load_model()
function with the path to the HDF5
file as an argument.
Example code
from keras.models import load_model
model = load_model('model.h5')
The load_model()
function returns a compiled model identical to the original, including weights and training configuration.
Code explanation
model.save()
: Saves the architecture, weights, and training configuration of a model in a singleHDF5
file.load_model()
: Loads a compiled model including weights and training configuration.
Helpful links
More of Python Keras
- How do I use validation_data when creating a Keras model in Python?
- How do I use Python Keras to zip a file?
- How do I check which version of Keras I am using in Python?
- How do I use Python's tf.keras.utils.get_file to retrieve a file?
- How can I use Python Keras to create a neural network with zero hidden layers?
- How can I resolve the issue of Python module Tensorflow.keras not being found?
- How can I use Python and Keras together?
- How to load a model in Python Keras?
- How do I use keras.utils.to_categorical in Python?
- How do I save weights in a Python Keras model?
See more codes...