尝试恢复检查点时 Tensorflow 失败并显示 "Unable to get element from the feed as bytes."

Tensorflow fail with "Unable to get element from the feed as bytes." when attempting to restore checkpoint

我正在使用 Tensorflow r0.12。

我在本地使用 google-cloud-ml 来 运行 2 个不同的训练作业。在第一份工作中,我为我的变量找到了很好的初始值。我将它们存储在 V2 检查点中。

当我尝试恢复我的变量以便在第二份工作中使用它们时:

import tensorflow as tf

sess = tf.Session()
new_saver = tf.train.import_meta_graph('../variables_pred/model.ckpt-10151.meta', clear_devices=True)
new_saver.restore(sess, tf.train.latest_checkpoint('../variables_pred/'))
all_vars = tf.trainable_variables()
for v in all_vars:
    print(v.name)

我收到以下错误消息:

tensorflow.python.framework.errors_impl.InternalError: Unable to get element from the feed as bytes.

检查点是在第一个作业中使用这些行创建的:

saver = tf.train.Saver()
saver.export_meta_graph(filename=os.path.join(output_dir, 'export.meta'))
saver.save(sess, os.path.join(output_dir, 'export'), write_meta_graph=False)

根据this answer,这可能是因为缺少元数据文件,但我正在加载元数据文件。

PS :我使用参数 clear_devices=True 是因为在 google-cloud-ml 上启动生成的设备规格非常复杂,我不一定需要得到同样的调度。

我认为问题可能出在您保存模型时设置了 write_meta_graph=False。因此,我认为您实际上并没有保存图表,因此当您尝试恢复时,没有图表可以恢复。尝试设置 write_meta_graph=True

错误信息是由于不小心缺少名为"checkpoint"的文件。

在适当的文件夹中重新引入此文件后,检查点的加载似乎正在运行。

抱歉忽略了这个关键点。

这个错误信息也是由于不小心将名为"checkpoint"的文件弄错了。

例如,包含模型的文件夹已被移动,但"checkpoint"中"model_checkpoint_path:"的值仍然是旧路径。