首页 > 解决方案 > 保存的 shasum(使用 tf.keras.model.save_weights())hdf5 文件不匹配(确定性模型)

问题描述

我正在从事一个个人项目,该项目本质上应该是确定性的。

在训练期间的每批之后,模型将进入下一个状态,就像有限状态机的工作方式一样。因此,无论模型从头开始训练多少次,它都会经历相同的状态,最终达到最终状态。

所以我正在关注这个

init state = compile_model_and_save_model() // I am using tf.keras.model.save_weights(). I cannot use model.save() as my model is custom subclassed model

for 2-3 training runs: // note I am using training runs instead of epoch because I am training from scratch every time
  model.load_weights() // loading init state
  model.fit() // after this model reaches final state
  model.save_weights() // save trained model in other location

check_shasum_of_trained_hdf5_model_file()

我无法让 sha 总和相互匹配,这意味着每次运行之间经过训练的 hdf5 文件彼此不同。但进一步检查表明,每次模型都达到相同的最终状态。

  1. 那么 hdf5 文件是否会保存某种元数据,例如(转储时间),这会导致 shasum 不匹配,或者我是否遗漏了其他内容?
  2. 另外,我如何检查模型采取的中间步骤是否始终保持不变?(一个代码片段会很棒)

请帮忙!

标签: tensorflow2.0hdf5

解决方案


推荐阅读