Pytorch pretrained model (VGG-19) same image gives slightly different class score in the final FC layer

I am using pretrained vgg-19 from torch.vision module
I have the pre-processing of image data like below:

normalize = transforms.Normalize(
    mean=[0.485, 0.456, 0.406],
    std=[0.229, 0.224, 0.225]
)

preprocess = transforms.Compose([
   transforms.Scale(224),
   transforms.ToTensor(),
   normalize
])

The problem is if I pass an image like a tennis ball through the network and save all the 1000 class score from the final FC layer and pass the same image again after some time, the final FC layer i.e the class score is slightly changed. Although the image category detected by the network is correct. (its a tennis ball)

Is it normal to have the slightly different class score for the same image? I mean, does this suppose to happen? Or for the correctly implemented pre-trained model, the network should give you the exact same class score every time for the same image.

Is your net in eval mode? If not some layers like Dropout and BatchNorm might change your output.

2 Likes

Thank you so much. You just made my day. Its working now. :slight_smile: