如何解决“ AttributeError:模块'google.protobuf.descriptor'没有属性'_internal_create_key”?

时间:2020-07-14 18:14:52

标签: tensorflow object-detection object-detection-api

从jupyter笔记本中的object_detection.utils import label_map_util运行时,我正在解决此问题。它实际上是tensorflow对象检测教程笔记本。我已经检查了类似的问题How to solve "AttributeError: module 'google.protobuf.descriptor' has no attribute '_internal_create_key"?,但答案并没有帮助我。我找不到应该做什么。

AttributeError                            Traceback (most recent call last)
<ipython-input-1-79a144ec076e> in <module>
     16 import tensorflow as tf
     17 
---> 18 from object_detection.utils import label_map_util
     19 from object_detection.utils import config_util
     20 from object_detection.utils import visualization_utils as viz_utils

~/Company/Projects/ADP/models/research/object_detection/utils/label_map_util.py in <module>
     27 import tensorflow.compat.v1 as tf
     28 from google.protobuf import text_format
---> 29 from object_detection.protos import string_int_label_map_pb2
     30 
     31 _LABEL_OFFSET = 1

~/Company/Projects/ADP/models/research/object_detection/protos/string_int_label_map_pb2.py in <module>
     19   syntax='proto2',
     20   serialized_options=None,
---> 21   create_key=_descriptor._internal_create_key,
     22   serialized_pb=b'\n2object_detection/protos/string_int_label_map.proto\x12\x17object_detection.protos\"\xee\x01\n\x15StringIntLabelMapItem\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\n\n\x02id\x18\x02 \x01(\x05\x12\x14\n\x0c\x64isplay_name\x18\x03 \x01(\t\x12M\n\tkeypoints\x18\x04 \x03(\x0b\x32:.object_detection.protos.StringIntLabelMapItem.KeypointMap\x12\x14\n\x0c\x61ncestor_ids\x18\x05 \x03(\x05\x12\x16\n\x0e\x64\x65scendant_ids\x18\x06 \x03(\x05\x1a(\n\x0bKeypointMap\x12\n\n\x02id\x18\x01 \x01(\x05\x12\r\n\x05label\x18\x02 \x01(\t\"Q\n\x11StringIntLabelMap\x12<\n\x04item\x18\x01 \x03(\x0b\x32..object_detection.protos.StringIntLabelMapItem'
     23 )

AttributeError: module 'google.protobuf.descriptor' has no attribute '_internal_create_key'```

1 个答案:

答案 0 :(得分:2)

版本不匹配会导致该问题。 跑步 pip2 show protobuf pip show protobuf protoc --version

所有应该返回相同的版本。

如果没有,就运行 pip2 install --upgrade protobuf pip install --upgrade protobuf

这为我解决了类似的问题。

如果是python3,使用pip3 install --upgrade protobuf