Implement the two functions that turn detector output into a benchmark score.
iou(box_a, box_b)
[x1, y1, x2, y2] with x1 < x2, y1 < y2. Return the intersection area divided by the union area as a float; 0.0 when the boxes do not overlap.mean_average_precision(preds, gts, iou_thresh=0.5)
preds is a list of (class_id, score, box) and gts a list of (class_id, box) for a single image.gts: sort that class's predictions by score descending; walk them in order and mark a prediction a true positive when its IoU with an unmatched ground-truth box of the same class is at least iou_thresh (the best-IoU unmatched box is taken and then consumed), otherwise a false positive.p[i] = max(p[i:])), and integrate over recall with the all-point method: with .gts, rounded to 4 decimals.max(0, min(x2s) - max(x1s)); union is the two areas minus the intersection.used list per class so a ground-truth box can match at most one prediction.