Tensorflow 版本 =1.8.0
我正在尝试使用 Tensorflow 中的一个中间检查点文件来恢复我的模型。默认情况下,Tensorflow 将采用最后保存的检查点文件。例如,该文件夹包含以下文件:
checkpoint 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 中加载一些中间检查点文件的正确方法是什么?
千巷猫影
陪伴而非守候
相关分类