详细实验过程见https://blog.csdn.net/leviopku/article/details/86612293
keras的模型一般保存为后缀名为h5的文件,比如final_model.h5。
#模型save
同样是h5文件用save()和save_weight()保存效果是不一样的。
#前提:模型训练好后
model.save('m2.h5')
model.save_weights('m3.h5')
m2表示save()保存的模型结果,它既保持了模型的图结构,又保存了模型的参数。
m3表示save_weights()保存的模型结果,它只保存了模型的参数,但并没有保存模型的图结构。
#模型load
from keras.models import load_model
model = load_model('m2.h5')
model.summary()#print model的信息
由save()保存下来的h5文件才可以直接通过load_model()打开!
from keras.models import Model
from keras.layers import Input, Dense
inputs = Input(shape=(784, ))
x = Dense(64, activation='relu')(inputs)
x = Dense(64, activation='relu')(x)
y = Dense(10, activation='softmax')(x)
model = Model(inputs=inputs, outputs=y)
model.load_weights('m3.h5')
'''