Skip to content

fix(metrics): prevent coordinate overflow in mAP - #2743

Merged
Borda merged 3 commits into
roboflow:developfrom
Nikhi00718:fix/map-coordinate-overflow
Oct 16, 2026
Merged

Borda merged 3 commits into
roboflow:developfrom
Nikhi00718:fix/map-coordinate-overflow

Conversation

@Nikhi00718

@Nikhi00718 Nikhi00718 commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Description

MeanAveragePrecision can 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:

import numpy as np
from supervision import Detections
from supervision.metrics import MeanAveragePrecision

xyxy = np.array([[0, 0, 512, 512]], dtype=np.float16)
target = Detections(xyxy=xyxy, class_id=np.array([0]))
prediction = Detections(
    xyxy=xyxy.copy(), class_id=np.array([0]), confidence=np.array([0.9])
)
result = MeanAveragePrecision().update(prediction, target).compute()
print(result.map50_95, result.large_objects.map50_95)

Before: -1 -1. With this fix: 1.0 1.0. The area 512 * 512 overflows 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.5 into 1.0. Coordinate storage dtype should not determine whether a valid box participates in evaluation.

Changes Made

  • Compute target and prediction box extents and areas using Python scalars, preserving caller arrays and their dtypes.
  • Add 11 public-result regression/control cases covering float16, uint16, int16, int32, float32, float64, and int64, including false-positive filtering by area.
  • Add an Unreleased changelog entry.

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 20d1c5741d9547df77f89091162dfd0277b78aab adds 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.md under Unreleased

Additional Notes

Public signatures are unchanged. Evaluation still uses the existing COCO area ranges. No optional model downloads are needed to reproduce this issue.

@Nikhi00718
Nikhi00718 requested a review from SkalskiP as a code owner October 16, 2026 14:41
@codecov

codecov Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94%. Comparing base (138ef8e) to head (d61466b).
⚠️ Report is 1 commits behind head on develop.

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:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Borda Borda added the bug Something isn't working label Oct 16, 2026
@Borda
Borda requested a balanced review from Copilot October 16, 2026 17:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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.

@Borda
Borda merged commit ffd0ac0 into roboflow:develop Oct 16, 2026
36 checks passed
jorge-asenjo added a commit to jorge-asenjo/supervision that referenced this pull request Oct 17, 2026
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]>
Borda added a commit to Lingikaushikreddy/supervision that referenced this pull request Oct 17, 2026
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]>
Borda added a commit that referenced this pull request Oct 20, 2026
* fix(metrics): prevent coordinate overflow in mAP
* docs(changelog): link mAP overflow fix

---------

Co-authored-by: Jirka Borovec <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants