Search code examples
pythontensorflowopencvmachine-learningyolo

Loading YOLO: invalid index to scalar variable


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?


Solution

  • 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.