【问题标题】:Tensorflow: has no attribute 'load_labelmap'Tensorflow:没有属性“load_labelmap”
【发布时间】:2017-07-25 21:20:40
【问题描述】:

我按照他们的 Github 上描述的步骤安装了Object Detection API,然后我运行了这个脚本:

python object_detection/builders/model_builder_test.py

并且测试成功了,所以我认为一切都设置正确。接下来我尝试使用 qtconsole 运行 Jupyter Notebook 来检测测试图像中的对象。但是它返回此错误:

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'

有人知道这个问题的原因是什么吗?

谢谢。

【问题讨论】:

  • 该回溯描述了“ipython-input-3”,但您显示了python 的命令行调用。你能显示你通过命令行调用得到的错误吗?如果你不能重现它,那么它几乎肯定与问题有关。 IIRC ipython 不适合 virtualenv(除非你在你的 virtualenv 中构建/安装它?)
  • 所以我将 Jupyter Notebook object_detection_tutorial.ipynb 转换为 python 脚本,并从命令行使用 ipython 调用它。我仍然遇到同样的错误。
  • commit that added this feature is relatively new。你确定你有一个兼容的版本吗?
  • 我在 3 天前下载了存储库,在您链接提交之后很长一段时间。无论如何,我只是再次克隆它并运行 Jupyter notebook,它现在似乎可以工作了!不知道到底是什么问题,但谢谢!

标签: machine-learning tensorflow


【解决方案1】:

在文件~\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 的导入失败。

如果您查看print(dir(label_map_util)) 的输出,您可以看到这一点。

使用object_detection.protos时:

['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'logging', 'text_format', 'tf']

将相对路径更改为protos 后,该函数应该可以访问了:

['__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']

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-07
    • 2020-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-05
    • 2019-08-04
    • 1970-01-01
    相关资源
    最近更新 更多