Repository navigation
fix(metrics): use the COCO crowd IoU for oriented-box mAP - #2941
Merged
Merged
Conversation
Oriented-box mAP used the standard IoU for crowd targets. Boxes and masks divide the intersection by the prediction area, so a prediction inside a crowd region is ignored there but was a false positive for oriented boxes. Axis-aligned oriented boxes now score like their boxes. The intersection loop of oriented_box_iou_batch moves into _oriented_box_pair_intersections without changes, so the crowd path can use the exact intersection. oriented_box_iou_batch output is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the oriented-box crowd-handling update.
No open issues 🎉
What changed in this PR
This PR aligns oriented-box mean average precision with COCO crowd handling in Supervision. Predictions inside crowd targets are ignored rather than counted as false positives, matching box and mask behavior.
Changes:
- Use intersection over prediction area for oriented-box crowd targets while preserving standard IoU for other targets.
- Extract shared oriented-box intersection logic for reuse by the metric.
- Add crowd-overlap, rotated-box, and
pycocotoolsparity tests, plus a changelog entry.
| File | Description |
|---|---|
tests/metrics/test_mean_average_precision.py |
Adds three regression tests for oriented-box crowd handling. |
src/supervision/metrics/mean_average_precision.py |
Applies COCO crowd IoU to oriented-box evaluation. |
src/supervision/detection/utils/iou_and_nms.py |
Extracts pairwise intersection computation for reuse. |
docs/changelog.md |
Documents the crowd-handling correction and links the PR. |
Review effort: Balanced
Changes: - Integrate target updates for mAP area buckets, OpenCV fallback arithmetic, CSV column validation, and their tests. - Preserve both target and oriented-box crowd changelog entries. Impact: - Retains the PR’s crowd matching while incorporating current target behavior and tests. Verification: - mAP test module: 127 passed using the NumPy fallback. - Merge index: no unresolved paths; git diff --cached --check passed. Residual limits: - OpenCV-specific tests were not run during merge integration. --- Co-authored-by: Codex <[email protected]>
Changes: - Divide oriented crowd intersections by positive detection areas without epsilon and guard zero-area detections. - Add exact-threshold, tiny-area, and collinear zero-area regressions; clarify the changelog’s parity example. Impact: - Crowd detections at matching thresholds and very small scales no longer become false positives because of denominator perturbation. Verification: - Configured pre-commit hooks and targeted format and type checks passed. - Full test suite: 6,669 passed, 281 skipped; 94% coverage. - Independent closure challenge completed; 446 targeted metric tests passed. Residual limits: - OpenCV-dependent tests were skipped in the clean test environment. --- Co-authored-by: Codex <[email protected]>
Borda
approved these changes
Nov 11, 2026
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #2941 +/- ##
=======================================
- Coverage 95% 95% -0%
=======================================
Files 83 83
Lines 14443 14461 +18
=======================================
+ Hits 13688 13705 +17
- Misses 755 756 +1 🚀 New features to boost your workflow:
|
Borda
added a commit
that referenced
this pull request
Nov 11, 2026
Oriented-box mAP used the standard IoU for crowd targets. Boxes and masks divide the intersection by the prediction area, so a prediction inside a crowd region is ignored there but was a false positive for oriented boxes. Axis-aligned oriented boxes now score like their boxes. The intersection loop of oriented_box_iou_batch moves into _oriented_box_pair_intersections without changes, so the crowd path can use the exact intersection. oriented_box_iou_batch output is unchanged. * docs(changelog): note oriented-box mAP crowd fix * fix(metrics): preserve oriented crowd overlap thresholds --------- Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Jirka Borovec <[email protected]> Co-authored-by: Codex <[email protected]>
2 of 3 tasks
avanish-garg
added a commit
to avanish-garg/supervision
that referenced
this pull request
Nov 13, 2026
A zero-dimensional float32 array skipped the NumPy-scalar branch and was widened through float(), so np.array(0.7, dtype=np.float32) on 90 items still gave 62 train items instead of 63. Unwrap it to its scalar first and cover it with a regression case. Also link the changelog entry to this PR and drop the roboflow#2941 entry that the merge of develop re-added under Unreleased although it is already released in 0.31.7.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
sv.metrics.MeanAveragePrecisionwithMetricTarget.ORIENTED_BOUNDING_BOXESuses the standard IoU for crowd targets (data["iscrowd"]). A code comment says crowd regions are not supported for oriented boxes. Boxes and masks use the COCO crowd IoU: the intersection over the prediction area. So a prediction inside a crowd region is ignored for boxes and masks, but it is a false positive for oriented boxes. The same data then gets a lower mAP as oriented boxes than as boxes.Repro: axis-aligned oriented boxes, so the boxes and
pycocotoolsgive the expected value.pycocotoolsgives 0.6 and 1.0 for these boxes.Motivation and Context
Crowd targets come from COCO-style data:
sv.DetectionDataset.from_cocostoresdata["iscrowd"]. The same rule must hold for all metric targets, or oriented-box scores cannot be compared with box scores.MeanAverageRecall,Precision,RecallandF1Scorealready give the same scores for axis-aligned oriented boxes and for boxes when crowd targets are present.I found this with a random-scene check: axis-aligned oriented boxes must score exactly like their boxes. There is no issue for it.
Changes Made
_oriented_box_iou_with_jaccard(new, private, inmean_average_precision.py): the oriented-box counterpart of_mask_iou_with_jaccard. For crowd targets it divides the exact intersection by the prediction area plusnp.spacing(1), asbox_iou_batch_with_jaccarddoes. It clips to[0, 1], asoriented_box_iou_batchdoes, because intersections use float32-rounded polygons. Other targets keep theoriented_box_iou_batchIoU._oriented_box_pair_intersections(new, private, iniou_and_nms.py): the per-pair intersection loop oforiented_box_iou_batch, moved out without changes. It returns the candidate pairs and their intersection areas, not a dense matrix, so NMS memory does not grow.oriented_box_iou_batchnow calculates its IoU or IoS from these pairs.pycocotoolsparity test for axis-aligned oriented boxes with a crowd target (all 6 AP values), and a rotated crowd target with a prediction inside it.Unreleased.Testing
New tests on
develop:3 failed. With this change:3 passed.oriented_box_iou_batchoutput is bit-identical todevelop(np.array_equal) on 1,600 matrices: IoU and IoS, self and cross comparison, float32, float64 and int64 corners, origins up to 1e6, 0 to 11 boxes per side.Speed, 3,000 rotated boxes, best of 7 runs, 2 alternating rounds: self comparison 0.67 to 0.72 s, cross comparison 1.10 to 1.13 s.
develop: 0.66 to 0.67 s and 1.11 to 1.21 s. No change beyond noise.pytest(full suite and doctests, NumPy 2.5.4, NumPy backend without OpenCV):6652 passed, 279 skipped.pre-commit runon the changed files: all hooks pass, mypy included.Random scenes, not added to the suite: 300 box scenes with 15% crowd targets, tied scores and sides near 32 and 96. For each scene,
MeanAveragePrecision,MeanAverageRecall,Precision,RecallandF1Scoreran on the boxes and on the same boxes as oriented boxes. Ondevelop, mAP differs in 60 of 300 scenes, and 0 differ without crowd targets. With this change, 0 of 300 scenes differ for all 5 metrics.Added/updated tests, and the full suite passes locally
Updated docs (docstrings / mkdocs entry) for new or changed public API (no API change)
Added a changelog entry in
docs/changelog.mdunderUnreleasedAdditional Notes
mean_average_precision.pyin different functions.🤖 Generated with Claude Code