Test that NMS correctly filters boxes based on score threshold. Note: This test uses a low score threshold (0.05) to ensure both TVM and ONNX Runtime output the same fixed shape [3,3], allowing use of the standard check_correctness function.
()
| 5476 | |
| 5477 | |
| 5478 | def test_nms_score_threshold(): |
| 5479 | """Test that NMS correctly filters boxes based on score threshold. |
| 5480 | |
| 5481 | Note: This test uses a low score threshold (0.05) to ensure both TVM and ONNX Runtime |
| 5482 | output the same fixed shape [3,3], allowing use of the standard check_correctness function. |
| 5483 | """ |
| 5484 | nms_node = helper.make_node( |
| 5485 | "NonMaxSuppression", |
| 5486 | ["boxes", "scores", "max_output_boxes_per_class", "iou_threshold", "score_threshold"], |
| 5487 | ["selected_indices"], |
| 5488 | center_point_box=0, |
| 5489 | ) |
| 5490 | |
| 5491 | # Create data with varying scores - ensure we get exactly 3 boxes after NMS |
| 5492 | boxes_data = np.array( |
| 5493 | [ |
| 5494 | [[0.0, 0.0, 1.0, 1.0], [2.0, 0.0, 3.0, 1.0], [0.0, 2.0, 1.0, 3.0]] # Box 0 # Box 1 |
| 5495 | ], # Box 2 |
| 5496 | dtype=np.float32, |
| 5497 | ) |
| 5498 | |
| 5499 | # Scores: 0.9, 0.3, 0.1 - adjust score threshold to get exactly 3 boxes |
| 5500 | scores_data = np.array([[[0.9, 0.3, 0.1]]], dtype=np.float32) |
| 5501 | |
| 5502 | boxes_shape = [1, 3, 4] |
| 5503 | scores_shape = [1, 1, 3] |
| 5504 | |
| 5505 | graph = helper.make_graph( |
| 5506 | [nms_node], |
| 5507 | "nms_test_score_threshold", |
| 5508 | inputs=[ |
| 5509 | helper.make_tensor_value_info("boxes", TensorProto.FLOAT, boxes_shape), |
| 5510 | helper.make_tensor_value_info("scores", TensorProto.FLOAT, scores_shape), |
| 5511 | ], |
| 5512 | initializer=[ |
| 5513 | helper.make_tensor("max_output_boxes_per_class", TensorProto.INT64, [1], [3]), |
| 5514 | helper.make_tensor("iou_threshold", TensorProto.FLOAT, [1], [0.1]), |
| 5515 | helper.make_tensor("score_threshold", TensorProto.FLOAT, [1], [0.05]), |
| 5516 | ], |
| 5517 | outputs=[helper.make_tensor_value_info("selected_indices", TensorProto.INT64, [3, 3])], |
| 5518 | ) |
| 5519 | |
| 5520 | model = helper.make_model(graph, producer_name="nms_test_score_threshold") |
| 5521 | model.ir_version = 8 |
| 5522 | model.opset_import[0].version = 11 |
| 5523 | |
| 5524 | inputs = { |
| 5525 | "boxes": boxes_data, |
| 5526 | "scores": scores_data, |
| 5527 | } |
| 5528 | |
| 5529 | # Run ONNX Runtime |
| 5530 | ort_session = onnxruntime.InferenceSession( |
| 5531 | model.SerializeToString(), providers=["CPUExecutionProvider"] |
| 5532 | ) |
| 5533 | ort_output = ort_session.run([], inputs) |
| 5534 | |
| 5535 | # Run TVM |
nothing calls this directly
no test coverage detected
searching dependent graphs…