From 4d67e8d3c91ce285cabead45dcad34b51d7f250f Mon Sep 17 00:00:00 2001 From: Daniel Angelov Date: Wed, 8 Jun 2022 23:41:24 +0300 Subject: [PATCH] Fix mAP calculation for areas with 0 predictions The issue was first dicussed here: https://github.com/PyTorchLightning/metrics/issues/1061#issuecomment-1150106306 --- torchmetrics/detection/mean_ap.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/torchmetrics/detection/mean_ap.py b/torchmetrics/detection/mean_ap.py index 557135aaad4..d81e9556904 100644 --- a/torchmetrics/detection/mean_ap.py +++ b/torchmetrics/detection/mean_ap.py @@ -482,9 +482,11 @@ def __evaluate_image_gt_no_preds( ) -> Dict[str, Any]: """Some GT but no predictions.""" # GTs - gt = gt[gt_label_mask] + gt = np.asarray(gt)[gt_label_mask] + if len(gt_label_mask) == 1: + gt = np.expand_dims(gt, axis=0) nb_gt = len(gt) - areas = box_area(gt) + areas = compute_area(gt, iou_type=self.iou_type).to(self.device) ignore_area = (areas < area_range[0]) | (areas > area_range[1]) gt_ignore, _ = torch.sort(ignore_area.to(torch.uint8)) gt_ignore = gt_ignore.to(torch.bool)