解决tensorflow测试模型时NotFoundError错误的问题

yipeiwu_com6年前Python基础

错误代码如下:

NotFoundError (see above for traceback): Unsuccessful TensorSliceReader constructor: 

Failed to find any matching files for xxx
……

经查资料分析,错误原因可能出在加载模型时的路径问题。我采用的加载模型方法:

with tf.Session() as sess:
  print("Reading checkpoints...")
  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)
   print('Loading success, global_step is %s' % global_step)
  else:
   print('No checkpoint file found')

在保存模型时,采用的方法为

saver = tf.train.Saver()
……
……
……
if step % 1000 == 0 or (step + 1) == MAX_STEP:
 checkpoint_path = os.path.join(logs_train_dir, './model.ckpt')
 saver.save(sess, checkpoint_path, global_step=step)

注意代码块中的./model.ckpt,这是关键,原来为model.ckpt就会报错。如果在加载模型时采用直接加载模型文件的方法,则:

改之前代码:

saver.restore(sess,'model.ckpt')

改之后的代码:

saver.restore(sess,'./model.ckpt')

我的改之后是没有什么问题了,如果这种方法不能解决你的问题,再查资料解决吧

以上这篇解决tensorflow测试模型时NotFoundError错误的问题就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

pycharm 解除默认unittest模式的方法

pycharm 解除默认unittest模式的方法

pycharm关闭unittest模式方法 网上看到了很多方法,尝试之后偶然奏效,该方法确定可以关闭单元测试: 点击如图所示的工具图标,Tools-python integrated...

python中logging库的使用总结

前言 最近因为工作的需要,在写一些python脚本,总是使用print来打印信息感觉很low,所以抽空研究了一下python的logging库,来优雅的来打印和记录日志,下面话不多说了,...

在Qt5和PyQt5中设置支持高分辨率屏幕自适应的方法

PyQt5: 程序入口添加 QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling) Qt5:...

Python处理CSV与List的转换方法

1.读取CSV文件到List def readCSV2List(filePath): try: file=open(filePath,'r',encoding="gbk")#...

Python实现批量更换指定目录下文件扩展名的方法

本文实例讲述了Python实现批量更换指定目录下文件扩展名的方法。分享给大家供大家参考,具体如下: #encoding=utf-8 #author: walker #date: 20...