Repository navigation
fix(metrics): size mAP buckets with the areas pycocotools uses - #2939
Merged
Borda merged 3 commits intoNov 11, 2026
Merged
Conversation
Predictions with data["area"] used that value as their area. pycocotools loadRes ignores result areas and calculates them from the bbox or segmentation, so the metadata moved unmatched predictions between size buckets. Target data["area"] was cast to float32. An area within about 1e-4 of 32² or 96² rounded onto the limit, and the target was scored in two buckets. Read it as float64, as pycocotools does. The COCO reference helper now passes prediction area metadata to pycocotools, so the live package decides how it is used. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2 of 3 tasks
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the mAP size-bucket corrections.
No open issues 🎉
What changed in this PR
Aligns MeanAveragePrecision size buckets with pycocotools, correcting small, medium, and large mAP when prediction area metadata conflicts with geometry or target areas lie near bucket boundaries.
Changes:
- Size predictions from their evaluated geometry, ignoring prediction area metadata.
- Preserve target area metadata as float64 to avoid rounding across bucket boundaries.
- Add six parity cases against
pycocotoolsand document the fixes.
| File | Description |
|---|---|
tests/metrics/test_mean_average_precision.py |
Adds box/mask metadata and target-boundary parity tests. |
tests/metrics/coco_reference.py |
Passes prediction area metadata through so pycocotools determines its handling. |
src/supervision/metrics/mean_average_precision.py |
Uses geometry-derived prediction areas and float64 target metadata. |
docs/changelog.md |
Documents both size-bucket corrections under Unreleased. |
Review effort: Balanced
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #2939 +/- ##
=======================================
- Coverage 95% 95% -0%
=======================================
Files 83 83
Lines 14445 14440 -5
=======================================
- Hits 13690 13685 -5
Misses 755 755 🚀 New features to boost your workflow:
|
Borda
previously approved these changes
Nov 11, 2026
Borda
approved these changes
Nov 11, 2026
Borda
added a commit
that referenced
this pull request
Nov 11, 2026
Predictions with data["area"] used that value as their area. pycocotools loadRes ignores result areas and calculates them from the bbox or segmentation, so the metadata moved unmatched predictions between size buckets. Target data["area"] was cast to float32. An area within about 1e-4 of 32² or 96² rounded onto the limit, and the target was scored in two buckets. Read it as float64, as pycocotools does. The COCO reference helper now passes prediction area metadata to pycocotools, so the live package decides how it is used. --------- Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Jirka Borovec <[email protected]>
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.MeanAveragePrecisionputs some objects in a different size bucket thanpycocotoolsdoes. This changes the small, medium and large mAP. There are 2 causes:data["area"]uses that value as its area.pycocotoolsCOCO.loadResignores the area of a result. It calculates the area again from the result'sbboxorsegmentation. An unmatched prediction counts as a false positive only in the buckets that contain its area, so the metadata moves false positives between buckets.data["area"]is cast to float32. float32 rounds an area within about 1e-4 of 32² or 96² onto the limit. The COCO area ranges include their limits, so the target is scored in 2 buckets.pycocotoolskeeps the area as a Python float.Repro, with
pycocotoolsthroughtests/metrics/coco_reference.py:Motivation and Context
Size-bucket mAP must match COCO, or the small, medium and large numbers cannot be compared with published results. Detections get
data["area"]from COCO files:sv.DetectionDataset.from_coco(..., use_iscrowd=True)stores it.sv.metrics.MeanAverageRecallalready reads target areas as float64 (get_detection_areas).I found both causes with a random-scene comparison against
pycocotools. There is no issue for them.Changes Made
MeanAveragePrecision._prepare_predictions: a prediction is always sized by its box, mask or oriented box (_content_area). Predictiondata["area"]is no longer read.MeanAveragePrecision._prepare_targets: targetdata["area"]is read as float64.tests/metrics/coco_reference.py: predictiondata["area"]now goes topycocotoolsin the result records. So the live package, not the helper, decides what to do with it.pycocotools. Prediction area metadata with boxes and with masks. Target areas just below and just above 32² and 96².Unreleased.EvaluationDataset.load_predictionsstill keeps anareakey that a caller gives it.MeanAveragePrecisionnow always gives it the geometry area.Testing
New tests on
develop:6 failed. With this change:6 passed.pytest tests/metrics:756 passed(750 passedondevelop).pytest(full suite and doctests, NumPy 2.5.4, NumPy backend without OpenCV):6655 passed, 279 skipped.pre-commit runon the changed files: all hooks pass, mypy included.Random scenes, not added to the suite: 300 box scenes and 300 mask scenes. Each scene has 1 to 3 images, 1 to 3 classes, sides near 32 and 96, 15% crowd targets and tied scores. Half of the target areas are moved to within 3e-4 of a limit, and every prediction has random
data["area"]. Ondevelop, 241 of the 300 box scenes differ frompycocotools. With this change, 0 box scenes and 0 mask scenes differ in any of the 6 AP values.MeanAverageRecallon the same scenes: 0 differences.Added/updated tests, and the full suite passes locally
Updated docs (docstrings / mkdocs entry) for new or changed public API (no API change)
Added a changelog entry in
docs/changelog.mdunderUnreleasedAdditional Notes
🤖 Generated with Claude Code