Skip to content

Commit af7dff5

Browse files
committed
fix issue on yolov3 tutorial
1 parent 3105f40 commit af7dff5

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

machine-learning/object-detection/live_yolo_opencv.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@
1616
net = cv2.dnn.readNetFromDarknet(config_path, weights_path)
1717

1818
ln = net.getLayerNames()
19-
ln = [ln[i[0] - 1] for i in net.getUnconnectedOutLayers()]
19+
try:
20+
ln = [ln[i[0] - 1] for i in net.getUnconnectedOutLayers()]
21+
except IndexError:
22+
# in case getUnconnectedOutLayers() returns 1D array when CUDA isn't available
23+
ln = [ln[i - 1] for i in net.getUnconnectedOutLayers()]
2024

2125
cap = cv2.VideoCapture(0)
2226

machine-learning/object-detection/read_video.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717
net = cv2.dnn.readNetFromDarknet(config_path, weights_path)
1818

1919
ln = net.getLayerNames()
20-
ln = [ln[i[0] - 1] for i in net.getUnconnectedOutLayers()]
20+
try:
21+
ln = [ln[i[0] - 1] for i in net.getUnconnectedOutLayers()]
22+
except IndexError:
23+
# in case getUnconnectedOutLayers() returns 1D array when CUDA isn't available
24+
ln = [ln[i - 1] for i in net.getUnconnectedOutLayers()]
2125
# read the file from the command line
2226
video_file = sys.argv[1]
2327
cap = cv2.VideoCapture(video_file)

machine-learning/object-detection/yolo_opencv.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@
3737

3838
# get all the layer names
3939
ln = net.getLayerNames()
40-
ln = [ln[i[0] - 1] for i in net.getUnconnectedOutLayers()]
40+
try:
41+
ln = [ln[i[0] - 1] for i in net.getUnconnectedOutLayers()]
42+
except IndexError:
43+
# in case getUnconnectedOutLayers() returns 1D array when CUDA isn't available
44+
ln = [ln[i - 1] for i in net.getUnconnectedOutLayers()]
4145
# feed forward (inference) and get the network output
4246
# measure how much it took in seconds
4347
start = time.perf_counter()

0 commit comments

Comments
 (0)