參考: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'
感謝。
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 ** –
你可以試試運行「print google.protobuf .__ version__」?我見過其他用戶遇到與protobuf運行時庫類似的問題(不是編譯器)。 此外,你可以考慮將tensorflow安裝升級到1.2嗎?無論如何,隨着我們使用更新的TF操作系統,我們需要更改SSD模型。 –