title: Protobuf errors while using Tensorflow Object Detection API locally
body: <p>I got tensorflow and object detection API on my machine.
  Test run shows that everything works.</p>
  
  <pre><code>~ $ 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
  </code></pre>
  
  <p>Then I tried to retrain a model and got the protobuf error</p>
  
  <pre><code>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) &amp; 0x80:
  TypeError: unsupported operand type(s) for &amp;: 'str' and 'int'
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File "train.py", line 184, in &lt;module&gt;
      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 $
  </code></pre>
  
  <p>I tried a bunch of similar problems' solutions, but they didn't work for my case. For example <a href="https://github.com/tensorflow/models/issues/1897" rel="nofollow noreferrer">this one</a> suggest to encode pbtxt file with ASCII.</p>
  
  <p>Python 2 gives an error too. Here is it's last line</p>
  
  <pre><code>google.protobuf.message.DecodeError: Unexpected end-group tag.
  </code></pre>
  
  <p><strong>Context:</strong></p>
  
  <ul>
  <li>macOS 10.13.4</li>
  <li>Local run on CPU</li>
  <li>Python 3.6.4</li>
  <li>protobuf 3.5.1</li>
  <li>libprotoc 3.4.0</li>
  <li>tensorflow 1.8.0</li>
  <li>Google Cloud SDK 200.0.0</li>
  <li>bq 2.0.33</li>
  <li>core 2018.04.30</li>
  <li>gsutil 4.31</li>
  </ul>