DetectionMetricsFactory ignores predictions for unrepresented ground truth classes, skipping False Positives in mAP
Maintainers usually reply within 6 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 87/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- python
- Domain
- machine-learning
Research direction
Start in perceptionmetrics/utils/detection_metrics.py, at the zero-ground-truth guard in compute_metrics() (around lines 174-177) and the matching guard in compute_coco_map() (around lines 268-271). Change both so a class with predictions but no ground truth records AP, Precision and Recall as 0.0, TP 0, FP len(detections), FN 0, and appends 0.0 to ap_values. Add a test in tests/test_detection_metrics.py that feeds predictions for an absent class and asserts the metrics and that mAP includes the zero.
Written by the indexing model from the issue text.
Description
DetectionMetricsFactory ignores predictions for unrepresented ground truth classes, skipping False Positives in mAP
Description
In perceptionmetrics/utils/detection_metrics.py, DetectionMetricsFactory.compute_metrics() (lines 174-177) and compute_coco_map() (lines 268-271) iterate over accumulated class detections:
for label, detections in self.results.items():
# Skip classes with no ground truth instances
if self.gt_counts.get(int(label), 0) == 0:
continue
When a model outputs predictions for a class that has zero ground truth instances in the evaluated dataset:
- In
update(), all such predictions are correctly flagged as False Positives(score, 0)underself.results[p_label]. - However, because
self.gt_counts.get(int(label), 0) == 0,compute_metrics()skips the class completely. - As a result,
compute_ap()is never executed for this class,Precisionis reported asNaN(or omitted) instead of0.0, and the0.0AP is excluded fromap_values. - In
compute_coco_map(), the identicalif self.gt_counts.get(int(label), 0) == 0: continuecheck skips the class at every IoU threshold.
This means a model that hallucinates dozens of phantom bounding boxes for classes not present in the dataset receives no penalty in its mAP calculation.
Expected Behavior
If predictions exist for a class with zero ground truth boxes, those predictions are False Positives. The class should have Precision = 0.0, Recall = 0.0, AP = 0.0, and should penalize the overall mAP by including 0.0 in the mean AP.
Proposed Solution
In compute_metrics() and compute_coco_map(), handle classes with predictions but zero ground truth instances by recording AP = 0.0, Precision = 0.0, Recall = 0.0, TP = 0, FP = len(detections), FN = 0, and including 0.0 in ap_values:
if self.gt_counts.get(int(label), 0) == 0:
if len(detections) > 0:
metrics[label] = {
"AP": 0.0,
"Precision": 0.0,
"Recall": 0.0,
"TP": 0,
"FP": len(detections),
"FN": 0,
}
ap_values.append(0.0)
continue
I can open a PR with this correction and a test case in tests/test_detection_metrics.py.
- Dominant language
- Python
- Stars
- 116
- Forks
- 117
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 6
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from JdeRobot/PerceptionMetrics
-
COCO-style mAP@[0.5:0.95] doesn't match pycocotools (uses 11-point interpolation)May be free again @clarkf19 claimed this 7 days ago, and no pull request is open. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
JdeRobot/PerceptionMetrics#685 · 2 comments ·
Maintainers usually reply within 6 days
-
COCO crowd annotations (iscrowd=1) are counted as ground truth, lowering detection recall and APOpen
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
JdeRobot/PerceptionMetrics#681 · 1 comment ·
Maintainers usually reply within 6 days
-
YOLO loader drops images that have no label fileMay be free again @guptakaran20 claimed this 12 days ago, and no pull request is open. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
JdeRobot/PerceptionMetrics#680 · 1 comment ·
Maintainers usually reply within 6 days
-
Four dataset tests fail on Windows because fixtures hard-code POSIX pathsPossibly taken @aericheng claimed this 7 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
JdeRobot/PerceptionMetrics#679 · 2 comments ·
Maintainers usually reply within 6 days
-
pm_eval_model crashes with TypeError after the evaluation when --out_fname is not given (regression from #617)Possibly taken @Siddhanthguptaa claimed this 16 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
JdeRobot/PerceptionMetrics#675 ·
Maintainers usually reply within 6 days
All issues in JdeRobot/PerceptionMetrics
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
UKGovernmentBEIS/inspect_ai#6733 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
ProyectoRespira/respira-webapp#334 ·
Maintainers usually reply within 1 day
-
bug security-alert
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
spectrayan/carefold#391 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
Jakeschincariol/instagram-agent-skill#83 ·
Maintainers usually reply within 10 days
-
Difficulty 1/5 Under an hour Newbie friendliness 64/100