3

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

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?

Thanks.

UmarZaii
  • 1,355
  • 1
  • 17
  • 26
  • That traceback describes "`ipython-input-3`" and yet you show a command-line invocation of `python`. Can you show the error that you get with the command-line invocation instead? If you can't reproduce it, then it's almost certainly related to the problem. IIRC `ipython` doesn't play nice with virtualenv (unless you build/install it in your virtualenv?) – Brian Cain Jul 25 '17 at 21:26
  • So I converted the Jupyter Notebook object_detection_tutorial.ipynb to a python script and invoked it with ipython from the command-line. I still get the same error. – noobprogrammer Jul 25 '17 at 21:47
  • 1
    The [commit that added this feature is relatively new](https://github.com/tensorflow/models/commit/a4944a57ad2811e1f6a7a87589a9fc8a776e8d3c). Are you sure you got a compatible release? – Brian Cain Jul 25 '17 at 22:03
  • I downloaded the repository just 3 days ago, quite a while after the commit you linked. Anyway, I just cloned it again and run the Jupyter notebook and it seems to work now! Not sure what exactly the problem was, but thanks! – noobprogrammer Jul 25 '17 at 22:16

1 Answers1

0

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

Try changing this:

from object_detection.protos import string_int_label_map_pb2

to this:

from protos import string_int_label_map_pb2

Explanation:

The function load_labelmap in the module label_map_util isn't accessible because the import of string_int_label_map_pb2 is failing.

You can see this if you look at the output of print(dir(label_map_util)).

When using object_detection.protos:

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

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

alphaleonis
  • 1,329
  • 11
  • 18