supervision icon indicating copy to clipboard operation
supervision copied to clipboard

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

Open Lingikaushikreddy opened this issue 1 month ago • 0 comments

Search before asking

  • [x] I have searched the issues and discussions and found no similar bug report.

Bug

sv.metrics.MeanAverageRecall counts crowd targets (targets.data["iscrowd"] == 1) as objects the model missed. In COCO evaluation a crowd region is an ignore region: it is never a miss, and a prediction on it is not a hit. DetectionDataset.from_coco stores iscrowd by default (use_iscrowd=True) and MeanAveragePrecision honours it, so on any COCO dataset with crowd annotations, mAR from supervision is lower than pycocotools AR. The same holds for the data["ignore"] flag that MeanAveragePrecision also reads.

In mean_average_recall.py the ignore mask passed to the confusion matrix is always zeros, and crowd targets stay in the denominator of every class's recall.

One normal target, one crowd target and one perfect prediction:

AR@100 ARs
pycocotools 2.0.11 1.0 -1 (no non-ignored small target)
sv develop 0.5 0.0

On a seeded harness with 0–3 crowd targets per image (100 trials, boxes), mAR differs from pycocotools in 77 of 100 trials on develop.

Environment

  • supervision develop @ 927dfeb05 (0.31.0)
  • macOS arm64, Python 3.12.13, NumPy 2.3.1, pycocotools 2.0.11

Minimal Reproducible Example

import numpy as np
import supervision as sv
from supervision.metrics import MeanAverageRecall

targets = sv.Detections(
    xyxy=np.array([[0, 0, 50, 50], [100, 0, 200, 100]], dtype=np.float32),
    class_id=np.array([0, 0]),
    data={"iscrowd": np.array([0, 1])},
)
predictions = sv.Detections(
    xyxy=np.array([[0, 0, 50, 50]], dtype=np.float32),
    class_id=np.array([0]),
    confidence=np.array([0.9]),
)
print(MeanAverageRecall().update(predictions, targets).compute().mAR_at_100)
# 0.5   (pycocotools AR@100: 1.0)

Are you willing to submit a PR?

  • [x] Yes I'd like to help by submitting a PR!

Lingikaushikreddy avatar Oct 16 '26 19:10 Lingikaushikreddy