利用h5py保存的模型所占的空间非常小。在利用h5py保存keras训练好的模型之前需要先安装h5py,具体的安装过程可参考我关于h5py安装的博文:http://blog.csdn.net/linmingan/article/details/50736300
利用h5py保存和读取keras模型的代码如下:
import h5py from keras.models import model_from_json
json_string = model.to_json()
open('my_model_architecture.json','w').write(json_string)
model.save_weights('my_model_weights.h5')
#读取model
model = model_from_json(open('my_model_architecture.json').read())
model.load_weights('my_model_weights.h5')