Keras model.save() 和 model.save_weights() 的区别? [英] Difference between Keras model.save() and model.save_weights()?

查看:47
本文介绍了Keras model.save() 和 model.save_weights() 的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Keras中保存模型,输出文件有什么区别:

To save a model in Keras, what are the differences between the output files of:

  1. model.save()
  2. model.save_weights()
  3. ModelCheckpoint() 在回调中
  1. model.save()
  2. model.save_weights()
  3. ModelCheckpoint() in the callback

model.save() 中保存的文件比 model.save_weights() 中的模型大,但明显大于 JSON 或 Yaml 模型架构文件.为什么是这样?

The saved file from model.save() is larger than the model from model.save_weights(), but significantly larger than a JSON or Yaml model architecture file. Why is this?

重申这一点:为什么 size(model.save()) + size(something) = size(model.save_weights()) + size(model.to_json()),那是什么东西"?

Restating this: Why is size(model.save()) + size(something) = size(model.save_weights()) + size(model.to_json()), what is that "something"?

仅使用 model.save_weights()model.to_json() 并从中加载是否比仅执行 model.save 更有效()load_model()?

Would it be more efficient to just model.save_weights() and model.to_json(), and load from these than to just do model.save() and load_model()?

有什么区别?

推荐答案

save() 将权重和模型结构保存到单个 HDF5 文件中.我相信它还包括优化器状态之类的东西.然后您可以使用带有 load() 的 HDF5 文件来重建整个模型,包括权重.

save() saves the weights and the model structure to a single HDF5 file. I believe it also includes things like the optimizer state. Then you can use that HDF5 file with load() to reconstruct the whole model, including weights.

save_weights() 仅将权重保存到 HDF5,没有其他任何内容.您需要额外的代码来从 JSON 文件重建模型.

save_weights() only saves the weights to HDF5 and nothing else. You need extra code to reconstruct the model from a JSON file.

这篇关于Keras model.save() 和 model.save_weights() 的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆