2017-07-06 630 views
2

参考:object_detection_tutorial.ipynbObject_Detection_Demo:谷歌的protobuf text_format.Merge:一类字节对象是必需的,而不是“海峡”

注:我已经按照安装说明Installation成功安装了一切,并研究在github上对此却都没有运气。

标签将地图索引映射到类别名称,所以当我们的卷积网络预测5时,我们知道这对应于飞机。

label_map = label_map_util.load_labelmap(PATH_TO_LABELS) 

这就提出了一个错误作为

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

向下钻取在此函数label_map_util.load_labelmap后,以下是所使用的函数(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) 

我试图看到错误是相同的。但是,您可以在输出中看到label_map_string已经是Bytes对象。阅读时也试过'r'模式。

提前输出

<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' 

感谢。

回答

0

您能否提供有关您的环境的更多信息?我已经在使用Anaconda 3的Windows 10机器上完成了这项工作。具体来说,您使用的是何种版本的tensorflow,以及您使用哪种版本的protoc编译原型?

+0

Windows 7,Conda 4.3.22,tensorflow 1.0.0 protobuf 3.3.0已安装。 但是对于编译protos目录文件,我不得不使用Protobuf二进制exe文件,如这里所述[https://github.com/tensorflow/models/issues/1591] astrung **对于窗口用户:使用protobuf二进制:protoc-3.3.0-win32.zip然后:\ link \ to \ protoc object_detection/protos/*。proto --python_out =。 >那么你可以导入string_int_label_map_pb2 ** –

+2

你可以试试运行“print google.protobuf .__ version__”?我见过其他用户遇到与protobuf运行时库类似的问题(不是编译器)。 此外,你可以考虑将tensorflow安装升级到1.2吗?无论如何,随着我们使用更新的TF操作系统,我们需要更改SSD模型。 –

2

如果发现从TensorFlow 1.0.0升级到TensorFlow 1.2.0解决了此错误。我在mac上使用protobuf == 3.3.0。

相关问题