Skip to content

Commit

Permalink
fix issue on yolov3 tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
x4nth055 committed Apr 26, 2022
1 parent 3105f40 commit af7dff5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
6 changes: 5 additions & 1 deletion machine-learning/object-detection/live_yolo_opencv.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
net = cv2.dnn.readNetFromDarknet(config_path, weights_path)

ln = net.getLayerNames()
ln = [ln[i[0] - 1] for i in net.getUnconnectedOutLayers()]
try:
ln = [ln[i[0] - 1] for i in net.getUnconnectedOutLayers()]
except IndexError:
# in case getUnconnectedOutLayers() returns 1D array when CUDA isn't available
ln = [ln[i - 1] for i in net.getUnconnectedOutLayers()]

cap = cv2.VideoCapture(0)

Expand Down
6 changes: 5 additions & 1 deletion machine-learning/object-detection/read_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
net = cv2.dnn.readNetFromDarknet(config_path, weights_path)

ln = net.getLayerNames()
ln = [ln[i[0] - 1] for i in net.getUnconnectedOutLayers()]
try:
ln = [ln[i[0] - 1] for i in net.getUnconnectedOutLayers()]
except IndexError:
# in case getUnconnectedOutLayers() returns 1D array when CUDA isn't available
ln = [ln[i - 1] for i in net.getUnconnectedOutLayers()]
# read the file from the command line
video_file = sys.argv[1]
cap = cv2.VideoCapture(video_file)
Expand Down
6 changes: 5 additions & 1 deletion machine-learning/object-detection/yolo_opencv.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@

# get all the layer names
ln = net.getLayerNames()
ln = [ln[i[0] - 1] for i in net.getUnconnectedOutLayers()]
try:
ln = [ln[i[0] - 1] for i in net.getUnconnectedOutLayers()]
except IndexError:
# in case getUnconnectedOutLayers() returns 1D array when CUDA isn't available
ln = [ln[i - 1] for i in net.getUnconnectedOutLayers()]
# feed forward (inference) and get the network output
# measure how much it took in seconds
start = time.perf_counter()
Expand Down

0 comments on commit af7dff5

Please sign in to comment.