您的位置:首页 > 大数据 > 人工智能

NotFoundError: Unsuccessful TensorSliceReader constructor: Failed to find any matching files for xxx

2018-02-05 10:35 3051 查看
之前在Ubuntu中做训练没问题,后来在win7中训练出现了以下问题。

环境:TensorFlow 1.5

NotFoundError: Unsuccessful TensorSliceReader constructor: Failed to find any matching files for C://spyderwork//catanddog//logs//train//model.ckpt-14999

[[Node: save/RestoreV2 = RestoreV2[dtypes=[DT_FLOAT], _device=”/job:localhost/replica:0/task:0/device:CPU:0”](_arg_save/Const_0_0, save/RestoreV2/tensor_names, save/RestoreV2/shape_and_slices)]]

出现上述问题的位置:

ckpt=tf.train.get_checkpoint_state(logs_train_dir)
if ckpt and ckpt.model_checkpoint_path:
global_step=ckpt.model_checkpoint_path.split('/')[-1].split('-')[-1]
saver.restore(sess,ckpt.model_checkpoint_path)#出错在该地


restore()的API如下



def restore(self, sess, save_path):
"""Restores previously saved variables.

This method runs the ops added by the constructor for restoring variables.
It requires a session in which the graph was launched.  The variables to
restore do not have to have been initialized, as restoring is itself a way
to initialize variables.

The `save_path` argument is typically a value previously returned from a
`save()` call, or a call to `latest_checkpoint()`.

Args:
sess: A `Session` to use to restore the parameters. None in eager mode.
save_path: Path where parameters were previously saved.

Raises:
ValueError: If save_path is None.
"""
if self._is_empty:
return
if save_path is None:
raise ValueError("Can't load save_path when it is None.")
logging.info("Restoring parameters from %s", save_path)
if context.in_graph_mode():
sess.run(self.saver_def.restore_op_name,
{self.saver_def.filename_tensor_name: save_path})
else:
self._build_eager(save_path, build_save=False, build_restore=True)


restore的save_path参数为先前保存checkpoint的地址—“Path where parameters were previously saved。

之前保存checkpoint的代码为:

checkpoint_path = os.path.join(logs_train_dir, 'model.ckpt')
saver.save(sess, checkpoint_path, global_step=step)


checkpoint打印出来的地址为C:/spyderwork/catanddog/logs/train/model.ckpt-14999

而ckpt.model_checkpoint_path打印出来为C://spyderwork//catanddog//logs//train//model.ckpt-14999

这一块不知道是TensorFlow在windows中的bug还是其他原因,所以会出现这类错误。

修改方法1:

将以下代码

ckpt=tf.train.get_checkpoint_state(logs_train_dir)
if ckpt and ckpt.model_checkpoint_path:
global_step=ckpt.model_checkpoint_path.split('/')[-1].split('-')[-1]
saver.restore(sess,ckpt.model_checkpoint_path)#出错在该地


换成

ckpt=tf.train.get_checkpoint_state(logs_train_dir)
if ckpt and ckpt.model_checkpoint_path:
global_step=ckpt.model_checkpoint_path.split('/')[-1].split('-')[-1]
checkpoint_path = os.path.join(logs_train_dir, 'model.ckpt')
saver.restore(sess,checkpoint_path)


修改方法2:

ckpt=tf.train.get_checkpoint_state(logs_train_dir)
if ckpt and ckpt.model_checkpoint_path:
global_step=ckpt.model_checkpoint_path.split('/')[-1].split('-')[-1]
saver.restore(sess,'C:/spyderwork/catanddog/logs/train/model.ckpt-14999')

或者

ckpt=tf.train.get_checkpoint_state(logs_train_dir)
if ckpt and ckpt.model_checkpoint_path:
global_step=ckpt.model_checkpoint_path.split('/')[-1].split('-')[-1]
saver.restore(sess,'./logs/train/model.ckpt-14999')


注:修改时请根据自己的路径进行修改

[参考]https://github.com/tensorflow/tensorflow/issues/6082
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐