Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Object_Detection_Demo: Google protobuf text_format.Merge: a bytes-like object is required, not 'str'

Reference: object_detection_tutorial.ipynb

NOTE : I have successfully installed everything according to installation instructions Installation and researched regarding this on github but had no luck.

Label maps map indices to category names, so that when our convolution network predicts 5, we know that this corresponds to airplane.

label_map = label_map_util.load_labelmap(PATH_TO_LABELS)

This raises a error as

TypeError: a bytes-like object is required, not 'str'

After drilling down in this function label_map_util.load_labelmap, below is the used function (load_labelmap)

from google.protobuf import text_format
from object_detection.protos import string_int_label_map_pb2

with tf.gfile.GFile(PATH_TO_LABELS, 'rb') as fid:
    label_map_string = fid.read()
    label_map = string_int_label_map_pb2.StringIntLabelMap()
    print(type(label_map_string))
    print(type(label_map))
    try:
      text_format.Merge(label_map_string, label_map)
    except text_format.ParseError:
      label_map.ParseFromString(label_map_string)

I tried to see the error which is same. But label_map_string is already a Bytes object as you can see in the output. Tried 'r' mode also while reading.

OUTPUT

<class 'bytes'>
<class 'object_detection.protos.string_int_label_map_pb2.StringIntLabelMap'>
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-25-3fce64fd5c00> in <module>()
      5     print(type(label_map))
      6     try:
----> 7       text_format.Merge(label_map_string, label_map)
      8     except text_format.ParseError:
      9       label_map.ParseFromString(label_map_string)

C:\Users\GUS9KOR\AppData\Local\Continuum\Anaconda3\envs\dlnd\lib\site-packages\protobuf-3.3.0-py3.5.egg\google\protobuf\text_format.py in Merge(text, message, allow_unknown_extension, allow_field_number, descriptor_pool)
    475   """
    476   return MergeLines(
--> 477       text.split('\n'),
    478       message,
    479       allow_unknown_extension,

TypeError: a bytes-like object is required, not 'str'

Thanks in advance.

like image 623
Saurav Gupta Avatar asked Oct 16 '25 20:10

Saurav Gupta


1 Answers

If found that upgrading from TensorFlow 1.0.0 to TensorFlow 1.2.0 resolved this error. I am using protobuf==3.3.0 on a mac.

like image 89
MyopicVisage Avatar answered Oct 19 '25 10:10

MyopicVisage