All problems
Matching Cost Matrix
Problem
Build the DETR matching cost matrix: cost[i][j] = cost_bbox * L1(pred_box_i, target_box_j) + cost_class * (1 - pred_probs[i][target_label_j]).
The signature is matching_cost_matrix(pred_boxes, target_boxes, pred_probs, target_labels, cost_bbox=5.0, cost_class=1.0). Boxes are [x1, y1, x2, y2] vectors.
Hint
The class cost uses the probability the prediction assigns to the target's label.
Test cases
case 1
in: [[[0,0,1,1],[1,1,2,2]],[[0,0,1,1]],[[0.9,0.1],[0.2,0.8]],[0],5,1]
expected: [[0.1],[20.8]]
case 2
in: [[[0,0,1,1],[2,2,3,3]],[[0,0,1,1],[1,1,2,2]],[[0.7,0.3],[0.4,0.6]],[0,1],5,1]
expected: [[0.3,20.7],[40.6,20.4]]
case 3
in: [[[0,0,1,1],[1,1,2,2],[2,2,3,3]],[[0,0,1,1]],[[0.5,0.5],[0.9,0.1],[0.1,0.9]],[1],1,1]
expected: [[0.5],[4.9],[8.1]]
case 4
in: [[[0,1]],[[0,2]],[[0.5,0.5]],[0],2,3]
expected: [[3.5]]
Starter codePython
def matching_cost_matrix(pred_boxes, target_boxes, pred_probs, target_labels, cost_bbox=5.0, cost_class=1.0):
# Your code here
pass4 test cases · run your code against them in the editor