Confusion matrix with one single image to test

You do not need confusion matrix for a single image. Confusion matrix is used for large number of inputs to get statistical measurement of model’s behavior. For instance, in training stage, you may have report Accuracy. This optained from confusion matrix, so for single image, it is 0 or 100% accuracy.

For any number of input images, depends on your model, you get a result like [samples, classes]. For a single image it is like pred=[1, classes]= [[0.1, 0.9, ..., 0.3]]. By taking argmax over this tensor, you will get the index of predicted class which in our example it would be torch.argmax(pred, dim=-1). It will return 1 as the index of maximum. So, there is no need to define confusion matrix for a single image.
Your model predict class 1 and you already have true label.

2 Likes