Skip to content
DeepForgeby svx
All problems
HardComputer Visioncv-124

NMS per Class Count

Problem

Run non-maximum suppression separately per class and count the surviving boxes.

Process boxes in descending score order (ties by index) and suppress a box when its IoU with an already kept box of the same class is strictly greater than iou_threshold. Return a list where index c is the number of kept boxes of class c, with length max(classes) + 1.

Hint

Boxes of different classes never suppress each other.

Test cases

case 1
in: [[[0,0,2,2],[1,1,3,3],[10,10,12,12]],[0.9,0.8,0.7],[0,0,0],0.5]
expected: [3]
case 2
in: [[[0,0,2,2],[1,1,3,3],[10,10,12,12]],[0.9,0.8,0.7],[0,0,0],0.1]
expected: [2]
case 3
in: [[[0,0,2,2],[1,1,3,3],[10,10,12,12]],[0.9,0.8,0.7],[0,1,0],0.1]
expected: [2,1]
case 4
in: [[[0,0,2,2],[1,1,3,3]],[0.9,0.8],[2,2],0.1]
expected: [0,0,1]
case 5
in: [[],[],[],0.5]
expected: []
Starter codePython
def nms_per_class_counts(boxes, scores, classes, iou_threshold):
    # Your code here
    pass

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