fix: correct area handling in MeanAveragePrecision for size-specific mAP #1894
+208
−2
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
This PR fixes an error in
supervision.metrics.mean_average_precision.MeanAveragePrecision
where the area used for size-specific evaluation (small / medium / large) was always zero unless explicitly provided inDetections.data
.The fix now:
data["area"]
if present (COCO import path).Detections.area[target_idx]
, leveraging Supervision’s property which already handles both bbox and mask cases.In addition, a lightweight test suite (
test/metrics/test_mean_average_precision_area.py
) has been added to guard against regressions.To reproduce:
Use a non-coco dataset as ground-truth (in my case yolov5). I am using from_yolo followed by using the Detection objects as GT's. Than, create the predictions using from_inference with results from our API. Pass both to the mAP calculator.
Before:

The areas will be 0 (the default fallback), leading to wrong/non-existing metrics for the specific sizes.
After:

Dependencies: none.
Type of change
Please delete options that are not relevant.
How has this change been tested, please provide a testcase or example of how you tested the change?
Running tests and testing with a yolov5 dataset.
The new tests cover:
Normal detections (empty data) – area is auto-calculated.
COCO detections (area in data) – provided area is preserved.
Mixed batch – both code paths together.
Size-specific mAP no longer returns -1.0 for medium / large.
Verification that the evaluator truly uses Detections.area.
All existing tests continue to pass.
Any specific deployment considerations
None – pure Python change, no API or dependency impact.
Docs