如何解决"属性错误:模块'google.protobuf.descriptor'没有属性'_internal_create_key"?



我在jupyter笔记本中从object_detection.utils导入label_map_utils时遇到此问题。它实际上是tensorflow对象检测教程笔记本。我检查过类似的问题"如何解决";AttributeError:模块';google.protobuf.descriptor';没有属性'_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.protox12x17object_detection.protos"xeex01nx15StringIntLabelMapItemx12x0cnx04namex18x01 x01(tx12nnx02idx18x02 x01(x05x12x14nx0cx64isplay_namex18x03 x01(tx12Mntkeypointsx18x04 x03(x0bx32:.object_detection.protos.StringIntLabelMapItem.KeypointMapx12x14nx0cx61ncestor_idsx18x05 x03(x05x12x16nx0ex64x65scendant_idsx18x06 x03(x05x1a(nx0bKeypointMapx12nnx02idx18x01 x01(x05x12rnx05labelx18x02 x01(t"Qnx11StringIntLabelMapx12<nx04itemx18x01 x03(x0bx32..object_detection.protos.StringIntLabelMapItem'
23 )
AttributeError: module 'google.protobuf.descriptor' has no attribute '_internal_create_key'```

版本不匹配可能会导致该问题。跑CCD_ 1,CCD_ 2,protoc --version

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

如果没有,就跑吧CCD_ 4,pip install --upgrade protobuf

这为我解决了类似的问题

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

最新更新