Fazle Rabbi Tanjil
Fazle Rabbi Tanjil

Reputation: 236

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.

Upvotes: 1

Views: 922

Answers (1)

patapouf_ai
patapouf_ai

Reputation: 18693

Possible reasons why the class score could be different:

  • You are using GPUs: The GPU evaluation is slightly stochastic, so if you are using GPUs in your feedforward evaluation, it could give slightly different scores.
  • You are using the model in training mode model.train() and didn't activate the evaluation mode using model.eval() and your model contains some stochastic parts like dropout or adding noise to input. Then those stochastic parts will still be active.

Upvotes: 2

Related Questions