3

我在 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:没有属性“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 文件是用 protoc 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
4

1 回答 1

1

如果您在 Windows 操作系统上,从命令提示符更改目录到研究(object_detection 的父级)文件夹运行以下命令。根据您所在的操作系统相应地更改命令

1) protoc object_detection/protos/*.proto --python_out=。

2) 设置 PYTHONPATH=%cd%;%cd%\slim

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

我不确定以下行的目的,尝试不运行 sys.path.append("..")

于 2018-07-09T19:14:44.523 回答