github博客传送门
博客园传送门
Keras模型保存简介
model.save()
model_save_path = "model_file_path.h5"
model.save(model_save_path)
del model
from keras.models import load_model
model = load_model(model_save_path)
model.save_weights()
model_save_path = "model_file_path.h5"
model.save_weights(model_save_path)
model.load_weights(model_save_path)
model.to_json()
json_string = model.to_json()
with open("model_save_file.json", "w") as f:
f.write(json_string)
from keras.models import model_from_json
with open("model_save_file.json", "r") as f:
json_string = f.read()
model = model_from_json(json_string)
model.to_yaml()
yaml_string = model.to_yaml()
with open("model_save_file.yaml", "w") as f:
f.write(yaml_string)
from keras.models import model_from_yaml
with open("model_save_file.yaml", "r") as f:
yaml_string = f.read()
model = model_from_yaml(yaml_string)
现在我们来说说这四种保存模型的联系与区别
项目 | 是否保存模型结构 | 是否保存模型权重 | 是否能继续训练网络 | 是否能进行模型预测 |
---|
model.save() | 是 | 是 | 是 | 是 |
model.save_weights() | 否 | 是 | 否 | 是 |
model.to_json() | 是 | 否 | 否 | 加载权重后能进行正常预测 |
model.to_yaml() | 是 | 否 | 否 | 加载权重后能进行正常预测 |
如有测试错误,欢迎指正.谢了.
print_r('点个赞吧');
var_dump('点个赞吧');
NSLog(@"点个赞吧!")
System.out.println("点个赞吧!");
console.log("点个赞吧!");
print("点个赞吧!");
printf("点个赞吧!\n");
cout << "点个赞吧!" << endl;
Console.WriteLine("点个赞吧!");
fmt.Println("点个赞吧!")
Response.Write("点个赞吧");
alert(’点个赞吧’)