Skip to content
DeepForgeby svx
All problems
HardComputer Visioncv-168

Mean IoU over Classes

Problem

Compute mean intersection over union over num_classes.

For each class compute intersection / union over the two label maps, where a pixel belongs to the union when either map equals the class. Classes with an empty union score 0.0; return the mean rounded to 4 decimal places.

Test cases

case 1
in: [[[0,1],[1,0]],[[0,1],[1,0]],2]
expected: 1
case 2
in: [[[0,1],[1,0]],[[1,1],[1,1]],2]
expected: 0.25
case 3
in: [[[0,0],[0,0]],[[0,0],[0,0]],2]
expected: 0.5
case 4
in: [[[0,1],[2,0]],[[0,2],[2,0]],3]
expected: 0.5
Starter codePython
def mean_iou(pred, target, num_classes):
    # Your code here
    pass

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