Keras model.save()和model.save_weights()之间的区别? [英] Difference between Keras model.save() and model.save_weights()?
问题描述
要在Keras中保存模型,以下文件的输出文件之间有什么区别?
To save a model in Keras, what are the differences between the output files of:
-
model.save()
-
model.save_weights()
回调中的 -
ModelCheckpoint()
model.save()
model.save_weights()
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
文件中.我相信它也包括诸如优化器状态之类的东西.然后,您可以将HDF5文件与load()
一起使用,以重建包括权重在内的整个模型.
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屋!