实现步骤
1 安装 h5py 库
打开cmd输入:
pip install h5py
2 载入相关库
from keras.models import load_model
3 save model
model.save('my_model.h5')
4 load model
model = load_model('my_model.h5')
5 其他保存方法
(1)保存与加载 weights
# save and load weights
model.save_weights('my_model_weights.h5')
model.load_weights('my_model_weights.h5')
(2)保存网络结构,但不保存训练生成的权重
# save and load fresh network without trained weights
from keras.models import model_from_json
json_string = model.to_json()
model = model_from_json(json_string)
注:以上代码源自网络,只是对其分析解读