Skip to content

fix(topi): suppress NMS boxes only on IoU greater than the threshold - #20845

Open
173787247 wants to merge 1 commit into
apache:mainfrom
173787247:fix/onnx-nms-strict-iou
Open

173787247 wants to merge 1 commit into
apache:mainfrom
173787247:fix/onnx-nms-strict-iou

Conversation

@173787247

Copy link
Copy Markdown

Fixes #20840

Problem

The all-class NMS loop invalidated a box when IoU >= iou_threshold. ONNX NonMaxSuppression suppresses only boxes whose IoU is strictly greater than the threshold, so a box at exactly the threshold was dropped.

The reported example: boxes with IoU exactly 0.5, threshold 0.5

  • ONNX Runtime: [[0, 0, 0], [0, 0, 1]]
  • TVM (before): [[0, 0, 0]]

Change

  • _nms_loop now uses iou > iou_threshold for the all-class NMS path (the classic NMS loop and the Python reference implementation keep their historical >= behavior).
  • Added test_nms_iou_equal_threshold, checked against ONNX Runtime for the equality boundary and the neighbouring 0.49 case.

Validation

pytest tests/python/relax/test_frontend_onnx.py -k nms passes (4 tests), and the reported input now selects both boxes at threshold 0.5.

@173787247

Copy link
Copy Markdown
Author

The only cpu/pr-head failure is tests/python/relax/test_vm_multi_device.py::test_multi_cpu: a 2.38e-07 absolute difference against rtol/atol 1e-07, i.e. the known numerical-tolerance flake, unrelated to the NMS change. docker/arm/gpu/wasm and the rest of the cpu suite pass. Could the cpu job be rerun?

The all-class NMS loop used "IoU >= threshold" when invalidating boxes,
so a box whose IoU equals the threshold was dropped.  ONNX
NonMaxSuppression keeps boxes at equality (only a strictly greater
overlap suppresses), which made imported NMS results miss boundary boxes.

Use a strict greater-than comparison and add an ONNX Runtime checked
regression test for the equality case.
@173787247
173787247 force-pushed the fix/onnx-nms-strict-iou branch from a6a86a8 to d783c2e Compare October 29, 2026 01:48

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug][Relax][ONNX] NonMaxSuppression suppresses boxes at the exact IoU threshold

1 participant