Repository navigation
fix(metrics): prevent coordinate overflow in mAP - #2743
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #2743 +/- ##
=======================================
Coverage 94% 94%
=======================================
Files 83 83
Lines 13612 13612
=======================================
Hits 12796 12796
Misses 816 816 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🟢 Approval recommended
The narrow fix covers both preparation paths with targeted regression tests and no identified blocking defects.
0 open findings
What changed in this PR
Prevents coordinate overflow in Supervision’s mAP evaluation without changing public interfaces or caller arrays.
Changes:
- Uses Python scalars for target and prediction box arithmetic.
- Adds 11 regression/control cases covering scores, size buckets, and coordinate preservation.
- Documents the fix in the changelog.
No actionable issues found. Coverage includes behavior, compatibility, tests, and documentation; tests were not rerun.
Quality: code 5/5, tests 5/5, documentation 5/5—focused implementation and coverage. Overall risk: 1/5.
| File | Description |
|---|---|
| tests/metrics/test_mean_average_precision_area.py | Adds dtype and false-positive regression coverage. |
| src/supervision/metrics/mean_average_precision.py | Converts coordinates to Python scalars before arithmetic. |
| docs/changelog.md | Records the overflow fix and its evaluation impact. |
🧠 Review effort: Balanced
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Merge develop at ffd0ac0, which released 0.31.0 and merged roboflow#2741, roboflow#2740 and roboflow#2743. Only docs/changelog.md conflicted: the CompactMask.area entry now opens the new Unreleased section and the rest matches develop. roboflow#2741 now filters MaskAnnotator ROI crops with CompactMask.area > 0, so that path uses the vectorized area; its tests pass unchanged. Verification: full suite 5,735 passed, 123 skipped, 94% coverage (NumPy fallback); compact mask, mask utility and annotator tests 601 passed with both the fallback and OpenCV 5.0.0; pre-commit passed on the PR files. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Changes: - Merge the fetched develop target into the Pascal VOC rounding branch, including the Unreleased notes for PRs roboflow#2740, roboflow#2741, and roboflow#2743. - Integrate OpenCV-compatible ellipse rasterization and its regression coverage. - Integrate mask ROI handling that excludes all-False masks and its tests. - Integrate overflow-safe mean-average-precision box extents and dtype regression tests. Impact: - Keeps the PR branch current so the roboflow#2748 changelog note can be added beside the target's Unreleased entries. - Brings the target's drawing, mask annotation, and metric fixes into the local PR branch. Verification: - The three-tree merge completed automatically without conflicts. - The staged merge diff check passed; all eight staged paths were reviewed. Residual limits: - None known. --- Co-authored-by: Codex <[email protected]>
* fix(metrics): prevent coordinate overflow in mAP * docs(changelog): link mAP overflow fix --------- Co-authored-by: Jirka Borovec <[email protected]>
Description
MeanAveragePrecisioncan ignore valid float16 detections or misclassify integer boxes by size because box extents and areas are calculated in the coordinate array's dtype. Convert box rows to Python scalars before arithmetic for both targets and predictions.Minimal reproduction on
develop:Before:
-1 -1. With this fix:1.0 1.0. The area512 * 512overflows float16 to infinity, so the evaluator ignores the ground truth. With uint16 the same area wraps to zero and puts the large object in the small bucket. Extent subtraction can also overflow for int16 and float16 boxes spanning negative and positive coordinates.Motivation and Context
Overflow can also inflate scores: a high-confidence unmatched float16 512×512 box is ignored, turning an expected mAP of
0.5into1.0. Coordinate storage dtype should not determine whether a valid box participates in evaluation.Changes Made
Testing
Base
6ecb27963, new regression cases: 7 failed, 4 passed for the expected score/size-bucket differences.uv run pytest tests/metrics -q --tb=short: 669 passed.uv run pytest src/ tests/ --cov=supervision -q --tb=short: 5,704 passed, 105 skipped, 1 timed out. The nested no-OpenCV subprocess exceeded its 180-second limit while other checks were running. Its isolated rerun passed in 52.70 seconds (uv run pytest tests/cv2/test_integration.py::test_ordinary_suite_passes_when_cv2_is_blocked -q --tb=short).uv run pre-commit run --all-files: all hooks passed (including mypy, Ruff, formatting, and codespell).Untouched base full suite: 5,694 passed, 105 skipped.
Final head
20d1c5741d9547df77f89091162dfd0277b78aabadds only the PR link to the changelog after the source validation.uv run pytest tests/metrics/test_mean_average_precision_area.py tests/cv2/test_release.py -q --tb=short: 18 passed; changelog pre-commit hooks passed.Added/updated tests; full-suite results and the passing isolated timeout rerun are recorded above
Updated docs (docstrings / mkdocs entry) for new or changed public API — not applicable; no public API change
Added a changelog entry in
docs/changelog.mdunderUnreleasedAdditional Notes
Public signatures are unchanged. Evaluation still uses the existing COCO area ranges. No optional model downloads are needed to reproduce this issue.