1.模型保存
model.save_model()可以保存网络结构权重以及优化器的参数
model.save_weights() 仅仅保存权重
2.模型加载
from keras.models import load_model
load_model()只能load 由save_model保存的,将模型和weight全load进来
filepath: String, path to the saved model.
custom_objects: Optional dictionary mapping names
(strings) to custom classes or functions to be
considered during deserialization.
compile: Boolean, whether to compile the model
after loading.
model.load_weights(self, filepath, by_name=False):
在加载权重之前,model必须编译好
metrics = ['accuracy']
if self.nb_classes >= 10:
metrics.append('top_k_categorical_accuracy')
# self.input_shape = (seq_length, features_length)
self.model,self.original_model = self.zf_model()
optimizer = SGD(lr=1e-3)
self.model.compile(loss='categorical

本文介绍了Keras中模型的保存和加载,强调了在加载权重前需先编译模型。同时,对比了sequential和functional两种模型的区别,并详细阐述了model类的方法,包括如何获取和打印各层权重。
最低0.47元/天 解锁文章
559

被折叠的 条评论
为什么被折叠?



