mindspore.ops.NMSWithMask
- class mindspore.ops.NMSWithMask(iou_threshold=0.5)[source]
When object detection problem is performed in the computer vision field, object detection algorithm generates a plurality of bounding boxes. Use the box with the highest score, calculate the overlap between other boxes and the current box, and delete the box based on a certain threshold(IOU). On Ascend platform, the input box score is ignored, which only selects boexs based on the IOU between boxes, which means if you want to remove boxes that has lower scores, you need to sort the input boxes by score in descending order in advance. The IOU is as follows,
\[\text{IOU} = \frac{\text{Area of Overlap}}{\text{Area of Union}}\]Warning
Only supports up to 2864 input boxes at one time.
- Parameters
iou_threshold (float) – Specifies the threshold of overlap boxes with respect to IOU. Default: 0.5.
- Inputs:
bboxes (Tensor) - The shape of tensor is \((N, 5)\). Input bounding boxes. N is the number of input bounding boxes. Every bounding box contains 5 values, the first 4 values are the coordinates(x0, y0, x1, y1) of bounding box which represents the point of top-left and bottom-right, and the last value is the score of this bounding box. The data type must be float16 or float32.
- Outputs:
tuple[Tensor], tuple of three tensors, they are output_boxes, output_idx and selected_mask.
output_boxes (Tensor) - The shape of tensor is \((N, 5)\). On GPU and CPU platform, it is a sorted list of bounding boxes by sorting the input bboxes in descending order of score. On Ascend platform, it is same as input bboxes.
output_idx (Tensor) - The shape of tensor is \((N,)\). The indexes list of output_boxes.
selected_mask (Tensor) - The shape of tensor is \((N,)\). A mask list of valid output bounding boxes. Apply this mask on output_boxes to get the list of bounding boxes after non-max suppression calculation, or apply this mask on output_idx to get the indexes list of bounding boxes after non-max suppression calculation.
- Raises
ValueError – If the iou_threshold is not a float number.
ValueError – if the first dimension of input Tensor is less than or equal to 0.
TypeError – if the dtype of the bboxes is not float16 or float32.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> bbox = np.array([[100.0, 100.0, 50.0, 68.0, 0.63], [150.0, 75.0, 165.0, 115.0, 0.55], ... [12.0, 190.0, 288.0, 200.0, 0.9], [28.0, 130.0, 106.0, 172.0, 0.3]]) >>> bbox[:, 2] += bbox[:, 0] >>> bbox[:, 3] += bbox[:, 1] >>> inputs = Tensor(bbox, mindspore.float32) >>> nms = ops.NMSWithMask(0.1) >>> output_boxes, indices, mask = nms(inputs) >>> indices_np = indices.asnumpy() >>> print(indices_np[mask.asnumpy()]) [0 1 2]