为了账号安全,请及时绑定邮箱和手机立即绑定

运行报错NotFoundError : Key regression/Variable not found in checkpoint

Traceback (most recent call last):

  File "C:\Users\Invisible\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\client\session.py", line 1322, in _do_call

    return fn(*args)

  File "C:\Users\Invisible\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\client\session.py", line 1307, in _run_fn

    options, feed_dict, fetch_list, target_list, run_metadata)

  File "C:\Users\Invisible\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\client\session.py", line 1409, in _call_tf_sessionrun

    run_metadata)

tensorflow.python.framework.errors_impl.NotFoundError: Key regression/Variable not found in checkpoint

[[Node: save/RestoreV2 = RestoreV2[dtypes=[DT_FLOAT, 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)]]


During handling of the above exception, another exception occurred:


Traceback (most recent call last):

  File "C:/Users/Invisible/PycharmProjects/mnist_testdemo/main.py", line 18, in <module>

    saver.restore(sess, "mnist/data/regression.ckpt")

  File "C:\Users\Invisible\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\training\saver.py", line 1768, in restore

    six.reraise(exception_type, exception_value, exception_traceback)

  File "C:\Users\Invisible\AppData\Local\Programs\Python\Python36\lib\site-packages\six.py", line 693, in reraise

    raise value

  File "C:\Users\Invisible\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\training\saver.py", line 1752, in restore

    {self.saver_def.filename_tensor_name: save_path})

  File "C:\Users\Invisible\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\client\session.py", line 900, in run

    run_metadata_ptr)

  File "C:\Users\Invisible\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\client\session.py", line 1135, in _run

    feed_dict_tensor, options, run_metadata)

  File "C:\Users\Invisible\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\client\session.py", line 1316, in _do_run

    run_metadata)

  File "C:\Users\Invisible\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\client\session.py", line 1335, in _do_call

    raise type(e)(node_def, op, message)

tensorflow.python.framework.errors_impl.NotFoundError: Key regression/Variable not found in checkpoint

[[Node: save/RestoreV2 = RestoreV2[dtypes=[DT_FLOAT, 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)]]


Caused by op 'save/RestoreV2', defined at:

  File "C:/Users/Invisible/PycharmProjects/mnist_testdemo/main.py", line 17, in <module>

    saver = tf.train.Saver(variables)

  File "C:\Users\Invisible\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\training\saver.py", line 1284, in __init__

    self.build()

  File "C:\Users\Invisible\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\training\saver.py", line 1296, in build

    self._build(self._filename, build_save=True, build_restore=True)

  File "C:\Users\Invisible\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\training\saver.py", line 1333, in _build

    build_save=build_save, build_restore=build_restore)

  File "C:\Users\Invisible\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\training\saver.py", line 781, in _build_internal

    restore_sequentially, reshape)

  File "C:\Users\Invisible\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\training\saver.py", line 400, in _AddRestoreOps

    restore_sequentially)

  File "C:\Users\Invisible\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\training\saver.py", line 832, in bulk_restore

    return io_ops.restore_v2(filename_tensor, names, slices, dtypes)

  File "C:\Users\Invisible\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\ops\gen_io_ops.py", line 1546, in restore_v2

    shape_and_slices=shape_and_slices, dtypes=dtypes, name=name)

  File "C:\Users\Invisible\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 787, in _apply_op_helper

    op_def=op_def)

  File "C:\Users\Invisible\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\ops.py", line 3414, in create_op

    op_def=op_def)

  File "C:\Users\Invisible\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\ops.py", line 1740, in __init__

    self._traceback = self._graph._extract_stack()  # pylint: disable=protected-access


NotFoundError (see above for traceback): Key regression/Variable not found in checkpoint

[[Node: save/RestoreV2 = RestoreV2[dtypes=[DT_FLOAT, 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_s


正在回答

3 回答

这里是TensorFlow的一个新bug

saver.restore(sess,"./mnist/data/convolutional.ckpt")

改成 

module_file =  tf.train.latest_checkpoint('mnist/data/convolutional.ckpt')
with tf.Session() as sess:
   sess.run(tf.global_variables_initializer())
   if module_file is not None:
      saver.restore(sess, module_file)

就可以了

4 回复 有任何疑惑可以回复我~
#1

诺言14

使用tf.Session()作为sess: sess.run(tf.global_variables_initializer()) 如果module_file不是None: saver.restore(sess,module_file) 在哪修改?
2018-09-30 回复 有任何疑惑可以回复我~
#2

劉小怂

亲测好用,感谢
2019-05-10 回复 有任何疑惑可以回复我~
#3

qq_灿烂千阳_3

感谢感谢,解决啦~
2019-12-13 回复 有任何疑惑可以回复我~

对 自己训练的就这样 源码里的就能用 

0 回复 有任何疑惑可以回复我~

你解决了吗?我也这样


0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

运行报错NotFoundError : Key regression/Variable not found in checkpoint

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信