Tensorflow:没有属性'load_labelmap' [英] Tensorflow: has no attribute 'load_labelmap'
问题描述
我按照他们在Github上描述的步骤安装了对象检测API ,然后运行此脚本:
I followed the steps described on their Github to install the Object Detection API and then I ran this script:
python object_detection/builders/model_builder_test.py
并且测试成功,所以我认为一切都已正确设置.接下来,我尝试运行带有qtconsole的Jupyter Notebook,以检测测试图像中的对象.但是,它返回此错误:
and the test were successful, so I assumed everything was setup correctly. Next I tried to run the Jupyter Notebook with qtconsole to detect objects in the test images. However it returns this error:
AttributeError Traceback (most recent call last)
<ipython-input-3-be6fe1ba8733> in <module>()
----> 1 from utils import label_map_util
2
3 from utils import visualization_utils as vis_util
4
~\Desktop\Objectdetection\models-master\object_detection\utils\label_map_util.py in <module>()
20 import tensorflow as tf
21 from google.protobuf import text_format
---> 22 from object_detection.protos import string_int_label_map_pb2
23
24
~\Desktop\Objectdetection\models-master\object_detection\object_detection.py in <module>()
114
115
--> 116 label_map = label_map_util.load_labelmap(PATH_TO_LABELS)
117 categories = label_map_util.convert_label_map_to_categories(label_map, max_num_classes=NUM_CLASSES, use_display_name=True)
118 category_index = label_map_util.create_category_index(categories)
AttributeError: module 'utils.label_map_util' has no attribute 'load_labelmap'
有人知道这个问题的原因是什么吗?
Does anyone have an idea what the cause of this problem is?
谢谢.
推荐答案
在文件~\Desktop\Objectdetection\models-master\object_detection\utils\label_map_util.py
尝试更改此内容:
from object_detection.protos import string_int_label_map_pb2
对此:
from protos import string_int_label_map_pb2
说明:
模块label_map_util
中的功能load_labelmap
无法访问,因为string_int_label_map_pb2
的导入失败.
The function load_labelmap
in the module label_map_util
isn't accessible because the import of string_int_label_map_pb2
is failing.
如果查看print(dir(label_map_util))
的输出,则可以看到此内容.
You can see this if you look at the output of print(dir(label_map_util))
.
使用object_detection.protos
时:
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'logging', 'text_format', 'tf']
将相对路径更改为protos
后,应该可以访问该功能:
After the changing the relative path to protos
the function should be accessible:
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_validate_label_map', 'convert_label_map_to_categories', 'create_category_index', 'get_label_map_dict', 'load_labelmap', 'logging', 'string_int_label_map_pb2', 'text_format', 'tf']
这篇关于Tensorflow:没有属性'load_labelmap'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!