How to interpret Resnet prediction output?

I have trained the pretrained Resnet model 18 for binary classification. I use this function to predict a single image:

def predict_image(image):
    image_tensor = test_transforms(image).float()
    image_tensor = image_tensor.unsqueeze_(0)
    input = Variable(image_tensor)
    input =
    output = model(input)
    index =
    return index

This prints
torch.Size([3, 224, 224])
torch.Size([1, 3, 224, 224])
[[-0.30215618 0.21753347]]

Shouldn’t the probabilities sum to 1, What does a negative probability mean here ?

Your outputs can’t be interpreted as probabilities as they don’t sum to 1. Did you use CrossEntropyLoss? That includes a log_softmax layer. Try to normalize your outputs by running them through a softmax layer to have them sum to 1.

edit: softmax -> log_softmax

1 Like

Would it be correct if I selected the class with larger number as the predicted class ?

Yes I’d say so (but it can depend on the label+loss but in 99% of the time you can)

1 Like