2017-07-25 110 views
3

我跟着他們的Github上描述的步驟來安裝Object Detection API然後我跑這個腳本:Tensorflow:有沒有屬性「load_labelmap」

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' 

有沒有人有一個想法是什麼原因導致這個問題?

謝謝。

+0

這追溯介紹了「'IPython中輸入-3' 「然而你顯示了對'python'的命令行調用。你可以通過命令行調用顯示錯誤嗎?如果你不能複製它,那麼它幾乎肯定與問題有關。 IIRC'ipython'與virtualenv搭配不好(除非你在virtualenv中構建/安裝它) –

+0

因此,我將Jupyter Notebook object_detection_tutorial.ipynb轉換爲python腳本,並從命令行通過ipython調用它。我仍然得到同樣的錯誤。 – noobprogrammer

+1

[添加此功能的提交相對較新](https://github.com/tensorflow/models/commit/a4944a57ad2811e1f6a7a87589a9fc8a776e8d3c)。你確定你有一個兼容的版本? –

回答

0

在文件~\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']

相關問題