从object_detection.protos导入string_int_label_map_pb2 ModuleNotFoundError:

时间:2018-07-07 18:32:34

标签: python tensorflow protoc

我正在使用来自github的python中的tensorflow的正式代码,但我没有传递该错误:

import tensorflow as tf

import cv2
cap = cv2.VideoCapture(1)

# This is needed since the notebook is stored in the object_detection folder.
sys.path.append("..")



# ## Object detection imports
# Here are the imports from the object detection module.

# In[3]:
from object_detection.utils import label_map_util
 File "C:/Users/azach/Desktop/python/tensorflow/models- 
master/research/object_detection/utils/label_map_util.py", line 22, in 
<module>
from object_detection.protos import string_int_label_map_pb2

ModuleNotFoundError: No module named 'object_detection'

有人在这里建议

Tensorflow: has no attribute 'load_labelmap'

我改变了

 from object_detection.protos import string_int_label_map_pb2

对此:

 from protos import string_int_label_map_pb2

我在Windows 10上使用Python 3.6.5,tensorflow 1.8。*。proto文件是使用协议3.4编译的。

编辑:来自cmd的错误:

label_map = label_map_util.load_labelmap(PATH_TO_LABELS)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'label_map_util' is not defined
>>> categories = label_map_util.convert_label_map_to_categories(label_map, 
max_num_classes=NUM_CLASSES, use_display_name=True)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'label_map_util' is not defined
>>> category_index = label_map_util.create_category_index(categories)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'label_map_util' is not defined

1 个答案:

答案 0 :(得分:0)

如果您使用的是Windows OS,请在命令提示符下将目录更改为research(object_detection的父目录)文件夹,然后运行以下命令。根据您所使用的操作系统相应地更改命令

1)协议object_detection / protos / *。proto --python_out =。

2)SET PYTHONPATH =%cd%;%cd%\ slim

然后从同一命令行启动笔记本计算机并尝试运行。

我不确定以下行的用途,请尝试不使用行 sys.path.append(“ ..”)