Repository navigation
fix(metrics): report -1 for mean average recall without targets - #2965
Merged
Merged
Conversation
MeanAverageRecall returned 0.0 when there were no targets, for the whole run or for an empty small, medium or large size bucket. pycocotools AR and MeanAveragePrecision report -1 in that case, so an empty bucket looked like a model that missed every object. Return -1 sentinel scores when there are no targets.
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the change distinguishing undefined recall from a genuine zero score.
No open issues 🎉
What changed in this PR
This PR aligns MeanAverageRecall with MeanAveragePrecision and pycocotools by returning -1 when no targets exist, distinguishing undefined recall from a genuine zero score.
Changes:
- Return
-1for target-free runs and empty size buckets; preserve0when targets exist but predictions do not. - Add COCO-reference coverage and update empty-input and size-boundary expectations.
- Document the sentinel behavior and advise excluding negative scores when aggregating results.
| File | Description |
|---|---|
tests/metrics/test_size_bucket_regressions.py |
Update the empty-small-bucket regression to expect -1. |
tests/metrics/test_mean_average_recall.py |
Add COCO sentinel comparisons and update empty-input and boundary expectations. |
src/supervision/metrics/mean_average_recall.py |
Return sentinel scores in both no-target paths and update documentation. |
docs/changelog.md |
Explain the behavior change and aggregation guidance. |
Review effort: Balanced
Changes: - Integrate the current develop branch, including its released documentation, detection, annotation, dataset, tooling, and dependency updates. - Preserve the mean average recall sentinel change and place its changelog entry alongside current unreleased entries. Impact: - The PR retains its undefined-recall behavior while incorporating current project behavior and resolving the changelog collision. Verification: - Focused mean average recall and size-bucket tests: 88 passed; Git diff whitespace check passed. Residual limits: - Focused tests used the NumPy fallback because OpenCV was unavailable; full remediation checks remain pending. --- Co-authored-by: Codex <[email protected]>
Changes: - Label undefined mean average recall values as N/A inside standalone and comparison plots. - Preserve numeric labels for other metrics and add regression coverage for zero scores, empty size buckets, and multiple models. - Document the plot labels in the PR changelog entry. Impact: - Plot readers can distinguish unavailable recall from a measured zero without changing other metrics' labels. Verification: - Full project gate: 7,584 tests passed, 283 skipped; pre-commit and diff checks passed. - Focused plot tests: 31 passed after failure-first checks. Residual limits: - Local tests used the NumPy fallback without OpenCV. - Develop advanced after the recorded target integration and has not been merged again. --- Co-authored-by: Codex <[email protected]>
Borda
approved these changes
Nov 24, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #2965 +/- ##
=======================================
Coverage 95% 95%
=======================================
Files 84 84
Lines 15503 15547 +44
=======================================
+ Hits 14772 14830 +58
+ Misses 731 717 -14 🚀 New features to boost your workflow:
|
Borda
enabled auto-merge (squash)
November 24, 2026 00:10
Borda
disabled auto-merge
November 24, 2026 00:28
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
sv.metrics.MeanAverageRecallreturned0.0when there were no targets to recall, for a whole run or for an empty small / medium / large size bucket.MeanAveragePrecisionand pycocotools return-1in that case, so an empty bucket looked like a model that found none of its objects. This PR returns the-1sentinel there.Motivation and Context
Recent mAR fixes have aligned the metric with pycocotools; this is the remaining difference I found when comparing the two on random inputs (it showed up only on empty buckets). It also matches what
MeanAveragePrecisionResultdocuments since #2415.Closes #2964
Changes Made
mean_average_recall.py: both no-target paths returnnp.full(max_detection_count, -1.0)instead of zeros (theif not statsearly return and theunique_classes.size == 0branch, which is not reachable today but kept consistent). Docstring and the__str__doctest updated. With targets but no predictions, mAR is still0.test_results_without_targets_match_coco_sentinel(no targets at all; only a large target, so small and medium are empty), compared against pycocotools throughtests/metrics/coco_reference.py.docs/changelog.md: entry under Unreleased, with a note for code that aggregates bucket scores.plot()keepsylim(0, 1), so a-1bar is not visible (same as mAP today); could be a follow-up.Testing
New and updated tests fail on
develop(ACTUAL: array([0., 0., 0.]) DESIRED: array([-1., -1., -1.])) and pass with this change.pytest -q(whole repo): 7704 passed, 45 skipped.tests/metricsplus metrics doctests: 791 passed.ruff check ./ruff format --check .(0.17.3): clean. mypy on the changed files: clean apart from missing third-party stubs in my local env (same ondevelop). codespell clean.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.mdunderUnreleased(skip for lint/type/format-only or pure doc changes)Additional Notes
Three existing tests asserted
0for the no-target case, and I changed them to-1:test_empty_inputs_keep_max_detection_axistest_small_bucket_mar_returns_zero_without_bucket_targetsintest_size_bucket_regressions.py, renamed to..._returns_sentinel_.... It was added in fix: resolve medium dataset findings #2408 to return zeros instead of NaN;-1still avoids NaN.TestMeanAverageRecallCocoSizeBuckets::test_boundary_area_belongs_to_both_coco_size_buckets(at-32,at-96, from fix(metrics): count COCO boundary areas in both mAR size buckets #2848): the empty bucket now expects-1.0.If
0was intended for mAR, I'm happy to drop this. Recall, Precision and F1 still return0for an empty bucket; I left them alone since they have no COCO reference.