NonMaxSuppression#
NonMaxSuppression - 11#
Version
domain: main
since_version: 11
function: False
support_level: SupportType.COMMON
shape inference: True
This version of the operator has been available since version 11.
Summary
Filter out boxes that have high intersection-over-union (IOU) overlap with previously selected boxes. Bounding boxes with score less than score_threshold are removed. Bounding box format is indicated by attribute center_point_box. Note that this algorithm is agnostic to where the origin is in the coordinate system and more generally is invariant to orthogonal transformations and translations of the coordinate system; thus translating or reflections of the coordinate system result in the same boxes being selected by the algorithm. The selected_indices output is a set of integers indexing into the input collection of bounding boxes representing the selected boxes. The bounding box coordinates corresponding to the selected indices can then be obtained using the Gather or GatherND operation.
Attributes
center_point_box: Integer indicate the format of the box data. The default is 0. 0 - the box data is supplied as [y1, x1, y2, x2] where (y1, x1) and (y2, x2) are the coordinates of any diagonal pair of box corners and the coordinates can be provided as normalized (i.e., lying in the interval [0, 1]) or absolute. Mostly used for TF models. 1 - the box data is supplied as [x_center, y_center, width, height]. Mostly used for Pytorch models. Default value is
0
.
Inputs
Between 2 and 5 inputs.
boxes (heterogeneous) - tensor(float): An input tensor with shape [num_batches, spatial_dimension, 4]. The single box data format is indicated by center_point_box.
scores (heterogeneous) - tensor(float): An input tensor with shape [num_batches, num_classes, spatial_dimension]
max_output_boxes_per_class (optional, heterogeneous) - tensor(int64): Integer representing the maximum number of boxes to be selected per batch per class. It is a scalar. Default to 0, which means no output.
iou_threshold (optional, heterogeneous) - tensor(float): Float representing the threshold for deciding whether boxes overlap too much with respect to IOU. It is scalar. Value range [0, 1]. Default to 0.
score_threshold (optional, heterogeneous) - tensor(float): Float representing the threshold for deciding when to remove boxes based on score. It is a scalar.
Outputs
selected_indices (heterogeneous) - tensor(int64): selected indices from the boxes tensor. [num_selected_indices, 3], the selected index format is [batch_index, class_index, box_index].
Examples
nonmaxsuppression_suppress_by_IOU
node = onnx.helper.make_node(
'NonMaxSuppression',
inputs=['boxes', 'scores', 'max_output_boxes_per_class', 'iou_threshold', 'score_threshold'],
outputs=['selected_indices']
)
boxes = np.array([[
[0.0, 0.0, 1.0, 1.0],
[0.0, 0.1, 1.0, 1.1],
[0.0, -0.1, 1.0, 0.9],
[0.0, 10.0, 1.0, 11.0],
[0.0, 10.1, 1.0, 11.1],
[0.0, 100.0, 1.0, 101.0]
]]).astype(np.float32)
scores = np.array([[[0.9, 0.75, 0.6, 0.95, 0.5, 0.3]]]).astype(np.float32)
max_output_boxes_per_class = np.array([3]).astype(np.int64)
iou_threshold = np.array([0.5]).astype(np.float32)
score_threshold = np.array([0.0]).astype(np.float32)
selected_indices = np.array([[0, 0, 3], [0, 0, 0], [0, 0, 5]]).astype(np.int64)
expect(node, inputs=[boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold], outputs=[selected_indices], name='test_nonmaxsuppression_suppress_by_IOU')
nonmaxsuppression_suppress_by_IOU_and_scores
node = onnx.helper.make_node(
'NonMaxSuppression',
inputs=['boxes', 'scores', 'max_output_boxes_per_class', 'iou_threshold', 'score_threshold'],
outputs=['selected_indices']
)
boxes = np.array([[
[0.0, 0.0, 1.0, 1.0],
[0.0, 0.1, 1.0, 1.1],
[0.0, -0.1, 1.0, 0.9],
[0.0, 10.0, 1.0, 11.0],
[0.0, 10.1, 1.0, 11.1],
[0.0, 100.0, 1.0, 101.0]
]]).astype(np.float32)
scores = np.array([[[0.9, 0.75, 0.6, 0.95, 0.5, 0.3]]]).astype(np.float32)
max_output_boxes_per_class = np.array([3]).astype(np.int64)
iou_threshold = np.array([0.5]).astype(np.float32)
score_threshold = np.array([0.4]).astype(np.float32)
selected_indices = np.array([[0, 0, 3], [0, 0, 0]]).astype(np.int64)
expect(node, inputs=[boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold], outputs=[selected_indices], name='test_nonmaxsuppression_suppress_by_IOU_and_scores')
nonmaxsuppression_flipped_coordinates
node = onnx.helper.make_node(
'NonMaxSuppression',
inputs=['boxes', 'scores', 'max_output_boxes_per_class', 'iou_threshold', 'score_threshold'],
outputs=['selected_indices']
)
boxes = np.array([[
[1.0, 1.0, 0.0, 0.0],
[0.0, 0.1, 1.0, 1.1],
[0.0, 0.9, 1.0, -0.1],
[0.0, 10.0, 1.0, 11.0],
[1.0, 10.1, 0.0, 11.1],
[1.0, 101.0, 0.0, 100.0]
]]).astype(np.float32)
scores = np.array([[[0.9, 0.75, 0.6, 0.95, 0.5, 0.3]]]).astype(np.float32)
max_output_boxes_per_class = np.array([3]).astype(np.int64)
iou_threshold = np.array([0.5]).astype(np.float32)
score_threshold = np.array([0.0]).astype(np.float32)
selected_indices = np.array([[0, 0, 3], [0, 0, 0], [0, 0, 5]]).astype(np.int64)
expect(node, inputs=[boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold], outputs=[selected_indices], name='test_nonmaxsuppression_flipped_coordinates')
nonmaxsuppression_limit_output_size
node = onnx.helper.make_node(
'NonMaxSuppression',
inputs=['boxes', 'scores', 'max_output_boxes_per_class', 'iou_threshold', 'score_threshold'],
outputs=['selected_indices']
)
boxes = np.array([[
[0.0, 0.0, 1.0, 1.0],
[0.0, 0.1, 1.0, 1.1],
[0.0, -0.1, 1.0, 0.9],
[0.0, 10.0, 1.0, 11.0],
[0.0, 10.1, 1.0, 11.1],
[0.0, 100.0, 1.0, 101.0]
]]).astype(np.float32)
scores = np.array([[[0.9, 0.75, 0.6, 0.95, 0.5, 0.3]]]).astype(np.float32)
max_output_boxes_per_class = np.array([2]).astype(np.int64)
iou_threshold = np.array([0.5]).astype(np.float32)
score_threshold = np.array([0.0]).astype(np.float32)
selected_indices = np.array([[0, 0, 3], [0, 0, 0]]).astype(np.int64)
expect(node, inputs=[boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold], outputs=[selected_indices], name='test_nonmaxsuppression_limit_output_size')
nonmaxsuppression_single_box
node = onnx.helper.make_node(
'NonMaxSuppression',
inputs=['boxes', 'scores', 'max_output_boxes_per_class', 'iou_threshold', 'score_threshold'],
outputs=['selected_indices']
)
boxes = np.array([[
[0.0, 0.0, 1.0, 1.0]
]]).astype(np.float32)
scores = np.array([[[0.9]]]).astype(np.float32)
max_output_boxes_per_class = np.array([3]).astype(np.int64)
iou_threshold = np.array([0.5]).astype(np.float32)
score_threshold = np.array([0.0]).astype(np.float32)
selected_indices = np.array([[0, 0, 0]]).astype(np.int64)
expect(node, inputs=[boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold], outputs=[selected_indices], name='test_nonmaxsuppression_single_box')
nonmaxsuppression_identical_boxes
node = onnx.helper.make_node(
'NonMaxSuppression',
inputs=['boxes', 'scores', 'max_output_boxes_per_class', 'iou_threshold', 'score_threshold'],
outputs=['selected_indices']
)
boxes = np.array([[
[0.0, 0.0, 1.0, 1.0],
[0.0, 0.0, 1.0, 1.0],
[0.0, 0.0, 1.0, 1.0],
[0.0, 0.0, 1.0, 1.0],
[0.0, 0.0, 1.0, 1.0],
[0.0, 0.0, 1.0, 1.0],
[0.0, 0.0, 1.0, 1.0],
[0.0, 0.0, 1.0, 1.0],
[0.0, 0.0, 1.0, 1.0],
[0.0, 0.0, 1.0, 1.0]
]]).astype(np.float32)
scores = np.array([[[0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9]]]).astype(np.float32)
max_output_boxes_per_class = np.array([3]).astype(np.int64)
iou_threshold = np.array([0.5]).astype(np.float32)
score_threshold = np.array([0.0]).astype(np.float32)
selected_indices = np.array([[0, 0, 0]]).astype(np.int64)
expect(node, inputs=[boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold], outputs=[selected_indices], name='test_nonmaxsuppression_identical_boxes')
nonmaxsuppression_center_point_box_format
node = onnx.helper.make_node(
'NonMaxSuppression',
inputs=['boxes', 'scores', 'max_output_boxes_per_class', 'iou_threshold', 'score_threshold'],
outputs=['selected_indices'],
center_point_box=1
)
boxes = np.array([[
[0.5, 0.5, 1.0, 1.0],
[0.5, 0.6, 1.0, 1.0],
[0.5, 0.4, 1.0, 1.0],
[0.5, 10.5, 1.0, 1.0],
[0.5, 10.6, 1.0, 1.0],
[0.5, 100.5, 1.0, 1.0]
]]).astype(np.float32)
scores = np.array([[[0.9, 0.75, 0.6, 0.95, 0.5, 0.3]]]).astype(np.float32)
max_output_boxes_per_class = np.array([3]).astype(np.int64)
iou_threshold = np.array([0.5]).astype(np.float32)
score_threshold = np.array([0.0]).astype(np.float32)
selected_indices = np.array([[0, 0, 3], [0, 0, 0], [0, 0, 5]]).astype(np.int64)
expect(node, inputs=[boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold], outputs=[selected_indices], name='test_nonmaxsuppression_center_point_box_format')
nonmaxsuppression_two_classes
node = onnx.helper.make_node(
'NonMaxSuppression',
inputs=['boxes', 'scores', 'max_output_boxes_per_class', 'iou_threshold', 'score_threshold'],
outputs=['selected_indices']
)
boxes = np.array([[
[0.0, 0.0, 1.0, 1.0],
[0.0, 0.1, 1.0, 1.1],
[0.0, -0.1, 1.0, 0.9],
[0.0, 10.0, 1.0, 11.0],
[0.0, 10.1, 1.0, 11.1],
[0.0, 100.0, 1.0, 101.0]
]]).astype(np.float32)
scores = np.array([[[0.9, 0.75, 0.6, 0.95, 0.5, 0.3],
[0.9, 0.75, 0.6, 0.95, 0.5, 0.3]]]).astype(np.float32)
max_output_boxes_per_class = np.array([2]).astype(np.int64)
iou_threshold = np.array([0.5]).astype(np.float32)
score_threshold = np.array([0.0]).astype(np.float32)
selected_indices = np.array([[0, 0, 3], [0, 0, 0], [0, 1, 3], [0, 1, 0]]).astype(np.int64)
expect(node, inputs=[boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold], outputs=[selected_indices], name='test_nonmaxsuppression_two_classes')
nonmaxsuppression_two_batches
node = onnx.helper.make_node(
'NonMaxSuppression',
inputs=['boxes', 'scores', 'max_output_boxes_per_class', 'iou_threshold', 'score_threshold'],
outputs=['selected_indices']
)
boxes = np.array([[[0.0, 0.0, 1.0, 1.0],
[0.0, 0.1, 1.0, 1.1],
[0.0, -0.1, 1.0, 0.9],
[0.0, 10.0, 1.0, 11.0],
[0.0, 10.1, 1.0, 11.1],
[0.0, 100.0, 1.0, 101.0]],
[[0.0, 0.0, 1.0, 1.0],
[0.0, 0.1, 1.0, 1.1],
[0.0, -0.1, 1.0, 0.9],
[0.0, 10.0, 1.0, 11.0],
[0.0, 10.1, 1.0, 11.1],
[0.0, 100.0, 1.0, 101.0]]]).astype(np.float32)
scores = np.array([[[0.9, 0.75, 0.6, 0.95, 0.5, 0.3]],
[[0.9, 0.75, 0.6, 0.95, 0.5, 0.3]]]).astype(np.float32)
max_output_boxes_per_class = np.array([2]).astype(np.int64)
iou_threshold = np.array([0.5]).astype(np.float32)
score_threshold = np.array([0.0]).astype(np.float32)
selected_indices = np.array([[0, 0, 3], [0, 0, 0], [1, 0, 3], [1, 0, 0]]).astype(np.int64)
expect(node, inputs=[boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold], outputs=[selected_indices], name='test_nonmaxsuppression_two_batches')
Differences
0 | 0 | Filter out boxes that have high intersection-over-union (IOU) overlap with previously selected boxes. | Filter out boxes that have high intersection-over-union (IOU) overlap with previously selected boxes. |
1 | 1 | Bounding boxes with score less than score_threshold are removed. Bounding box format is indicated by attribute center_point_box. | Bounding boxes with score less than score_threshold are removed. Bounding box format is indicated by attribute center_point_box. |
2 | 2 | Note that this algorithm is agnostic to where the origin is in the coordinate system and more generally is invariant to | Note that this algorithm is agnostic to where the origin is in the coordinate system and more generally is invariant to |
3 | 3 | orthogonal transformations and translations of the coordinate system; thus translating or reflections of the coordinate system | orthogonal transformations and translations of the coordinate system; thus translating or reflections of the coordinate system |
4 | 4 | result in the same boxes being selected by the algorithm. | result in the same boxes being selected by the algorithm. |
5 | 5 | The selected_indices output is a set of integers indexing into the input collection of bounding boxes representing the selected boxes. | The selected_indices output is a set of integers indexing into the input collection of bounding boxes representing the selected boxes. |
6 | 6 | The bounding box coordinates corresponding to the selected indices can then be obtained using the Gather or GatherND operation. | The bounding box coordinates corresponding to the selected indices can then be obtained using the Gather or GatherND operation. |
7 | 7 |
|
|
8 | 8 | **Attributes** | **Attributes** |
9 | 9 |
|
|
10 | 10 | * **center_point_box**: | * **center_point_box**: |
11 | 11 | Integer indicate the format of the box data. The default is 0. 0 - | Integer indicate the format of the box data. The default is 0. 0 - |
12 | 12 | the box data is supplied as [y1, x1, y2, x2] where (y1, x1) and (y2, | the box data is supplied as [y1, x1, y2, x2] where (y1, x1) and (y2, |
13 | 13 | x2) are the coordinates of any diagonal pair of box corners and the | x2) are the coordinates of any diagonal pair of box corners and the |
14 | 14 | coordinates can be provided as normalized (i.e., lying in the | coordinates can be provided as normalized (i.e., lying in the |
15 | 15 | interval [0, 1]) or absolute. Mostly used for TF models. 1 - the box | interval [0, 1]) or absolute. Mostly used for TF models. 1 - the box |
16 | 16 | data is supplied as [x_center, y_center, width, height]. Mostly used | data is supplied as [x_center, y_center, width, height]. Mostly used |
17 | 17 | for Pytorch models. Default value is 0. | for Pytorch models. Default value is 0. |
18 | 18 |
|
|
19 | 19 | **Inputs** | **Inputs** |
20 | 20 |
|
|
21 | 21 | Between 2 and 5 inputs. | Between 2 and 5 inputs. |
22 | 22 |
|
|
23 | 23 | * **boxes** (heterogeneous) - **tensor(float)**: | * **boxes** (heterogeneous) - **tensor(float)**: |
24 | 24 | An input tensor with shape [num_batches, spatial_dimension, 4]. The | An input tensor with shape [num_batches, spatial_dimension, 4]. The |
25 | 25 | single box data format is indicated by center_point_box. | single box data format is indicated by center_point_box. |
26 | 26 | * **scores** (heterogeneous) - **tensor(float)**: | * **scores** (heterogeneous) - **tensor(float)**: |
27 | 27 | An input tensor with shape [num_batches, num_classes, | An input tensor with shape [num_batches, num_classes, |
28 | 28 | spatial_dimension] | spatial_dimension] |
29 | 29 | * **max_output_boxes_per_class** (optional, heterogeneous) - **tensor(int64)**: | * **max_output_boxes_per_class** (optional, heterogeneous) - **tensor(int64)**: |
30 | 30 | Integer representing the maximum number of boxes to be selected per | Integer representing the maximum number of boxes to be selected per |
31 | 31 | batch per class. It is a scalar. Default to 0, which means no | batch per class. It is a scalar. Default to 0, which means no |
32 | 32 | output. | output. |
33 | 33 | * **iou_threshold** (optional, heterogeneous) - **tensor(float)**: | * **iou_threshold** (optional, heterogeneous) - **tensor(float)**: |
34 | 34 | Float representing the threshold for deciding whether boxes overlap | Float representing the threshold for deciding whether boxes overlap |
35 | 35 | too much with respect to IOU. It is scalar. Value range [0, 1]. | too much with respect to IOU. It is scalar. Value range [0, 1]. |
36 | 36 | Default to 0. | Default to 0. |
37 | 37 | * **score_threshold** (optional, heterogeneous) - **tensor(float)**: | * **score_threshold** (optional, heterogeneous) - **tensor(float)**: |
38 | 38 | Float representing the threshold for deciding when to remove boxes | Float representing the threshold for deciding when to remove boxes |
39 | 39 | based on score. It is a scalar. | based on score. It is a scalar. |
40 | 40 |
|
|
41 | 41 | **Outputs** | **Outputs** |
42 | 42 |
|
|
43 | 43 | * **selected_indices** (heterogeneous) - **tensor(int64)**: | * **selected_indices** (heterogeneous) - **tensor(int64)**: |
44 | 44 | selected indices from the boxes tensor. [num_selected_indices, 3], | selected indices from the boxes tensor. [num_selected_indices, 3], |
45 | 45 | the selected index format is [batch_index, class_index, box_index]. | the selected index format is [batch_index, class_index, box_index]. |
NonMaxSuppression - 10#
Version
domain: main
since_version: 10
function: False
support_level: SupportType.COMMON
shape inference: True
This version of the operator has been available since version 10.
Summary
Filter out boxes that have high intersection-over-union (IOU) overlap with previously selected boxes. Bounding boxes with score less than score_threshold are removed. Bounding box format is indicated by attribute center_point_box. Note that this algorithm is agnostic to where the origin is in the coordinate system and more generally is invariant to orthogonal transformations and translations of the coordinate system; thus translating or reflections of the coordinate system result in the same boxes being selected by the algorithm. The selected_indices output is a set of integers indexing into the input collection of bounding boxes representing the selected boxes. The bounding box coordinates corresponding to the selected indices can then be obtained using the Gather or GatherND operation.
Attributes
center_point_box: Integer indicate the format of the box data. The default is 0. 0 - the box data is supplied as [y1, x1, y2, x2] where (y1, x1) and (y2, x2) are the coordinates of any diagonal pair of box corners and the coordinates can be provided as normalized (i.e., lying in the interval [0, 1]) or absolute. Mostly used for TF models. 1 - the box data is supplied as [x_center, y_center, width, height]. Mostly used for Pytorch models. Default value is
0
.
Inputs
Between 2 and 5 inputs.
boxes (heterogeneous) - tensor(float): An input tensor with shape [num_batches, spatial_dimension, 4]. The single box data format is indicated by center_point_box.
scores (heterogeneous) - tensor(float): An input tensor with shape [num_batches, num_classes, spatial_dimension]
max_output_boxes_per_class (optional, heterogeneous) - tensor(int64): Integer representing the maximum number of boxes to be selected per batch per class. It is a scalar. Default to 0, which means no output.
iou_threshold (optional, heterogeneous) - tensor(float): Float representing the threshold for deciding whether boxes overlap too much with respect to IOU. It is scalar. Value range [0, 1]. Default to 0.
score_threshold (optional, heterogeneous) - tensor(float): Float representing the threshold for deciding when to remove boxes based on score. It is a scalar.
Outputs
selected_indices (heterogeneous) - tensor(int64): selected indices from the boxes tensor. [num_selected_indices, 3], the selected index format is [batch_index, class_index, box_index].