How to save Scikit-Learn-Keras Model into a Persistence File (pickle/hd5/json/yaml)

后端 未结 5 842
小鲜肉
小鲜肉 2020-12-13 19:23

I have the following code, using Keras Scikit-Learn Wrapper:

from keras.models import Sequential
from sklearn import datasets
from keras.layers import Dense
         


        
5条回答
  •  轮回少年
    2020-12-13 19:56

    Just adding to gaarv's answer - If you don't require the separation between the model structure (model.to_json()) and the weights (model.save_weights()), you can use one of the following:

    • Use the built-in keras.models.save_model and 'keras.models.load_model` that store everything together in a hdf5 file.
    • Use pickle to serialize the Model object (or any class that contains references to it) into file/network/whatever..
      Unfortunetaly, Keras doesn't support pickle by default. You can use my patchy solution that adds this missing feature. Working code is here: http://zachmoshe.com/2017/04/03/pickling-keras-models.html

提交回复
热议问题