所以我正在关注senddex的对象检测教程,我已经到了应该导出推理图的步骤。我正在使用 Tensorflow 的 object_detection 文件夹中的“export_inference_graph.py”脚本。
问题是我收到了这个 ValueError:

Traceback (most recent call last):
  File "C:\Users\Zelcore-Dator\AppData\Local\Programs\Python\Python35\lib\site-packages\google\proto
buf\internal\python_message.py", line 545, in _GetFieldByName
    return message_descriptor.fields_by_name[field_name]
KeyError: 'layout_optimizer'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "export_inference_graph.py", line 119, in <module>
    tf.app.run()
  File "C:\Users\Zelcore-Dator\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\p
ython\platform\app.py", line 48, in run
    _sys.exit(main(_sys.argv[:1] + flags_passthrough))
  File "export_inference_graph.py", line 115, in main
    FLAGS.output_directory, input_shape)
  File "C:\Users\Zelcore-Dator\AppData\Local\Programs\Python\Python35\lib\site-packages\object_detec
tion-0.1-py3.5.egg\object_detection\exporter.py", line 427, in export_inference_graph
    input_shape, optimize_graph, output_collection_name)
  File "C:\Users\Zelcore-Dator\AppData\Local\Programs\Python\Python35\lib\site-packages\object_detec
tion-0.1-py3.5.egg\object_detection\exporter.py", line 391, in _export_inference_graph
    initializer_nodes='')
  File "C:\Users\Zelcore-Dator\AppData\Local\Programs\Python\Python35\lib\site-packages\object_detec
tion-0.1-py3.5.egg\object_detection\exporter.py", line 72, in freeze_graph_with_def_protos
    layout_optimizer=rewriter_config_pb2.RewriterConfig.ON)
  File "C:\Users\Zelcore-Dator\AppData\Local\Programs\Python\Python35\lib\site-packages\google\proto
buf\internal\python_message.py", line 484, in init
    field = _GetFieldByName(message_descriptor, field_name)
  File "C:\Users\Zelcore-Dator\AppData\Local\Programs\Python\Python35\lib\site-packages\google\proto
buf\internal\python_message.py", line 548, in _GetFieldByName
    (message_descriptor.name, field_name))
ValueError: Protocol message RewriterConfig has no "layout_optimizer" field.

我猜它与 protobuf 有关系,但我已经重新安装了几次都没有成功。
所有帮助表示赞赏

最佳答案

也发生在我身上。几周前没有发生。
在修复错误之前,您可以使用仍然有效的早期版本。
替换“object_detection/exporter.py”中的第 72 行:

layout_optimizer=rewriter_config_pb2.RewriterConfig.ON)

使用旧的和工作的线:
optimize_tensor_layout=True)

关于python - 导出推理图时出错 (ValueError),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48215159/

10-12 19:31