keras--save model file and load model file _ frame

Source: Internet
Author: User
Tags keras keras model

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 ")

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.