Skip to content

fix(metrics): count COCO boundary areas in both mAR size buckets - #2848

Merged
Borda merged 5 commits into
roboflow:developfrom
kevin9327:fix/mar-coco-inclusive-size-buckets
Nov 2, 2026
Merged

Borda merged 5 commits into
roboflow:developfrom
kevin9327:fix/mar-coco-inclusive-size-buckets

Conversation

@kevin9327

Copy link
Copy Markdown
Contributor

Summary

Fixes #2846.

MeanAverageRecall filtered size buckets with ObjectSizeCategory's half-open bins (area < 32², 32² <= area < 96², area >= 96²). An object whose area is exactly 32² or 96² therefore landed in only one bucket.

pycocotools and this repo's MeanAveragePrecision use inclusive COCO ranges ([0, 32²], [32², 96²], [96², 1e5²]), so the same object is counted in both neighbouring buckets. On identical data, mAR and mAP disagreed about which bucket an object belonged to.

Filter mAR size buckets with those inclusive ranges. ObjectSizeCategory stays half-open for general filtering.

Testing

  • Added TestMeanAverageRecallCocoSizeBuckets.test_boundary_area_belongs_to_both_coco_size_buckets
  • Verified locally: a perfect 32×32 prediction scores mAR@100 = 1 in both small and medium; a perfect 96×96 scores 1 in both medium and large

AI-assisted (Grok)

MeanAverageRecall filtered targets with ObjectSizeCategory's half-open
bins, so an object of area exactly 32² or 96² belonged to only one
bucket. pycocotools and MeanAveragePrecision use inclusive ranges and
count those boundary areas in both neighbouring buckets.

Filter mAR size buckets with the same inclusive COCO ranges as mAP.
Leave ObjectSizeCategory's half-open bins unchanged for general use.
@kevin9327
kevin9327 requested a review from SkalskiP as a code owner October 29, 2026 06:30
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-29T06:36:30.907643Z
We couldn’t complete this review. Comment @codex review to try again.
9a20196 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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

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.

🟡 Changes recommended

Float16 area multiplication can overflow before conversion to float64, causing valid large boxes to be incorrectly excluded from the large-object bucket.

1 open issue
What changed in this PR

This PR addresses #2846 by aligning MeanAverageRecall size buckets with COCO’s inclusive boundaries, while preserving ObjectSizeCategory’s half-open bins for general filtering.

Changes:

  • Includes areas exactly 32² and 96² in both neighboring mAR buckets.
  • Adds area extraction for boxes, masks, oriented boxes, and explicit area metadata.
  • Adds regression tests for perfect predictions at both boundaries.
File Description
tests/​metrics/​test_mean_average_recall.py Tests boundary inclusion and unchanged empty-bucket results.
src/​supervision/​metrics/​utils/​object_size.py Adds per-detection area extraction helpers.
src/​supervision/​metrics/​mean_average_recall.py Replaces half-open category filtering with inclusive COCO ranges.

Review effort: Balanced

@kevin9327

Copy link
Copy Markdown
Contributor Author

CI was red because test_small_bucket_mar_returns_zero_without_bucket_targets used a 32 x 32 target to get an empty small bucket. With the inclusive COCO range ([0, 32²], as in MeanAveragePrecision and pycocotools) that target is now small, so the test no longer had "no support". 057b22c moves the target to 33 x 33 so the test still checks what its docstring says (zeros instead of NaN when the small bucket has no targets). tests/metrics passes locally (481 passed).

@codecov

codecov Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 79.03226% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 94%. Comparing base (d3a07a5) to head (ab78e2f).
⚠️ Report is 7 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff           @@
##           develop   #2848   +/-   ##
=======================================
- Coverage       94%     94%   -0%     
=======================================
  Files           83      83           
  Lines        13975   14059   +84     
=======================================
+ Hits         13206   13282   +76     
- Misses         769     777    +8     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

A float16 box such as [0, 0, 256, 256] overflowed to an infinite area because the
subtraction and multiplication ran in float16, so the finite COCO upper bound
dropped it from the large bucket. Also fix the pre-commit failures: wrap the long
docstring line, use 'x' instead of the multiplication sign, and type the test
helper's return as MeanAverageRecallResult.
Changes:
- Parametrize mAR size bucket coverage for 32×32, 96×96, and both boundary boxes together.
- Move the detection area utility import to module scope.

Impact:
- Reports each boundary scenario independently and checks their combined result.

Verification:
- Mean average recall test file: 53 passed in an existing compatible environment.
- Repository-wide pre-commit checks: passed.
- git diff --check: passed.

Residual limits:
- Full coverage suite stopped during collection because the available environment lacks scikit-learn.

---

Co-authored-by: Codex <[email protected]>
@Borda
Borda merged commit 5d9c2f7 into roboflow:develop Nov 2, 2026
35 checks passed
Borda added a commit that referenced this pull request Nov 3, 2026
MeanAverageRecall filtered targets with ObjectSizeCategory's half-open
bins, so an object of area exactly 32² or 96² belonged to only one
bucket. pycocotools and MeanAveragePrecision use inclusive ranges and
count those boundary areas in both neighbouring buckets.

Filter mAR size buckets with the same inclusive COCO ranges as mAP.
Leave ObjectSizeCategory's half-open bins unchanged for general use.

* test(metrics): use a 33x33 target for the empty small-bucket mAR test
* fix(metrics): promote float box coordinates before computing areas
* test(metrics): parametrize recall size boundary cases

---------

Co-authored-by: kevin9327 <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Jirka Borovec <[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 drops objects with area exactly 32² or 96² from one COCO size bucket (pycocotools and MeanAveragePrecision include them)

3 participants