Keras save and load model

How to save and load a keras model?

2 votesNN160.00
1 Answers

Keras has save and load function in it's api and here is the solution of you question

from keras.models import load_model'my_model.h5')  # creates a HDF5 file 'my_model.h5'
del model  # deletes the existing model

# returns a compiled model
# identical to the previous one
model = load_model('my_model.h5')

You can also save and load only architecture of the model.

# save as JSON
json_string = model.to_json()

# save as YAML
yaml_string = model.to_yaml()
# model reconstruction from JSON:
from keras.models import model_from_json
model = model_from_json(json_string)

# model reconstruction from YAML:
from keras.models import model_from_yaml
model = model_from_yaml(yaml_string)

Also here is the link you can check out.

Couldn't find what you were looking for?and we will find an expert to answer.
How helpful was this page?