[Bug]: with_nmm(threshold=0.0) merges detections that do not overlap at all, while with_nms(threshold=0.0) keeps them
Search before asking
- [x] I have searched the issues and discussions and found no similar bug report.
Bug
What's the bug?
Detections.with_nmm(threshold=0.0) (and box_non_max_merge, mask_non_max_merge, oriented_box_non_max_merge) merge detections of the same class that do not overlap at all. _validate_iou_threshold accepts 0, but the grouping compares ious >= iou_threshold, so every pair with an IoU of exactly 0 (disjoint or only touching) is grouped.
Expected behavior:
At threshold 0, only pairs that actually overlap (IoU > 0) should merge, which is what with_nms(threshold=0.0) does (it compares with a strict >). Three disjoint boxes should stay three boxes.
Actual behavior:
with_nms(threshold=0.0) -> 3 detections (3 expected)
with_nmm(threshold=0.0) -> 1 detections, xyxy = [[0.0, 0.0, 210.0, 210.0]]
box_non_max_merge groups -> [[0, 1, 2]] (expected [[0], [1], [2]] in some order)
mask_non_max_merge groups -> [[0, 1, 2]]
oriented_box_non_max_merge groups -> [[0, 1, 2]]
match_detections(disjoint, iou_threshold=0.0) has the same >= and returns [[0, 0]]; I am leaving that one out of the proposed fix because its docstring says it mirrors the matcher used by the metrics modules.
Environment
- Supervision: 0.32.0.dev (
developat 5210466) - Python: 3.12.14
- OS: macOS (Apple Silicon)
Minimal Reproducible Example
import numpy as np
import supervision as sv
xyxy = np.array([[0, 0, 10, 10], [100, 100, 110, 110], [200, 200, 210, 210]], dtype=float)
det = sv.Detections(
xyxy=xyxy,
confidence=np.array([0.9, 0.8, 0.7]),
class_id=np.array([0, 0, 0]),
)
print(len(det.with_nms(threshold=0.0))) # 3
print(len(det.with_nmm(threshold=0.0))) # 1 (box [0, 0, 210, 210]), expected 3
Are you willing to submit a PR?
- [x] Yes I'd like to help by submitting a PR!