Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] NMS update #4990

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
f198c57
Add score_threshold and max_num for NMS in bbox_nms
SemyonBevzuk Apr 15, 2021
8f997c7
Fix bboxes
SemyonBevzuk Apr 15, 2021
bcf95ae
Merge branch 'master' into nms_update
SemyonBevzuk Apr 16, 2021
95f45b7
Fix problem with score_thr after score_factor
SemyonBevzuk Apr 17, 2021
a3d7284
Move score_threshold=0
SemyonBevzuk Apr 19, 2021
bfe6f2b
Add torch.onnx.is_in_onnx_export () for nms_cfg
SemyonBevzuk Apr 21, 2021
4c9fa6a
Fix codestyle
SemyonBevzuk Apr 21, 2021
64bf5b3
Merge remote-tracking branch 'upstream/master' into nms_update
SemyonBevzuk Apr 22, 2021
28f078e
Move nms_cfg in multiclass_nms
SemyonBevzuk Apr 23, 2021
8d9a44d
Removed tools from setup.cfg
SemyonBevzuk Apr 23, 2021
76de85b
Changed max_num to match NMSop.symbolic update
SemyonBevzuk Apr 26, 2021
396fe94
Add max_per_img to cfg.nms
SemyonBevzuk Apr 30, 2021
9382e5a
Merge branch 'master' into nms_update
RunningLeon May 6, 2021
99089b1
Updated calls to batched_nms
SemyonBevzuk May 7, 2021
686bdcd
Merge branch 'nms_update' of https://github.com/SemyonBevzuk/mmdetect…
SemyonBevzuk May 7, 2021
1bdd343
Updates from master
SemyonBevzuk Jun 2, 2021
275ad55
Rename 'det_bboxes' to ' det_result' in fovea_head:get_bboxes()
SemyonBevzuk Jun 3, 2021
5f5feed
Fixed 'max_shape' type in atss_head:_get_bboxes(). Because 'max_shape…
SemyonBevzuk Jun 3, 2021
0a1b93a
Merge branch 'master' into nms_update
SemyonBevzuk Jun 9, 2021
48831ec
Upstream merge
SemyonBevzuk Jun 15, 2021
2d2223c
Remove max_num for soft_nms in cornernet
SemyonBevzuk Jun 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions mmdet/core/post_processing/bbox_nms.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ def multiclass_nms(multi_bboxes,
tuple: (dets, labels, indices (optional)), tensors of shape (k, 5),
(k), and (k). Dets are boxes with scores. Labels are 0-based.
"""
num_classes = multi_scores.size(1) - 1
num_classes = int(multi_scores.size(1) - 1)
RunningLeon marked this conversation as resolved.
Show resolved Hide resolved
# exclude background category
if multi_bboxes.shape[1] > 4:
bboxes = multi_bboxes.view(multi_scores.size(0), -1, 4)
else:
bboxes = multi_bboxes[:, None].expand(
multi_scores.size(0), num_classes, 4)

scores = multi_scores[:, :-1]
scores = multi_scores[:, :num_classes]

labels = torch.arange(num_classes, dtype=torch.long)
labels = labels.view(1, -1).expand_as(scores)
Expand Down Expand Up @@ -82,11 +82,11 @@ def multiclass_nms(multi_bboxes,
else:
return dets, labels

dets, keep = batched_nms(bboxes, scores, labels, nms_cfg)
if nms_cfg.type == 'nms':
nms_cfg.score_threshold = score_thr if score_factors is None else 0
nms_cfg.max_num = max_num

if max_num > 0:
dets = dets[:max_num]
keep = keep[:max_num]
dets, keep = batched_nms(bboxes, scores, labels, nms_cfg)

if return_inds:
return dets, labels[keep], keep
Expand Down
2 changes: 1 addition & 1 deletion mmdet/models/dense_heads/atss_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ def _get_bboxes(self,
anchors = anchors.expand_as(bbox_pred)

bboxes = self.bbox_coder.decode(
anchors, bbox_pred, max_shape=img_shapes)
anchors, bbox_pred, max_shape=torch.tensor(img_shapes[0][:2]))
mlvl_bboxes.append(bboxes)
mlvl_scores.append(scores)
mlvl_centerness.append(centerness)
Expand Down
4 changes: 3 additions & 1 deletion mmdet/models/dense_heads/cascade_rpn_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,8 @@ def _get_bboxes_single(self,
'Please delete max_num which will be deprecated.'
else:
cfg.max_per_img = cfg.max_num
if 'max_per_img' in cfg:
cfg.nms.max_num = cfg.max_per_img
if 'nms_thr' in cfg:
assert cfg.nms.iou_threshold == cfg.nms_thr, f'You set' \
f' iou_threshold in nms and ' \
Expand All @@ -668,7 +670,7 @@ def _get_bboxes_single(self,
f'which will be deprecated.'

dets, keep = batched_nms(proposals, scores, ids, cfg.nms)
return dets[:cfg.max_per_img]
return dets


@HEADS.register_module()
Expand Down
4 changes: 2 additions & 2 deletions mmdet/models/dense_heads/fovea_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,11 @@ def get_bboxes(self,
]
img_shape = img_metas[img_id]['img_shape']
scale_factor = img_metas[img_id]['scale_factor']
det_bboxes = self._get_bboxes_single(cls_score_list,
det_result = self._get_bboxes_single(cls_score_list,
bbox_pred_list, featmap_sizes,
points, img_shape,
scale_factor, cfg, rescale)
result_list.append(det_bboxes)
result_list.append(det_result)
return result_list

def _get_bboxes_single(self,
Expand Down
4 changes: 3 additions & 1 deletion mmdet/models/dense_heads/rpn_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,14 @@ def _get_bboxes_single(self,
proposals = proposals[valid_mask]
scores = scores[valid_mask]
ids = ids[valid_mask]
if 'max_per_img' in cfg:
cfg.nms.max_num = cfg.max_per_img
if proposals.numel() > 0:
dets, keep = batched_nms(proposals, scores, ids, cfg.nms)
else:
return proposals.new_zeros(0, 5)

return dets[:cfg.max_per_img]
return dets

def onnx_export(self, x, img_metas):
"""Test without augmentation.
Expand Down
4 changes: 1 addition & 3 deletions mmdet/models/roi_heads/trident_roi_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,10 @@ def merge_trident_bboxes(self, trident_det_bboxes, trident_det_labels):
nms_scores = trident_det_bboxes[:, 4].contiguous()
nms_inds = trident_det_labels
nms_cfg = self.test_cfg['nms']
nms_cfg['max_num'] = self.test_cfg['max_per_img']
det_bboxes, keep = batched_nms(nms_bboxes, nms_scores, nms_inds,
nms_cfg)
det_labels = trident_det_labels[keep]
if self.test_cfg['max_per_img'] > 0:
det_labels = det_labels[:self.test_cfg['max_per_img']]
det_bboxes = det_bboxes[:self.test_cfg['max_per_img']]

return det_bboxes, det_labels

Expand Down