我正在使用CNN进行面部表情识别。我使用Keras和Tensorflow作为后端。我的模型保存为h5格式。微调Keras模型
我想重新训练我的网络,并使用VGG模型微调我的模型。
我该怎么做keras?从这里再次
from keras.models import model_from_json
model = model_from_json(json_string)
model.load_weights('model_weights.h5')
开始训练微调:
我正在使用CNN进行面部表情识别。我使用Keras和Tensorflow作为后端。我的模型保存为h5格式。微调Keras模型
我想重新训练我的网络,并使用VGG模型微调我的模型。
我该怎么做keras?从这里再次
from keras.models import model_from_json
model = model_from_json(json_string)
model.load_weights('model_weights.h5')
开始训练微调:
保存您的模型架构和重量:
json_string = model.to_json()
model.save_weights('model_weights.h5')
负载模型结构和权重。我希望这有帮助。
您可以使用Keras model.save(filepath)
功能。
详细的各种Keras保存和加载技术,在此YouTube视频的例子讨论:Save and load a Keras model
model.save(filepath)
节省:
要加载这个保存的模型,你可以使用下列内容:
from keras.models import load_model
new_model = load_model(filepath)
如果使用model.to_json()
,你只会被保存模型的架构。此外,如果您使用model.save_weights()
,则只会保存模型的权重。使用这两种替代保存技术,您不会保存培训配置(损失,优化器),也不会保存优化器的状态。