在本地使用Tensorflow Object Detection API时出现Protobuf错误

时间:2018-05-16 13:35:14

标签: tensorflow protocol-buffers python-3.6 object-detection-api

我的机器上有张量流和对象检测API。 测试运行表明一切正常。

~ $ cd models/research
research $ protoc object_detection/protos/*.proto --python_out=.
research $ export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
research $ python3 object_detection/builders/model_builder_test.py
...............
----------------------------------------------------------------------
Ran 15 tests in 0.144s

OK

然后我尝试重新训练模型并得到protobuf错误

research $ cd object_detection
object_detection $ python3 train.py --logtostderr --train_dir=training/ --pipeline_config_path=ssdlite_mobilenet_v2_coco_2018_05_09/pipeline.config
WARNING:tensorflow:From /Users/me/models/research/object_detection/trainer.py:257: create_global_step (from tensorflow.contrib.framework.python.ops.variables) is deprecated and will be removed in a future version.
Instructions for updating:
Please switch to tf.train.create_global_step
Traceback (most recent call last):
  File "/Users/me/models/research/object_detection/utils/label_map_util.py", line 135, in load_labelmap
    text_format.Merge(label_map_string, label_map)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/google/protobuf/text_format.py", line 533, in Merge
    descriptor_pool=descriptor_pool)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/google/protobuf/text_format.py", line 587, in MergeLines
    return parser.MergeLines(lines, message)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/google/protobuf/text_format.py", line 620, in MergeLines
    self._ParseOrMerge(lines, message)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/google/protobuf/text_format.py", line 635, in _ParseOrMerge
    self._MergeField(tokenizer, message)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/google/protobuf/text_format.py", line 735, in _MergeField
    merger(tokenizer, message, field)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/google/protobuf/text_format.py", line 823, in _MergeMessageField
    self._MergeField(tokenizer, sub_message)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/google/protobuf/text_format.py", line 722, in _MergeField
    tokenizer.Consume(':')
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/google/protobuf/text_format.py", line 1087, in Consume
    raise self.ParseError('Expected "%s".' % token)
google.protobuf.text_format.ParseError: 3:10 : Expected ":".

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/google/protobuf/internal/python_message.py", line 1083, in MergeFromString
    if self._InternalParse(serialized, 0, length) != length:
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/google/protobuf/internal/python_message.py", line 1105, in InternalParse
    (tag_bytes, new_pos) = local_ReadTag(buffer, pos)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/google/protobuf/internal/decoder.py", line 181, in ReadTag
    while six.indexbytes(buffer, pos) & 0x80:
TypeError: unsupported operand type(s) for &: 'str' and 'int'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "train.py", line 184, in <module>
    tf.app.run()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 126, in run
    _sys.exit(main(argv))
  File "train.py", line 180, in main
    graph_hook_fn=graph_rewriter_fn)
  File "/Users/me/models/research/object_detection/trainer.py", line 264, in train
    train_config.prefetch_queue_capacity, data_augmentation_options)
  File "/Users/me/models/research/object_detection/trainer.py", line 59, in create_input_queue
    tensor_dict = create_tensor_dict_fn()
  File "train.py", line 121, in get_next
    dataset_builder.build(config)).get_next()
  File "/Users/me/models/research/object_detection/builders/dataset_builder.py", line 155, in build
    label_map_proto_file=label_map_proto_file)
  File "/Users/me/models/research/object_detection/data_decoders/tf_example_decoder.py", line 245, in __init__
    use_display_name)
  File "/Users/me/models/research/object_detection/utils/label_map_util.py", line 152, in get_label_map_dict
    label_map = load_labelmap(label_map_path)
  File "/Users/me/models/research/object_detection/utils/label_map_util.py", line 137, in load_labelmap
    label_map.ParseFromString(label_map_string)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/google/protobuf/message.py", line 185, in ParseFromString
    self.MergeFromString(serialized)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/google/protobuf/internal/python_message.py", line 1089, in MergeFromString
    raise message_mod.DecodeError('Truncated message.')
google.protobuf.message.DecodeError: Truncated message.
object_detection $

我尝试了一些类似问题的解决方案,但它们并不适用于我的情况。例如,this one建议使用ASCII编码pbtxt文件。

Python 2也给出了错误。这是最后一行

google.protobuf.message.DecodeError: Unexpected end-group tag.

上下文

  • macOS 10.13.4
  • 在CPU上本地运行
  • Python 3.6.4
  • protobuf 3.5.1
  • libprotoc 3.4.0
  • tensorflow 1.8.0
  • Google Cloud SDK 200.0.0
  • bq 2.0.33
  • core 2018.04.30
  • gsutil 4.31

0 个答案:

没有答案