From ed6a0db6b6082225c2a8bd4970b257fd2b41d754 Mon Sep 17 00:00:00 2001 From: Yonghye Kwon Date: Thu, 15 Dec 2022 11:28:37 +0900 Subject: [PATCH 1/3] limit detections without explicit if condition Signed-off-by: Yonghye Kwon --- utils/general.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/utils/general.py b/utils/general.py index e5a843c4a758..a7cbb01d0528 100644 --- a/utils/general.py +++ b/utils/general.py @@ -979,8 +979,7 @@ def non_max_suppression( c = x[:, 5:6] * (0 if agnostic else max_wh) # classes boxes, scores = x[:, :4] + c, x[:, 4] # boxes (offset by class), scores i = torchvision.ops.nms(boxes, scores, iou_thres) # NMS - if i.shape[0] > max_det: # limit detections - i = i[:max_det] + i = i[:min(i.shape[0], max_det)] # limit detections if merge and (1 < n < 3E3): # Merge NMS (boxes merged using weighted mean) # update boxes as boxes(i,4) = weights(i,n) * boxes(n,4) iou = box_iou(boxes[i], boxes) > iou_thres # iou matrix From 79c05d54c806b548629e80484b48dfaa6a22d645 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 15 Dec 2022 02:30:50 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- utils/general.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/general.py b/utils/general.py index a7cbb01d0528..cf636d9daf0e 100644 --- a/utils/general.py +++ b/utils/general.py @@ -979,7 +979,7 @@ def non_max_suppression( c = x[:, 5:6] * (0 if agnostic else max_wh) # classes boxes, scores = x[:, :4] + c, x[:, 4] # boxes (offset by class), scores i = torchvision.ops.nms(boxes, scores, iou_thres) # NMS - i = i[:min(i.shape[0], max_det)] # limit detections + i = i[:min(i.shape[0], max_det)] # limit detections if merge and (1 < n < 3E3): # Merge NMS (boxes merged using weighted mean) # update boxes as boxes(i,4) = weights(i,n) * boxes(n,4) iou = box_iou(boxes[i], boxes) > iou_thres # iou matrix From 677fe4d100a2a20f146fbeb21611ad4b8bf1e4ad Mon Sep 17 00:00:00 2001 From: Yonghye Kwon Date: Sat, 17 Dec 2022 23:39:34 +0900 Subject: [PATCH 3/3] cleanup indexing code for limit detections --- utils/general.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/general.py b/utils/general.py index 05944406cd97..70b6f6446f23 100644 --- a/utils/general.py +++ b/utils/general.py @@ -978,7 +978,7 @@ def non_max_suppression( c = x[:, 5:6] * (0 if agnostic else max_wh) # classes boxes, scores = x[:, :4] + c, x[:, 4] # boxes (offset by class), scores i = torchvision.ops.nms(boxes, scores, iou_thres) # NMS - i = i[:min(i.shape[0], max_det)] # limit detections + i = i[:max_det] # limit detections if merge and (1 < n < 3E3): # Merge NMS (boxes merged using weighted mean) # update boxes as boxes(i,4) = weights(i,n) * boxes(n,4) iou = box_iou(boxes[i], boxes) > iou_thres # iou matrix