python - 错误 :tensorflow:Couldn't match files for checkpoint

标签 python tensorflow

我正在训练一个 tensorflow 模型,在每个 epoch 之后我保存模型状态并 pickle 一些数组。到目前为止,我的模型做了 2 个时期,保存状态的文件夹包含以下文件:

checkpoint
model_e_knihy_preprocessed.txt_e0.ckpt-1134759.data-00000-of-00001
model_e_knihy_preprocessed.txt_e0.ckpt-1134759.index
model_e_knihy_preprocessed.txt_e0.ckpt-1134759.meta
model_e_knihy_preprocessed.txt_e1.ckpt-2269536.data-00000-of-00001
model_e_knihy_preprocessed.txt_e1.ckpt-2269536.index
model_e_knihy_preprocessed.txt_e1.ckpt-2269536.meta
topgrads_e_knihy_preprocessed.txt_[it0].pkl
topgrads_e_knihy_preprocessed.txt_[it1].pkl
toppositions_e_knihy_preprocessed.txt_[it0].pkl
toppositions_e_knihy_preprocessed.txt_[it1].pkl
vocab.txt

我没有移动文件夹,也没有对文件结构进行任何外部修改。 checkpoint 文件包含以下内容:

model_checkpoint_path: "model_e_knihy_preprocessed.txt_e1.ckpt-2269536"
all_model_checkpoint_paths: "model_e_knihy_preprocessed.txt_e0.ckpt-1134759"
all_model_checkpoint_paths: "model_e_knihy_preprocessed.txt_e1.ckpt-2269536"

我按照以下方式恢复模型

with tf.Session() as session:
    model = Word2Vec(opts, session)
    model.saver.restore(session, tf.train.latest_checkpoint(path_to_model))

但是 tf.train.latest_checkpoint(path_to_model) 方法中已经有错误

ERROR:tensorflow:Couldn't match files for checkpoint /mnt/minerva1/nlp/projects/deep_learning/word2vec/trainedmodels/tf_w2vopt_[CS]ebooks_topgradients_iterative/model_e_knihy_preprocessed.txt_e1.ckpt-2269536

所以我偷看了方法

def latest_checkpoint(checkpoint_dir, latest_filename=None):
  ckpt = get_checkpoint_state(checkpoint_dir, latest_filename)
  if ckpt and ckpt.model_checkpoint_path:
    # Look for either a V2 path or a V1 path, with priority for V2.
    v2_path = _prefix_to_checkpoint_path(ckpt.model_checkpoint_path,
                                         saver_pb2.SaverDef.V2)
    v1_path = _prefix_to_checkpoint_path(ckpt.model_checkpoint_path,
                                         saver_pb2.SaverDef.V1)
    if file_io.get_matching_files(v2_path) or file_io.get_matching_files(
        v1_path):
      return ckpt.model_checkpoint_path
    else:
      logging.error("Couldn't match files for checkpoint %s",
                    ckpt.model_checkpoint_path)
  return None

发现 file_io.get_matching_files(v2_path) 什么也找不到(v2_path 包含值 /mnt/minerva1/nlp/projects/deep_learning/word2vec/trainedmodels/tf_w2vopt_[CS]ebooks_topgradients_iterative/model_e_knihy_preprocessed.txt_e1.ckpt-2269536 .index 存在于文件夹中!遗憾的是我无法进一步了解,因为此方法的控制导致进入 tensorflow 包装器。这是 tensorflow 错误吗?

我使用的是 Tensorflow 版本 1.5.0-rc0。

最佳答案

所以,答案是不要在文件路径中使用方括号。 Tensorflow 无法处理它们。 参见 https://github.com/tensorflow/tensorflow/issues/6082#issuecomment-265055615 .

关于python - 错误 :tensorflow:Couldn't match files for checkpoint,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49669695/

相关文章:

tensorflow - Tensorboard:从命令行导出 CSV 文件

python-3.x - 现在正在加载 Eager TensorFlow 吗?

python - 使用在 file1 中找到的数据更新 file2 中的记录

python - Python中的函数是对象吗?

python - 如何使用标准 Python 库使用文件参数触发经过身份验证的 Jenkins 作业

python - 在 TensorFlow 中调试 python 测试

tensorflow seq2seq : Tensor' object is not iterable

python - Aca-py 0.6.0 : INFO Ledger instance not provided error/bug?

python - 在 python mysql 中显示表时出错

tensorflow - Keras后端: Difference between random_normal and random_normal_variable