=====method 1=====

保存神經網路的結構與訓練好的參數

json_string = model.to_json()

open('model_architecture.json', 'w').write(json_string)

model.save_weights('model_weights.h5')

 

載入先前的model與weights

import h5py from keras.models import model_from_json

model = model_from_json(open('model_architecture.json').read())

model.load_weights('model_weights.h5')

 

=====method 2=====

保存model結構以及weights為一個HDF5檔案

'''

...

model = conv2D(....)

model = maxpooling2D(...)

....

'''

model.save('model.h5') #create a HDF5 file to save model

del model #deletes the existing model

 

重新載入以保存的model

from keras.models import load_model

model = load_model('model.h5')

model.summary()

 

arrow
arrow

    楓綺 發表在 痞客邦 留言(0) 人氣()