IoU sits under every detection metric and every round of non-maximum suppression, and it has one bug that everybody writes once.
Implement iou_matrix(a, b). Given a of shape (n, 4) and b of shape (m, 4), where each row is a box [x1, y1, x2, y2] with x2 >= x1 and y2 >= y1, return the (n, m) array whose entry [i, j] is the intersection over union of a[i] and b[j].
a = [[0, 0, 2, 2]] area 4
b = [[1, 0, 3, 2]] area 4
intersection = 1 * 2 = 2
union = 4 + 4 - 2 = 6
iou = 1/3
Two boxes that do not touch have an IoU of 0.0. Two boxes of zero area also have an IoU of 0.0 rather than nan.
Do it without any Python loops: n and m are both in the thousands during evaluation.
The bug everyone writes once: the intersection width and height are computed as differences, and for disjoint boxes both come out negative. Multiplied together, two negatives give a confidently positive overlap for two boxes on opposite sides of the image.
Build the architecture on a canvas: place the components, configure them, connect them into a data flow, and write a short reason for each one. The AI reviewer grades your design against a rubric written specifically for this problem.
Minimum 5 components · needs a wide desktop screen