Skip to content

fix(metrics): leave crowd and ignored targets out of MeanAverageRecall - #2750

Merged
Borda merged 3 commits into
roboflow:developfrom
Lingikaushikreddy:fix/mar-ignore-crowd-targets
Oct 19, 2026
Merged

Borda merged 3 commits into
roboflow:developfrom
Lingikaushikreddy:fix/mar-ignore-crowd-targets

Conversation

@Lingikaushikreddy

Copy link
Copy Markdown
Contributor

Description

MeanAverageRecall now leaves COCO ignore regions out of recall. These are targets with data["iscrowd"] or data["ignore"] set, the same rule MeanAveragePrecision applies. They were counted as misses, so mAR on COCO data with crowd annotations came out lower than pycocotools AR. With one normal target, one crowd target and a perfect prediction, mAR_at_100 was 0.5; pycocotools gives 1.0, and so does this PR.

Motivation and Context

Closes #2749

DetectionDataset.from_coco keeps iscrowd by default, and #2689 / #2701 set pycocotools AR as the reference for this metric.

Changes Made

  • MeanAverageRecall._compute drops ignore-region targets before the size filter, through a new _drop_ignored_targets.
    • This matches COCO for recall. COCO tries non-ignored targets first and only lets a prediction match an ignore region when no regular target is left for it, and a prediction on an ignore region adds nothing to recall.
    • A class whose only targets are crowd regions drops out of the mean, as COCO reports -1 for it.
  • Class docstring: one paragraph on crowd and ignore targets.
  • Tests: crowd and ignore targets are not misses; a class with only crowd targets is left out of the mean.
  • docs/changelog.md entry.
  • Out of scope: Precision, Recall and F1Score also ignore iscrowd. They aren't COCO metrics, so I left them alone. Happy to follow up if you want the same rule there.

Testing

  • New tests on develop: all 3 fail with recall [0.5, 0.5, 0.5] instead of [1, 1, 1].

  • With this change: uv run pytest tests/metrics, 661 passed. Full suite: uv run pytest, 5697 passed, 105 skipped (develop: 5694 passed, 105 skipped).

  • Against pycocotools 2.0.11 on a seeded harness (0–3 crowd targets per image, 100 trials, boxes):

  • uv run pre-commit run --all-files passes.

  • Added/updated tests, and the full suite passes locally

  • Updated docs (docstrings / mkdocs entry) for new or changed public API

  • Added a changelog entry in docs/changelog.md under Unreleased

Lingikaushikreddy added a commit to Lingikaushikreddy/supervision that referenced this pull request Oct 16, 2026
@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 (1fb42a4) to head (d9d8bec).

Additional details and impacted files
@@           Coverage Diff           @@
##           develop   #2750   +/-   ##
=======================================
  Coverage       94%     94%           
=======================================
  Files           83      83           
  Lines        13612   13633   +21     
=======================================
+ Hits         12807   12828   +21     
  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 16, 2026
@Borda
Borda requested a balanced review from Copilot October 16, 2026 20: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 focused correction preserves prediction limits, includes regression coverage, and has no unresolved findings.

0 open findings

What changed in this PR

Updates MeanAverageRecall to exclude crowd and ignored targets, aligning this aspect of recall with COCO evaluation while preserving prediction limits.

Changes:

  • Removes ignored targets before size filtering and recall calculation.
  • Adds regression tests for ignored targets and crowd-only classes.
  • Documents the behavior in the class docstring and changelog.
File Description
tests/​metrics/​test_mean_average_recall.py Adds crowd and ignore regression tests.
src/​supervision/​metrics/​mean_average_recall.py Filters ignored targets and documents the behavior.
docs/​changelog.md Records the recall correction.

🧠 Review effort: Balanced


💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@px12811

px12811 commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Thanks for pointing out the remaining matching-order difference. I reproduced it in a small example without crowd or ignored targets and opened #2758 to address it.
The fix is limited to confidence-ordered matching in mAR; the crowd/ignore handling remains separate in this PR. Sharing here to avoid duplicating work, and thanks for the analysis that helped identify the issue!

Changes:
- Match each top-ranked prediction to its best eligible unmatched same-class target for each IoU threshold and detection limit.
- Use a fully qualified Sphinx role for the COCO dataset loader and add a regression test and changelog entry for confidence-order behavior.

Impact:
- MeanAverageRecall now follows confidence-first matching, so a lower-confidence prediction cannot claim a target before a higher-confidence prediction.
- The dataset loader reference renders as a navigable API link.

Verification:
- Ruff lint, full pre-commit, and mypy passed.
- Full coverage suite passed: 5,733 passed, 123 skipped, 94% total coverage.
- Offline MkDocs render passed and the generated mAR page contains the fully qualified method target.

Residual limits:
- pycocotools runtime parity was unavailable; the strict full-site build could not reach GitHub through the git-committers plugin. The docs render passed with that metadata plugin disabled.

---

Co-authored-by: Codex <[email protected]>
@Borda Borda changed the title fix(metrics): leave crowd and ignored targets out of MeanAverageRecall fix(metrics): leave crowd and ignored targets out of MeanAverageRecall Oct 19, 2026
@Borda
Borda merged commit 4922f3a into roboflow:develop Oct 19, 2026
36 checks passed
Borda added a commit to MohammadHijjawi97/supervision that referenced this pull request Oct 19, 2026
Changes:
- Merge target roboflow#2750 and roboflow#2752 metrics behavior and regression coverage into the PR branch.
- Retain the PR roboflow#2755 grayscale annotator changelog entry alongside target metrics release notes.

Impact:
- Keeps the PR branch current with develop while preserving both PR and target behavior.
- Retains release notes for grayscale annotator and metrics changes in one Unreleased section.

Verification:
- `git merge-tree` identified one changelog conflict; the resolution keeps all three independent entries.
- Reviewed the five-path merge index; no unmerged paths remain and `git diff --cached --check` passes.

Residual limits:
- The conflict was documentation-only; merged target code remains subject to this remediation run's quality gates.

---

Co-authored-by: Codex <[email protected]>
Borda added a commit that referenced this pull request Oct 20, 2026
…ll` (#2750)

* fix(metrics): leave crowd and ignored targets out of MeanAverageRecall
* docs(changelog): note MeanAverageRecall crowd handling (#2750)
* fix(metrics): match recall predictions by confidence

---------

Co-authored-by: Lingikaushikreddy <[email protected]>
Co-authored-by: jirka <[email protected]>
Co-authored-by: Codex <[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.

[Bug]: MeanAverageRecall counts crowd targets as misses, so mAR is lower than pycocotools on COCO data

4 participants