Reputation: 113
Getting an error for IndexError: invalid index to scalar variable on the yolo_layers line.
network = cv2.dnn.readNetFromDarknet('yolov3.cfg', 'yolov3.weights')
layers = network.getLayerNames()
yolo_layers = [layers[i[0] - 1] for i in network.getUnconnectedOutLayers()]
This code won't work on my Jupyter notebook but will run fine on google collab. No idea why. Could be my python version?
Upvotes: 9
Views: 11111
Reputation: 21203
For CPU versions:
network = cv2.dnn.readNetFromDarknet('yolov3.cfg', 'yolov3.weights')
layers = network.getLayerNames()
yolo_layers = [layers[i - 1] for i in network.getUnconnectedOutLayers()]
returns: ['yolo_82', 'yolo_94', 'yolo_106']
Tested on OpenCV version 4.5.5
.
Upvotes: 7
Reputation: 164
It's may caused by the different versions of cv2. The version of cv2 module with CUDA support will give you a 2-D array when calling network.getUnconnectedOutLayers()
. However, the version without CUDA support will give a 1-D array.
You may try to take the brackets out which closing the index 0.
Upvotes: 14