Why does accuracy differs though the learning rate is kept constant

I am running this code for differentiating two people. I have image set of these two person.
But, the accuracy of the model changes each time i run the code. though the learning rate is constant.

The code is exact same as taught in the first lesson.

import sys

sys.path.append(“C:\Users\Anurag\github_pro\fastai”)

from fastai.imports import *
from fastai.transforms import *
from fastai.conv_learner import *
from fastai.model import *
from fastai.dataset import *
from fastai.sgdr import *
from fastai.plots import *

PATH = “C:\Users\Anurag\github_pro\fastai\courses\dl1\data\BTS\”
sz=124
arch=resnet34
data = ImageClassifierData.from_paths(PATH, tfms=tfms_from_model(arch, sz))
learn = ConvLearner.pretrained(arch, data, precompute=True)
learn.fit(0.01, 2)

What i might be doing wrong?

Thanks.

There are a couple of reasons:

  1. Each time you run this code you are creating a new learner object. The weights for the last added linear layers will get randomly initialized to new values each time. This can be seen by running the code below after creating the learner and before running the fit function.

    for child in learn.model.children():
        if isinstance(child, nn.Linear):
            print(child.weight)    
    
  2. The dropout layers will randomly pick values to zero out based on the percentage dropout that they are defined with (25% and 50% in this case) and these randomly selected values change for each forward call.

1 Like

Okay, I get it.

Thanks a lot.