Skip to content
DeepForgeby svx
All problems
EasyComputer Visioncv-180

Pixel Confusion Matrix

Problem

Build a pixel confusion matrix between a prediction map and a target map.

Return a num_classes x num_classes matrix where entry [t][p] counts pixels whose target class is t and predicted class is p.

Hint

Rows are target classes and columns are predicted classes.

Test cases

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

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