From 300e9a7ad68b021e723fe27fc3d2d6bfddc0545a Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 31 Mar 2020 21:31:09 -0700 Subject: [PATCH] merge NMS full matrix --- utils/utils.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/utils/utils.py b/utils/utils.py index 109c78bd..d434ccf4 100755 --- a/utils/utils.py +++ b/utils/utils.py @@ -555,11 +555,12 @@ def non_max_suppression(prediction, conf_thres=0.1, iou_thres=0.6, multi_label=T boxes, scores = x[:, :4].clone() + c.view(-1, 1) * max_wh, x[:, 4] # boxes (offset by class), scores if method == 'merge': # Merge NMS (boxes merged using weighted mean) i = torchvision.ops.boxes.nms(boxes, scores, iou_thres) - # weights = (box_iou(boxes, boxes).tril_() > iou_thres) * scores.view(-1, 1) # box weights - # weights /= weights.sum(0) # normalize - # x[:, :4] = torch.mm(weights.T, x[:, :4]) - weights = (box_iou(boxes[i], boxes) > iou_thres) * scores[None] # box weights - x[i, :4] = torch.mm(weights / weights.sum(1, keepdim=True), x[:, :4]) # boxes(i,4) = w(i,n) * boxes(n,4) + if n < 1E4: # update boxes + # weights = (box_iou(boxes, boxes).tril_() > iou_thres) * scores.view(-1, 1) # box weights + # weights /= weights.sum(0) # normalize + # x[:, :4] = torch.mm(weights.T, x[:, :4]) + weights = (box_iou(boxes[i], boxes) > iou_thres) * scores[None] # box weights + x[i, :4] = torch.mm(weights / weights.sum(1, keepdim=True), x[:, :4]) # boxes(i,4) = w(i,n) * boxes(n,4) elif method == 'vision': i = torchvision.ops.boxes.nms(boxes, scores, iou_thres) elif method == 'fast': # FastNMS from https://github.com/dbolya/yolact