Unverified Commit b10eaedd authored by Hakjin Lee's avatar Hakjin Lee Committed by GitHub
Browse files

[Fix] batched nms for nms_rotated (#1688)

* Fix batched_nms to support nms_rotated

* Update test code for batched_nms with nms_rotated

* Edit indexing the score in nms

* Use -1 indexing for batched_nms
parent 62c1b7f6
......@@ -325,12 +325,13 @@ def batched_nms(boxes, scores, idxs, nms_cfg, class_agnostic=False):
if boxes_for_nms.shape[0] < split_thr or torch.onnx.is_in_onnx_export():
dets, keep = nms_op(boxes_for_nms, scores, **nms_cfg_)
boxes = boxes[keep]
# -1 indexing works abnormal in TensorRT
# This assumes `dets` has 5 dimensions where
# This assumes `dets` has arbitrary dimensions where
# the last dimension is score.
# TODO: more elegant way to handle the dimension issue.
# Some type of nms would reweight the score, such as SoftNMS
scores = dets[:, 4]
# Currently it supports bounding boxes [x1, y1, x2, y2, score] or
# rotated boxes [cx, cy, w, h, angle_radian, score].
scores = dets[:, -1]
else:
max_num = nms_cfg_.pop('max_num', -1)
total_mask = scores.new_zeros(scores.size(), dtype=torch.bool)
......
......@@ -68,3 +68,17 @@ class TestNmsRotated:
dets[..., -2] *= -1
assert np.allclose(dets.cpu().numpy()[:, :5], np_expect_dets)
assert np.allclose(keep_inds.cpu().numpy(), np_expect_keep_inds)
# test batched_nms with nms_rotated
from mmcv.ops import batched_nms
nms_cfg = dict(type='nms_rotated', iou_threshold=0.5)
boxes, keep = batched_nms(
torch.from_numpy(np_boxes[:, :5]),
torch.from_numpy(np_boxes[:, -1]),
torch.from_numpy(np.array([0, 0, 0, 0])),
nms_cfg,
class_agnostic=False)
assert np.allclose(boxes.cpu().numpy()[:, :5], np_expect_dets)
assert np.allclose(keep.cpu().numpy(), np_expect_keep_inds)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment