Skip to content

Commit

Permalink
Fix mAP calculation for areas with 0 predictions
Browse files Browse the repository at this point in the history
The issue was first dicussed here: #1061 (comment)
  • Loading branch information
23pointsNorth committed Jun 8, 2022
1 parent cb2d553 commit 4d67e8d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions torchmetrics/detection/mean_ap.py
Expand Up @@ -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)
Expand Down

0 comments on commit 4d67e8d

Please sign in to comment.