Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to execute object_detection #46

Open
tomgit-com opened this issue Nov 1, 2021 · 7 comments
Open

Unable to execute object_detection #46

tomgit-com opened this issue Nov 1, 2021 · 7 comments

Comments

@tomgit-com
Copy link

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.

@claudia-hm
Copy link

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

@tomgit-com
Copy link
Author

tomgit-com commented Nov 3, 2021

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 =)

@mihaipanait
Copy link

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]

@tomgit-com
Copy link
Author

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

@arunponnusamy
Copy link
Owner

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

@motskin
Copy link

motskin commented Dec 8, 2021

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

arunponnusamy added a commit that referenced this issue Feb 5, 2022
@Greg-Kojadinovich
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants