File tree 3 files changed +15
-3
lines changed
machine-learning/object-detection
3 files changed +15
-3
lines changed Original file line number Diff line number Diff line change 16
16
net = cv2 .dnn .readNetFromDarknet (config_path , weights_path )
17
17
18
18
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 ()]
20
24
21
25
cap = cv2 .VideoCapture (0 )
22
26
Original file line number Diff line number Diff line change 17
17
net = cv2 .dnn .readNetFromDarknet (config_path , weights_path )
18
18
19
19
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 ()]
21
25
# read the file from the command line
22
26
video_file = sys .argv [1 ]
23
27
cap = cv2 .VideoCapture (video_file )
Original file line number Diff line number Diff line change 37
37
38
38
# get all the layer names
39
39
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 ()]
41
45
# feed forward (inference) and get the network output
42
46
# measure how much it took in seconds
43
47
start = time .perf_counter ()
You can’t perform that action at this time.
0 commit comments