Skip to content

fix(metrics): match COCO target ties in mAR - #2758

Merged
Borda merged 5 commits into
roboflow:developfrom
px12811:fix/mar-confidence-matching
Oct 20, 2026
Merged

Borda merged 5 commits into
roboflow:developfrom
px12811:fix/mar-confidence-matching

Conversation

@px12811

@px12811 px12811 commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Description

After #2750 added confidence-ordered mAR matching, equal-IoU targets still chose the first eligible target instead of COCO's last-target tie rule. A higher-confidence prediction could therefore consume the only target available to a later prediction and undercount recall.

This PR now builds on the merged #2750. It reverses the eligible target indices before selecting the maximum IoU, preserving confidence order, per-class detection limits, and crowd/ignore handling. The shared matcher and other metrics are unchanged.

For targets [0, 0, 10, 10] and [10, 0, 20, 10], with predictions [0, 0, 20, 10] and [0, 0, 10, 10] at scores 0.9 and 0.8, current develop returns AR [0.05, 0.50, 0.50]; this fix and pycocotools return [0.05, 0.55, 0.55].

Motivation and Context

Refs #2701 and follows up on #2750. Conflicts with #2750 have been resolved while retaining its crowd/ignore support and tests.

Changes Made

  • Match COCO's equal-IoU target tie rule in the existing confidence-ordered matcher.
  • Retain box/mask/OBB confidence-order regression coverage and add equal-IoU cases with ordinary, crowd, and ignored targets.
  • Correct the expected AR in fix(metrics): leave crowd and ignored targets out of MeanAverageRecall #2750's overlapping-target test: official COCO gives [0.1, 0.6, 0.6] because its first prediction has equal IoU with both targets.
  • Update the matcher docstring and changelog.

Testing

CPU validation with Python 3.13.16 and the NumPy fallback backend:

  • New equal-IoU regressions on develop 4922f3a4: 9 failed; all pass with the fix.

  • mAR tests: 46 passed. All metrics tests: 691 passed.

  • Full suite: 5751 passed, 123 skipped, 94% coverage. Baseline: 5733 passed, 123 skipped; every previously passing test still passes.

  • pre-commit run --all-files: passed, including mypy.

  • Official pycocotools 2.0.11: 8/8 tie comparisons agree for boxes/masks, with and without crowd targets. The unmodified baseline disagrees on all eight.

  • Supplemental seeded comparison: 100 box scenes + 100 mask scenes, all 606 valid area results agree within 1e-7; this randomized comparison excludes crowd/ignore targets.

  • Added/updated tests

  • Updated docstrings

  • Added an Unreleased changelog entry

Additional Notes

No new dependency or public API. Implementation and tests were developed with Codex assistance.

@px12811
px12811 requested a review from SkalskiP as a code owner October 17, 2026 17:39
@codecov

codecov Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94%. Comparing base (a8b1ef4) to head (2ab2d54).

Additional details and impacted files
@@           Coverage Diff           @@
##           develop   #2758   +/-   ##
=======================================
  Coverage       94%     94%           
=======================================
  Files           83      83           
  Lines        13644   13644           
=======================================
  Hits         12839   12839           
  Misses         805     805           
🚀 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 19, 2026
@Borda
Borda requested a balanced review from Copilot October 19, 2026 11:55

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 localized matching change has focused regression coverage and no unresolved blocking findings.

No open issues 🎉

What changed in this PR

🟢 Approve — This localized fix aligns mAR matching with COCO’s confidence ordering while preserving per-class detection limits and other metrics’ behavior. No actionable issues remain.

Changes:

  • Match predictions by descending confidence, independently at each IoU threshold, with COCO-compatible target tie-breaking.
  • Add 14 regression cases covering geometries, ordering, class isolation, thresholds, and empty inputs.
  • Update the mAR docstring and changelog.

Static coverage included behavior, compatibility, tests, and documentation; tests were not rerun here. Code: 5/5 (focused implementation); testing: 5/5 (targeted regressions); documentation: 5/5 (accurate scope). Overall risk: 1/5.

File Description
tests/​metrics/​test_mean_average_recall.py Adds confidence-order and matching-edge-case regressions.
src/​supervision/​metrics/​mean_average_recall.py Introduces the mAR-specific matcher and documents its behavior.
docs/​changelog.md Records the matching correction and unchanged scope.

Review effort: Balanced

@px12811 px12811 changed the title fix(metrics): match mAR detections in confidence order fix(metrics): match COCO target ties in mAR Oct 19, 2026
Borda and others added 2 commits October 19, 2026 20:16
Changes:
- Merge develop at a8b1ef4 into fix/mar-confidence-matching, bringing the OBB threshold precision, overflow-safe NMM area, and grayscale annotator/image updates with their regression tests.
- Resolve docs changelog collision by retaining the PR roboflow#2758 target-tie entry and all fetched develop Unreleased entries.

Impact:
- Preserves COCO equal-IoU target tie behavior while integrating four commits made on develop after the PR base.
- Keeps merged behavior and its existing tests aligned on the attached PR branch.

Verification:
- Affected modules: 589 passed, 3 skipped, 4 warnings.
- git diff --cached --check: passed; merge analysis found one changelog collision and no other unmerged paths after resolution.

Residual limits:
- The PR one-line test-docstring finding remains for the separate remediation change.

---

Co-authored-by: Codex <codex@openai.com>
Changes:
- Shorten the equal-IoU COCO tie test docstring while preserving its ignored-region scenario.

Impact:
- Keeps the test purpose readable and compliant with the project one-line test docstring rule; runtime behavior is unchanged.

Verification:
- Focused metric test module: 46 passed.
- All-file pre-commit hooks: passed.

Residual limits:
- Canonical full repository gate pending.

---

Co-authored-by: Codex <codex@openai.com>
Comment on lines +55 to +57
# pycocotools 2.0.11 gives these AR@1/10/100 scores for both boxes and masks.
np.testing.assert_allclose(result.recall_scores, expected)
np.testing.assert_allclose(result.large_objects.recall_scores, expected)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we rather install this package as a test dependency and run live results

@Borda
Borda merged commit c944ecb into roboflow:develop Oct 20, 2026
36 checks passed
Borda added a commit that referenced this pull request Oct 20, 2026
* fix(metrics): match mAR detections in confidence order
* test(metrics): clarify COCO equal-IoU tie test

---------

Co-authored-by: jirka <6035284+borda@users.noreply.github.com>
Co-authored-by: Codex <codex@openai.com>
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