Why does my output from a pretrained VGG19 model keep changing after model.eval()?

I am playing around with pre-trained models. In this case, VGG19. After training the full model and running model.eval(), I input a single image into the model to see what the output returns. If I run it for a second time, the output has completely changed for the same image.

Now I am wondering, is the dropout layer not freezing? When I run model.classifier[5].training, it returns false. Which tells me it is frozen.

I’ve posted my code here.

You are using classify_img, which uses TRANSFORM_IMG, which uses random transformations:

TRANSFORM_IMG = transforms.Compose([
                                    transforms.RandomResizedCrop(size=256, scale=(0.8, 1.0)),
                                    transforms.Normalize([0.485, 0.456, 0.406],
                                                         [0.229, 0.224, 0.225])

so the difference is expected.
Create a transformation for the validation/test case without the random transformations and it should work. :slight_smile:

1 Like