megengine.functional.nn.nms¶
- nms(boxes, scores, iou_thresh, max_output=None)[source]¶
Performs non-maximum suppression (NMS) on the boxes according to their intersection-over-union(IoU).
- Parameters
boxes (
Tensor
) – tensor of shape(N, 4)
; the boxes to perform nms on; each box is expected to be in(x1, y1, x2, y2)
format.iou_thresh (
float
) – IoU threshold for overlapping.scores (
Tensor
) – tensor of shape(N,)
, the score of boxes.max_output (
Optional
[int
]) – the maximum number of boxes to keep; it is optional if this operator is not traced otherwise it required to be specified; if it is not specified, all boxes are kept.
- Return type
- Returns
indices of the elements that have been kept by NMS, sorted by scores.
Note
max_output should be specified and should have valid positive value under tracing.
Examples
>>> import numpy as np >>> x = np.zeros((100,4)) >>> np.random.seed(42) >>> x[:,:2] = np.random.rand(100,2)*20 >>> x[:,2:] = np.random.rand(100,2)*20 + 100 >>> scores = Tensor(np.random.rand(100)) >>> inp = Tensor(x) >>> F.vision.nms(inp, scores, iou_thresh=0.7) Tensor([75 69], dtype=int32, device=xpux:0)