mmcv.ops.batched_nms¶
- mmcv.ops.batched_nms(boxes: torch.Tensor, scores: torch.Tensor, idxs: torch.Tensor, nms_cfg: Optional[Dict], class_agnostic: bool = False) → Tuple[torch.Tensor, torch.Tensor][source]¶
Performs non-maximum suppression in a batched fashion.
Modified from torchvision/ops/boxes.py#L39. In order to perform NMS independently per class, we add an offset to all the boxes. The offset is dependent only on the class idx, and is large enough so that boxes from different classes do not overlap.
Note
In v1.4.1 and later,
batched_nms
supports skipping the NMS and returns sorted raw results when nms_cfg is None.- Parameters
boxes (torch.Tensor) – boxes in shape (N, 4) or (N, 5).
scores (torch.Tensor) – scores in shape (N, ).
idxs (torch.Tensor) – each index value correspond to a bbox cluster, and NMS will not be applied between elements of different idxs, shape (N, ).
nms_cfg (dict | optional) –
Supports skipping the nms when nms_cfg is None, otherwise it should specify nms type and other parameters like iou_thr. Possible keys includes the following.
iou_threshold (float): IoU threshold used for NMS.
split_thr (float): threshold number of boxes. In some cases the number of boxes is large (e.g., 200k). To avoid OOM during training, the users could set split_thr to a small value. If the number of boxes is greater than the threshold, it will perform NMS on each group of boxes separately and sequentially. Defaults to 10000.
class_agnostic (bool) – if true, nms is class agnostic, i.e. IoU thresholding happens over all boxes, regardless of the predicted class. Defaults to False.
- Returns
kept dets and indice.
boxes (Tensor): Bboxes with score after nms, has shape (num_bboxes, 5). last dimension 5 arrange as (x1, y1, x2, y2, score)
keep (Tensor): The indices of remaining boxes in input boxes.
- Return type