Hi! I trained a ResNet model and I want to write an “if” condition for the times that my model predicted correctly and the image was a dog.
this is my data loader:
Could it be that you overlooked, that your batchsize is 100 not 1?
Could you give me a bit more information:
Predicted what correctly? One out of the 100 images in your batch? All of the 100 images in your batch? All dog images out of the 100 images in your batch?
By the way, this will only be True if all 100 images in your batch are correct.
Again, what image? One dog image of the 100 images? All dog images?
But since you said you only have 2 classes it might be either 0 or 1. Try printing your labels tensor and check for yourself.
Just in case you do want to use higher batchsize. Try something like:
for i, label in enumerate(labels):
if label == 5:
num_dog_label += 1
if predicted[i] == 5:
num_correct_dog += 1
accuracy = 100*num_correct_dog/num_dog_label
print(f"number of dog labels: {num_dog_label}")
print(f"number of correctly detected dog labels: {num_correct_dog}")
print(f"dog classification accuracy: {accuracy:.2f}%")