tensorflow模型恢复问题——saver.restore

恢复分类模型中出现问题,而且看起来很吓人那种。

2019-11-28 17:31:37.421411: W tensorflow/core/framework/op_kernel.cc:1502] OP_REQUIRES failed at save_restore_v2_ops.cc:184 : Not found: Key batch_normalization_1/beta not found in checkpoint
Traceback (most recent call last):
  File "D:\python\lib\site-packages\tensorflow\python\client\session.py", line 1356, in _do_call
    return fn(*args)
  File "D:\python\lib\site-packages\tensorflow\python\client\session.py", line 1341, in _run_fn
    options, feed_dict, fetch_list, target_list, run_metadata)
  File "D:\python\lib\site-packages\tensorflow\python\client\session.py", line 1429, in _call_tf_sessionrun
    run_metadata)
tensorflow.python.framework.errors_impl.NotFoundError: Key batch_normalization_1/beta not found in checkpoint
         [[{{node save/RestoreV2}}]]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\python\lib\site-packages\tensorflow\python\training\saver.py", line 1286, in restore
    {self.saver_def.filename_tensor_name: save_path})
  File "D:\python\lib\site-packages\tensorflow\python\client\session.py", line 950, in run
    run_metadata_ptr)
  File "D:\python\lib\site-packages\tensorflow\python\client\session.py", line 1173, in _run
    feed_dict_tensor, options, run_metadata)
  File "D:\python\lib\site-packages\tensorflow\python\client\session.py", line 1350, in _do_run
    run_metadata)
  File "D:\python\lib\site-packages\tensorflow\python\client\session.py", line 1370, in _do_call
    raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.NotFoundError: Key batch_normalization_1/beta not found in checkpoint
         [[node save/RestoreV2 (defined at my_guess_end.py:256) ]]

Original stack trace for 'save/RestoreV2':
  File "my_guess_end.py", line 271, in <module>
    tf.compat.v1.app.run()
  File "D:\python\lib\site-packages\tensorflow\python\platform\app.py", line 40, in run
    _run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef)
  File "D:\python\lib\site-packages\absl\app.py", line 300, in run
    _run_main(main, args)
  File "D:\python\lib\site-packages\absl\app.py", line 251, in _run_main
    sys.exit(main(argv))
  File "my_guess_end.py", line 256, in main
    saver = tf.compat.v1.train.Saver()
  File "D:\python\lib\site-packages\tensorflow\python\training\saver.py", line 825, in __init__
    self.build()
  File "D:\python\lib\site-packages\tensorflow\python\training\saver.py", line 837, in build
    self._build(self._filename, build_save=True, build_restore=True)
  File "D:\python\lib\site-packages\tensorflow\python\training\saver.py", line 875, in _build
    build_restore=build_restore)
  File "D:\python\lib\site-packages\tensorflow\python\training\saver.py", line 508, in _build_internal
    restore_sequentially, reshape)
  File "D:\python\lib\site-packages\tensorflow\python\training\saver.py", line 328, in _AddRestoreOps
    restore_sequentially)
  File "D:\python\lib\site-packages\tensorflow\python\training\saver.py", line 575, in bulk_restore
    return io_ops.restore_v2(filename_tensor, names, slices, dtypes)
  File "D:\python\lib\site-packages\tensorflow\python\ops\gen_io_ops.py", line 1779, in restore_v2
    name=name)
  File "D:\python\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 788, in _apply_op_helper
    op_def=op_def)
  File "D:\python\lib\site-packages\tensorflow\python\util\deprecation.py", line 507, in new_func
    return func(*args, **kwargs)
  File "D:\python\lib\site-packages\tensorflow\python\framework\ops.py", line 3616, in create_op
    op_def=op_def)
  File "D:\python\lib\site-packages\tensorflow\python\framework\ops.py", line 2005, in __init__
    self._traceback = tf_stack.extract_stack()


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\python\lib\site-packages\tensorflow\python\training\saver.py", line 1296, in restore
    names_to_keys = object_graph_key_mapping(save_path)
  File "D:\python\lib\site-packages\tensorflow\python\training\saver.py", line 1614, in object_graph_key_mapping
    object_graph_string = reader.get_tensor(trackable.OBJECT_GRAPH_PROTO_KEY)
  File "D:\python\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 678, in get_tensor
    return CheckpointReader_GetTensor(self, compat.as_bytes(tensor_str))
tensorflow.python.framework.errors_impl.NotFoundError: Key _CHECKPOINTABLE_OBJECT_GRAPH not found in checkpoint

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "my_guess_end.py", line 271, in <module>
    tf.compat.v1.app.run()
  File "D:\python\lib\site-packages\tensorflow\python\platform\app.py", line 40, in run
    _run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef)
  File "D:\python\lib\site-packages\absl\app.py", line 300, in run
    _run_main(main, args)
  File "D:\python\lib\site-packages\absl\app.py", line 251, in _run_main
    sys.exit(main(argv))
  File "my_guess_end.py", line 257, in main
    saver.restore(sess, model_checkpoint_path)
  File "D:\python\lib\site-packages\tensorflow\python\training\saver.py", line 1302, in restore
    err, "a Variable name or other graph key that is missing")
tensorflow.python.framework.errors_impl.NotFoundError: Restoring from checkpoint failed. This is most likely due to a Variable name or other graph key that is missing from the checkpoint. Please ensure that you have not altered the graph expected based on the checkpoint. Original error:

Key batch_normalization_1/beta not found in checkpoint
         [[node save/RestoreV2 (defined at my_guess_end.py:256) ]]

Original stack trace for 'save/RestoreV2':
  File "my_guess_end.py", line 271, in <module>
    tf.compat.v1.app.run()
  File "D:\python\lib\site-packages\tensorflow\python\platform\app.py", line 40, in run
    _run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef)
  File "D:\python\lib\site-packages\absl\app.py", line 300, in run
    _run_main(main, args)
  File "D:\python\lib\site-packages\absl\app.py", line 251, in _run_main
    sys.exit(main(argv))
  File "my_guess_end.py", line 256, in main
    saver = tf.compat.v1.train.Saver()
  File "D:\python\lib\site-packages\tensorflow\python\training\saver.py", line 825, in __init__
    self.build()
  File "D:\python\lib\site-packages\tensorflow\python\training\saver.py", line 837, in build
    self._build(self._filename, build_save=True, build_restore=True)
  File "D:\python\lib\site-packages\tensorflow\python\training\saver.py", line 875, in _build
    build_restore=build_restore)
  File "D:\python\lib\site-packages\tensorflow\python\training\saver.py", line 508, in _build_internal
    restore_sequentially, reshape)
  File "D:\python\lib\site-packages\tensorflow\python\training\saver.py", line 328, in _AddRestoreOps
    restore_sequentially)
  File "D:\python\lib\site-packages\tensorflow\python\training\saver.py", line 575, in bulk_restore
    return io_ops.restore_v2(filename_tensor, names, slices, dtypes)
  File "D:\python\lib\site-packages\tensorflow\python\ops\gen_io_ops.py", line 1779, in restore_v2
    name=name)
  File "D:\python\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 788, in _apply_op_helper
    op_def=op_def)
  File "D:\python\lib\site-packages\tensorflow\python\util\deprecation.py", line 507, in new_func
    return func(*args, **kwargs)
  File "D:\python\lib\site-packages\tensorflow\python\framework\ops.py", line 3616, in create_op
    op_def=op_def)
  File "D:\python\lib\site-packages\tensorflow\python\framework\ops.py", line 2005, in __init__
    self._traceback = tf_stack.extract_stack()

这种情况下,直接用原有方法恢复,测试下,only恢复模型,try

卧槽,老子又试了之前的恢复模型的方法,告诉我没有变量save

  File "D:\python\lib\site-packages\tensorflow\python\training\saver.py", line 825, in __init__
    self.build()
  File "D:\python\lib\site-packages\tensorflow\python\training\saver.py", line 837, in build
    self._build(self._filename, build_save=True, build_restore=True)
  File "D:\python\lib\site-packages\tensorflow\python\training\saver.py", line 862, in _build
    raise ValueError("No variables to save")
ValueError: No variables to save

难道先加载构造的model?

是的,先加载构造好的模型,再加载训练好的模型[有模型参数]。加载成功了。

but in fact also has the first prolem,so Y ?

search for the problem,Found that they say the version is the key,but I always in the same windows ,no more than one version !!什么鬼,算了,寡人累了,先加载这个模型吧。

寡人发现这个问题应该是MTCNN引入的,在我用MTCNN检测人脸后这个程序就出现了这个鬼,可能这玩意也有模型加载,所以两个模型冲突了。我将前者搞成函数??

果然是,经检查,引入MTCNN的确会造成模型加载失败,这是说明MTCNN是个傻逼,没做好,但加载h5模型没有问题,tf还是不行啊。但是我还是依靠小明哥的帅气,啊呸,智慧,完美解决了问题。哈哈

人生艰难,但请足够相信小明哥。

另外有相关问题可以加入QQ群讨论,不设微信群

QQ群:868373192 

语音深度学习群

猜你喜欢

转载自blog.csdn.net/SPESEG/article/details/103297879