Tensorflow: has no load_labelmap attribute.

I followed the steps outlined on their Github to install the Object Detection API and then I ran this script:

python object_detection/builders/model_builder_test.py

      

and the test was successful, so I figured everything was set up correctly. Then I tried to run Jupyter Notebook with qtconsole to detect objects in 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 know what is the cause of this problem?

Thank.

+3


source to share


1 answer


In file ~\Desktop\Objectdetection\models-master\object_detection\utils\label_map_util.py

Try to change this:

from object_detection.protos import string_int_label_map_pb2

:

from protos import string_int_label_map_pb2

Explanation



The function load_labelmap

in the module is label_map_util

not available because the import is string_int_label_map_pb2

not in progress.

This can be seen if you look at the result print(dir(label_map_util))

.

When using object_detection.protos

:

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

After changing the relative path to the protos

function, it should be available:

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

0


source







All Articles