【问题标题】:Restore intermediate checkpoint files of Tensorflow恢复 Tensorflow 的中间检查点文件
【发布时间】:2019-04-03 06:27:00
【问题描述】:

Tensorflow 版本 =1.8.0

我正在尝试使用 Tensorflow 中的中间检查点文件之一来恢复我的模型。默认情况下,Tensorflow 将采用最后保存的检查点文件。 例如,该文件夹包含如下文件:

检查点 model-56000.index model-56000.data-00000-of-00001 model-56000.meta model-57000.index model-57000.data-00000-of-00001 model-57000.meta

默认情况下,Tensorflow 会加载最后一个 57K 检查点,但出于某种原因,我想加载 56K 检查点的权重。 以下是我恢复模型的代码:

def load_G(self, checkpoint_dir):
    print(" [*] Reading checkpoints of G...")
    ckpt = tf.train.get_checkpoint_state(checkpoint_dir)
    if ckpt and ckpt.model_checkpoint_path:
        ckpt_name = os.path.basename(ckpt.model_checkpoint_path)
        self.saver_gen.restore(self.sess, os.path.join(checkpoint_dir, ckpt_name))
        return True
    else:
        return False

从 Tensorflow 的页面,我读到了 tf.train.get_checkpoint_state(),我可以指定 tf.train.get_checkpoint_state(checkpoint_dir, latest_filename=None)。但我不知道,我应该为 latest_filename 写什么。我试着写 latest_filename = model-56000 但这并没有加载模型。

我也试过写 latest_filename = model-56000.meta。那也没用。

那么,在 Tensorflow 中加载一些中间检查点文件的正确方法是什么。

【问题讨论】:

    标签: python tensorflow deep-learning


    【解决方案1】:

    好的,所以一个 hack 是修改 checkpoint protobuf 文件并将该文件的第一行从: model_checkpoint_path: "model-57000" 更改为 model_checkpoint_path: "model-56000" 现在它会加载 56K 检查点。 寻找一些更好的方法来做到这一点。

    【讨论】:

      【解决方案2】:

      ckpt 文件名将是model-56000.ckpt

      model-56000.meta指向ckpt的元信息

      model-56000 是 ckpt、数据文件或元文件的文件名

      【讨论】:

      • 所以,我写了 tf.train.get_checkpoint_state(checkpoint_dir, latest_filename='model-56000.ckpt')。但是 IF 条件仍然没有变为 True。我有什么遗漏吗?
      猜你喜欢
      • 2017-07-30
      • 1970-01-01
      • 2016-09-29
      • 1970-01-01
      • 2018-02-16
      • 1970-01-01
      • 1970-01-01
      • 2018-05-23
      • 2016-06-14
      相关资源
      最近更新 更多