arunponnusamy/cvlib

Unable to execute object_detection

Opened this issue ยท 7 comments

As of rather recently I am unable to use object_detection, whereas everything else seems to work rather fine.
It boils down to that error message:

Traceback (most recent call last):#################################################################################### |
  File "detector_mine.py", line 35, in <module>
    bbox, label, conf = cv.detect_common_objects(rect_img, confidence=0.75, enable_gpu=True')
  File "/home/user/.local/lib/python3.8/site-packages/cvlib/object_detection.py", line 135, in detect_common_objects
    outs = net.forward(get_output_layers(net))
  File "/home/user/.local/lib/python3.8/site-packages/cvlib/object_detection.py", line 29, in get_output_layers
    output_layers = [layer_names[i[0] - 1] for i in net.getUnconnectedOutLayers()]
  File "/home/user/.local/lib/python3.8/site-packages/cvlib/object_detection.py", line 29, in <listcomp>
    output_layers = [layer_names[i[0] - 1] for i in net.getUnconnectedOutLayers()]
IndexError: invalid index to scalar variable.

It runs fine on my old Win10/11 installation from a couple of months ago, however accessing the same script from a WSL machine on the exact same PC results in the error above. I'm also getting the same from a new macOS setup.

Hello, I am using ubuntu and I run to the same error

I have found a temporary workaround.

If you change in line 29
output_layers = [layer_names[i[0] - 1] for i in net.getUnconnectedOutLayers()]

to (removing the typechange from list to value)
output_layers = [layer_names[i - 1] for i in net.getUnconnectedOutLayers()]

in the object_detection.py script (you'll find the location in the error message) it should work again.

Small edit: I've forked the library and added the fix there. Feel free to add it to the main project, I'll remove the fork later =)

Besides the change mentioned by @tomgit-com I also had to comment out i = i[0] on line 245:

    for i in indices:
        #i = i[0]
        box = boxes[i]

I've also noticed that issues, but it happened rather lately. I don't know if there've been some changes on the pretrained models

I think there are some changes in the latest OpenCV version. Try using with older opencv version for now. Will fix this soon.

with openCV 4.5.3.56 works, But with 4.5.4.58, 4.5.4.60(latest) doesn't work.

Hello, this issue still exists, I ran into it today. I followed tomgit-com and mihaipanait's comments and it worked. Thank you for the direction.