tf.train.get_checkpoint_state 总是无 [英] tf.train.get_checkpoint_state always None

查看:61
本文介绍了tf.train.get_checkpoint_state 总是无的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 tf.train.get_checkpoint_state 来检查我是否有一个有效的检查点文件来恢复 Tensorflow 保存的模型.

I am using tf.train.get_checkpoint_state to check whether I have a valid checkpoint file to restore a Tensorflow saved model.

ckpt = tf.train.get_checkpoint_state(os.path.dirname('fi/saves'))
if ckpt and ckpt.model_checkpoint_path:
   saver.restore(sess, ckpt.model_checkpoint_path)  

我的问题是 ckpt 始终为 None.这是我的保存目录的内容:

My issue is that ckpt is always None. Here is the content of my saves directory:

  • internals.pkl
  • stats.json
  • variables.ckpt.data-00000-of-00001
  • variables.ckpt.index

请注意,直接调用恢复效果很好.

Please note that a call to restore directly works well.

我曾尝试使用这样的 latest_filename 参数:

I have tried using the latest_filename argument like this:

tf.train.get_checkpoint_state(os.path.dirname(checkpoint_dir), latest_filename='variables.ckpt.index')  

我仍然没有收到.

推荐答案

我发现 tf.train.get_checkpoint_state 寻找检查点文件.

I figured out that tf.train.get_checkpoint_state looks for a checkpoint file.

我没有这个文件,因为我在保存时这样做了:

I did not have this file because I was doing this when saving:

saver.save(sess, variables_file_path, write_meta_graph=False, write_state=False)

代替:

saver.save(sess, variables_file_path, write_meta_graph=False, write_state=True)  # write state is true by default.

现在可以了!

这篇关于tf.train.get_checkpoint_state 总是无的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆