Skip to content
DeepForgeby svx
All problems
MediumComputer Visioncv-313

Pairwise IoU Matrix

Problem

Compute the IoU of every box in boxes_a against every box in boxes_b.

Boxes use [x1, y1, x2, y2] with continuous coordinates. Return a len(boxes_a) x len(boxes_b) matrix of IoUs rounded to 4 decimal places; non-overlapping or degenerate pairs score 0.0.

Test cases

case 1
in: [[[0,0,2,2],[1,1,3,3]],[[0,0,2,2],[4,4,6,6]]]
expected: [[1,0],[0.1429,0]]
case 2
in: [[[0,0,1,1]],[]]
expected: [[]]
case 3
in: [[[0,0,2,2]],[[0,0,2,2],[2,2,4,4],[1,1,2,2]]]
expected: [[1,0,0.25]]
Starter codePython
def iou_matrix(boxes_a, boxes_b):
    # Your code here
    pass

3 test cases · run your code against them in the editor