There are a number of ways to save Keras model files and load Keras files. The models in Keras mainly include two parts of model and weight. JSON files, yaml files, HDF5 files
The main way to save the model section: one is through the JSON file
JSON file
[Python] View plain copy # Serialize model to JSON Model_json = Model.to_json () with open ("Model.json", "W") as JSON _file:json_file.write (Model_json)
Yaml file
[Python] View plain copy # Save as YAML yaml_string = Model.to_yaml ()
Ways to save weights: by saving weights (coefficients)
HDF5 file
[CPP] View plain copy # Serialize weights to HDF5 model.save_weights (' Model.h5 ') print ("Saved model to disk")
The way to save model and weight at the same time:
[Python] View plain copy from keras.models import Load_model model.save (' Model_weight.h5 ') # Creates a HDF5 file ' My_model.h5 '
How to load Model
Json&hdf5
[Python] View plain copy # Load JSON and create model Json_file = open (' Model.json ', ' r ') Loaded_model_json = Json_f Ile.read () json_file.close () Loaded_model = Model_from_json (Loaded_model_json
[Python] View plain copy from keras.models import Load_model model = Load_model (' model.h5 ')
Load weights
[Python] View plain copy # Load weights into New model loaded_model.load_weights ("Model.h5") print ("Loaded model fro M disk ")