Neural Networks on CIFAR-10

i have a ResNet trained on CIFAR-10. after giving the model images of cats and dogs and horses, how can I know the prediction of my model for each image? I want to know that for a pic x, did my model predicted correctly and was the pic a dog?

Hey again.
I am guessing this is the same question as here.
But there you said you only want to check for the dog labels.
If you want to check for all cifar10 labels you could try something like this:

classes = ('plane', 'car', 'bird', 'cat',
           'deer', 'dog', 'frog', 'horse', 'ship', 'truck')

num_label_lst = [0]*10
correct_lst = [0]*10

for images, labels in test_loader:
    images =
    labels =
    outputs = model(images)
    _, predicted = torch.max(, 1)

    #go through all labels
    for i, label in enumerate(labels):
        for j in range(10):
            #check with which cifar10 label it matches
            if label == j:
                #count up the counter for the number of occurrence for that label 
                num_label_lst[j] += 1
                #check if the prediction is the same
                if predicted[i] == j:
                    #count up the counter for the number of correct occurrences for that label
                    correct_lst[j] += 1
                #no need to check the other cifar10 labels so break the inner loop

for label_index, correct in enumerate(correct_lst):
    print(f"number of correct {classes[label_index]} labels: {correct}")
    print(f"{classes[label_index]} classification accuracy: {100*correct/num_label_lst[label_index]:.2f}%")
1 Like