Skip to content

Commit 98d4b73

Browse files
Fix AP/mAP calculations by sorting prediction confidence scores and handle IoU zero division (#545)
Co-authored-by: Shardul Mahamulkar <shardulmahamulkar@users.noreply.github.com>
1 parent cb729b7 commit 98d4b73

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

perceptionmetrics/utils/detection_metrics.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,13 @@ def _match_predictions(
127127

128128
ious = compute_iou_matrix(pred_boxes, gt_boxes) # shape: (num_preds, num_gts)
129129

130-
for i, (p_box, p_label, score) in enumerate(
131-
zip(pred_boxes, pred_labels, pred_scores)
132-
):
130+
# Sort predictions by descending score to ensure highest-confidence predictions match first
131+
sorted_indices = np.argsort([-s for s in pred_scores])
132+
133+
for i in sorted_indices:
134+
p_box = pred_boxes[i]
135+
p_label = pred_labels[i]
136+
score = pred_scores[i]
133137
max_iou = 0
134138
max_j = -1
135139

0 commit comments

Comments
 (0)