Mean Average Precision producing incorrect values, maybe? #1695
Replies: 2 comments
|
Any updates on this issue? I have a similar problem |
|
@dominic-simon @Leonnorblad — the MAP values being identical for original vs. adversarial images likely comes down to confidence score filtering, not a bug in the metric. Here's what's probably happening: Faster R-CNN outputs predictions sorted by confidence. When you have both true detections (high confidence) and adversarial false positives (which may also have high confidence or — more commonly — lower confidence), MAP is dominated by the high-confidence true detections because:
Debugging steps: from torchmetrics.detection import MeanAveragePrecision
metric = MeanAveragePrecision(
iou_type="bbox",
class_metrics=True,
extended_summary=True,
)
metric.update(preds_original, targets)
result_orig = metric.compute()
metric.reset()
metric.update(preds_adversarial, targets)
result_adv = metric.compute()
# Compare per-class
print("Original per-class:", result_orig["map_per_class"])
print("Adversarial per-class:", result_adv["map_per_class"])
# Check if the predictions are actually different
print("Num preds original:", sum(len(p["scores"]) for p in preds_original))
print("Num preds adversarial:", sum(len(p["scores"]) for p in preds_adversarial))Also check your Filter by confidence to see the effect: threshold = 0.3
filtered_preds = []
for p in preds_adversarial:
mask = p["scores"] > threshold
filtered_preds.append({
"boxes": p["boxes"][mask],
"scores": p["scores"][mask],
"labels": p["labels"][mask],
})Docs: MeanAveragePrecision |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hello,
I'm trying to find the Mean Average Precision (mAP) over a set of images from the MSCOCO dataset that have been modified to cause the object detector in use (Faster-RCNN, in this case) to predict objects that don't exist. To be clear, the objects that don't exist are objects that generally have very little to no overlap with any ground truth objects.
My issue is that when I compare the original image mAP to the modified image mAP, they are the exact same, which does not seem correct. Below are what the images look like:



Ground Truths
Original Image Predictions
Modified Image Predictions
To the best of my knowledge, these two images should have two different mAPs, with the original image having a much higher mAP than the modified image since the modified image has many False Positive predictions (all the boxes to the left of the man on the surfboard). However, that is not the case, with both images receiving a mAP of 0.85.
Can someone confirm that I am correct in thinking that these two images should receive different mAPs? If I'm wrong, then perhaps an explanation of where I'm going wrong would be useful? I'm not sure what I'm misunderstanding here, so any help is appreciated.
Here's my code, in case I'm doing something wrong there:
All reactions