首页 > 解决方案 > 无法将检查点模型转换为 Tensorflow 图原型

问题描述

系统信息:

我创建了自己的包含 100 张图像和 1 个类别的数据集,并运行 legacy/train.py 脚本进行训练。我得到了以下检查点文件:

model.ckpt-649.data-00000-of-00001
model.ckpt-649.index
model.ckpt-649.meta

但是,当我运行 export_inference_graph.py 文件时出现以下错误。

python .\object_detection\export_inference_graph.py --input_type image_tensor --pipeline_config_path .\object_detection\training\ssd_mobilenet_v1_pets.config --trained_checkpoint_prefix .\object_detection\training\model.ckpt-649.index --output_directory .\object_detection\trained-inference -图表

我最终想使用 .pb 文件使用 tensorflow 提供的代码来评估模型。

日志:

Traceback (most recent call last):
  File "C:\Anaconda3\Lib\site-packages\tensorflow\python\client\session.py", line 1278, in _do_call
    return fn(*args)
  File "C:\Anaconda3\Lib\site-packages\tensorflow\python\client\session.py", line 1263, in _run_fn
    options, feed_dict, fetch_list, target_list, run_metadata)
  File "C:\Anaconda3\Lib\site-packages\tensorflow\python\client\session.py", line 1350, in _call_tf_sessionrun
    run_metadata)
tensorflow.python.framework.errors_impl.NotFoundError: Tensor name "BoxPredictor_0/BoxEncodingPredictor/biases" not found in checkpoint fil
es .\object_detection\training\model.ckpt-649.index
         [[Node: save/RestoreV2 = RestoreV2[dtypes=[DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, ..., DT_FLOAT, DT_FLOAT, DT_FLOAT, DT
_FLOAT, DT_INT64], _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:\Anaconda3\Lib\site-packages\tensorflow\python\training\saver.py", line 1725, in restore
    {self.saver_def.filename_tensor_name: save_path})
  File "C:\Anaconda3\Lib\site-packages\tensorflow\python\client\session.py", line 877, in run
    run_metadata_ptr)
  File "C:\Anaconda3\Lib\site-packages\tensorflow\python\client\session.py", line 1100, in _run
    feed_dict_tensor, options, run_metadata)
  File "C:\Anaconda3\Lib\site-packages\tensorflow\python\client\session.py", line 1272, in _do_run
    run_metadata)
  File "C:\Anaconda3\Lib\site-packages\tensorflow\python\client\session.py", line 1291, in _do_call
    raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.NotFoundError: Tensor name "BoxPredictor_0/BoxEncodingPredictor/biases" not found in checkpoint fil
es .\object_detection\training\model.ckpt-649.index
         [[Node: save/RestoreV2 = RestoreV2[dtypes=[DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, ..., DT_FLOAT, DT_FLOAT, DT_FLOAT, DT
_FLOAT, DT_INT64], _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 ".\object_detection\export_inference_graph.py", line 153, in <module>
    tf.app.run()
  File "C:\Anaconda3\Lib\site-packages\tensorflow\python\platform\app.py", line 125, in run
    _sys.exit(main(argv))
  File ".\object_detection\export_inference_graph.py", line 149, in main
    write_inference_graph=FLAGS.write_inference_graph)
  File "C:\Anaconda3\Lib\site-packages\tensorflow\models\research\object_detection\exporter.py", line 405, in export_inference_graph
    write_inference_graph=write_inference_graph)
  File "C:\Anaconda3\Lib\site-packages\tensorflow\models\research\object_detection\exporter.py", line 334, in _export_inference_graph
    trained_checkpoint_prefix=checkpoint_to_use)
  File "C:\Anaconda3\Lib\site-packages\tensorflow\models\research\object_detection\exporter.py", line 241, in write_graph_and_checkpoint
    tf.import_graph_def(inference_graph_def, name='')
  File "C:\Anaconda3\Lib\site-packages\tensorflow\python\util\deprecation.py", line 454, in new_func
    return func(*args, **kwargs)
  File "C:\Anaconda3\Lib\site-packages\tensorflow\python\framework\importer.py", line 442, in import_graph_def
    _ProcessNewOps(graph)
  File "C:\Anaconda3\Lib\site-packages\tensorflow\python\framework\importer.py", line 234, in _ProcessNewOps
    for new_op in graph._add_new_tf_operations(compute_devices=False):  # pylint: disable=protected-access
  File "C:\Anaconda3\Lib\site-packages\tensorflow\python\framework\ops.py", line 3289, in _add_new_tf_operations
    for c_op in c_api_util.new_tf_operations(self)
  File "C:\Anaconda3\Lib\site-packages\tensorflow\python\framework\ops.py", line 3289, in <listcomp>
    for c_op in c_api_util.new_tf_operations(self)
  File "C:\Anaconda3\Lib\site-packages\tensorflow\python\framework\ops.py", line 3180, in _create_op_from_tf_operation
    ret = Operation(c_op, self)
  File "C:\Anaconda3\Lib\site-packages\tensorflow\python\framework\ops.py", line 1717, in __init__
    self._traceback = tf_stack.extract_stack()

NotFoundError (see above for traceback): Tensor name "BoxPredictor_0/BoxEncodingPredictor/biases" not found in checkpoint files .\object_de
tection\training\model.ckpt-649.index
         [[Node: save/RestoreV2 = RestoreV2[dtypes=[DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, ..., DT_FLOAT, DT_FLOAT, DT_FLOAT, DT
_FLOAT, DT_INT64], _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:\Anaconda3\Lib\site-packages\tensorflow\python\training\saver.py", line 1737, in restore
    checkpointable.OBJECT_GRAPH_PROTO_KEY)
  File "C:\Anaconda3\Lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 348, in get_tensor
    status)
  File "C:\Anaconda3\Lib\site-packages\tensorflow\python\framework\errors_impl.py", line 519, in __exit__
    c_api.TF_GetCode(self.status.status))
tensorflow.python.framework.errors_impl.NotFoundError: _CHECKPOINTABLE_OBJECT_GRAPH not found in checkpoint file

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File ".\object_detection\export_inference_graph.py", line 153, in <module>
    tf.app.run()
  File "C:\Anaconda3\Lib\site-packages\tensorflow\python\platform\app.py", line 125, in run
    _sys.exit(main(argv))
  File ".\object_detection\export_inference_graph.py", line 149, in main
    write_inference_graph=FLAGS.write_inference_graph)
  File "C:\Anaconda3\Lib\site-packages\tensorflow\models\research\object_detection\exporter.py", line 405, in export_inference_graph
    write_inference_graph=write_inference_graph)
  File "C:\Anaconda3\Lib\site-packages\tensorflow\models\research\object_detection\exporter.py", line 334, in _export_inference_graph
    trained_checkpoint_prefix=checkpoint_to_use)
  File "C:\Anaconda3\Lib\site-packages\tensorflow\models\research\object_detection\exporter.py", line 245, in write_graph_and_checkpoint
    saver.restore(sess, trained_checkpoint_prefix)
  File "C:\Anaconda3\Lib\site-packages\tensorflow\python\training\saver.py", line 1743, 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. Origin
al error:

Tensor name "BoxPredictor_0/BoxEncodingPredictor/biases" not found in checkpoint files .\object_detection\training\model.ckpt-649.index
         [[Node: save/RestoreV2 = RestoreV2[dtypes=[DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, ..., DT_FLOAT, DT_FLOAT, DT_FLOAT, DT
_FLOAT, DT_INT64], _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 ".\object_detection\export_inference_graph.py", line 153, in <module>
    tf.app.run()
  File "C:\Anaconda3\Lib\site-packages\tensorflow\python\platform\app.py", line 125, in run
    _sys.exit(main(argv))
  File ".\object_detection\export_inference_graph.py", line 149, in main
    write_inference_graph=FLAGS.write_inference_graph)
  File "C:\Anaconda3\Lib\site-packages\tensorflow\models\research\object_detection\exporter.py", line 405, in export_inference_graph
    write_inference_graph=write_inference_graph)
  File "C:\Anaconda3\Lib\site-packages\tensorflow\models\research\object_detection\exporter.py", line 334, in _export_inference_graph
    trained_checkpoint_prefix=checkpoint_to_use)
  File "C:\Anaconda3\Lib\site-packages\tensorflow\models\research\object_detection\exporter.py", line 241, in write_graph_and_checkpoint
    tf.import_graph_def(inference_graph_def, name='')
  File "C:\Anaconda3\Lib\site-packages\tensorflow\python\util\deprecation.py", line 454, in new_func
    return func(*args, **kwargs)
  File "C:\Anaconda3\Lib\site-packages\tensorflow\python\framework\importer.py", line 442, in import_graph_def
    _ProcessNewOps(graph)
  File "C:\Anaconda3\Lib\site-packages\tensorflow\python\framework\importer.py", line 234, in _ProcessNewOps
    for new_op in graph._add_new_tf_operations(compute_devices=False):  # pylint: disable=protected-access
  File "C:\Anaconda3\Lib\site-packages\tensorflow\python\framework\ops.py", line 3289, in _add_new_tf_operations
    for c_op in c_api_util.new_tf_operations(self)
  File "C:\Anaconda3\Lib\site-packages\tensorflow\python\framework\ops.py", line 3289, in <listcomp>
    for c_op in c_api_util.new_tf_operations(self)
  File "C:\Anaconda3\Lib\site-packages\tensorflow\python\framework\ops.py", line 3180, in _create_op_from_tf_operation
    ret = Operation(c_op, self)
  File "C:\Anaconda3\Lib\site-packages\tensorflow\python\framework\ops.py", line 1717, in __init__
    self._traceback = tf_stack.extract_stack()

NotFoundError (see above for traceback): 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:

Tensor name "BoxPredictor_0/BoxEncodingPredictor/biases" not found in checkpoint files .\object_detection\training\model.ckpt-649.index
         [[Node: save/RestoreV2 = RestoreV2[dtypes=[DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, ..., DT_FLOAT, DT_FLOAT, DT_FLOAT, DT
_FLOAT, DT_INT64], _device="/job:localhost/replica:0/task:0/device:CPU:0"](_arg_save/Const_0_0, save/RestoreV2/tensor_names, save/RestoreV2
/shape_and_slices)]]

标签: pythontensorflow

解决方案


推荐阅读