Document feedback

Question document fragment

When a question document fragment contains a formula, it is displayed as a space.

Submission type
issue

It's a little complicated...

I'd like to ask someone.

Please select the submission type

Problem type
Specifications and Common Mistakes

- Specifications and Common Mistakes:

- Misspellings or punctuation mistakes,incorrect formulas, abnormal display.

- Incorrect links, empty cells, or wrong formats.

- Chinese characters in English context.

- Minor inconsistencies between the UI and descriptions.

- Low writing fluency that does not affect understanding.

- Incorrect version numbers, including software package names and version numbers on the UI.

Usability

- Usability:

- Incorrect or missing key steps.

- Missing main function descriptions, keyword explanation, necessary prerequisites, or precautions.

- Ambiguous descriptions, unclear reference, or contradictory context.

- Unclear logic, such as missing classifications, items, and steps.

Correctness

- Correctness:

- Technical principles, function descriptions, supported platforms, parameter types, or exceptions inconsistent with that of software implementation.

- Incorrect schematic or architecture diagrams.

- Incorrect commands or command parameters.

- Incorrect code.

- Commands inconsistent with the functions.

- Wrong screenshots.

- Sample code running error, or running results inconsistent with the expectation.

Risk Warnings

- Risk Warnings:

- Lack of risk warnings for operations that may damage the system or important data.

Content Compliance

- Content Compliance:

- Contents that may violate applicable laws and regulations or geo-cultural context-sensitive words and expressions.

- Copyright infringement.

Please select the type of question

Problem description

Describe the bug so that we can quickly locate the problem.

mindspore.ops.NMSWithMask

class mindspore.ops.NMSWithMask(iou_threshold=0.5)[source]

Non-maximum Suppression. 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:

IOU=Area of OverlapArea 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

>>> import mindspore
>>> import numpy as np
>>> from mindspore import Tensor, ops
>>> 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]