Accuracy worsens after unfreezing

I am working on a typical image classification task and I am encountering some weird behaviors.

After unfreezing, my accuracy worsens after I call fit_one_cycle. What might be the issue to this behavior?

Thank you.

As you unfreeze and start training again, you are poking at these finely tuned imagenet weights. You should do that with care. Try:

  • adopting a smaller learning rate for the earliest block

  • freezing the whole first block (so that you retrain just the second and the final block).


Thank you for the reply. How can I freeze only the first block because calling unfreeze itself unfreezes all the blocks.

Note that the library splits in 3 groups by dafault: first half of the CNN (roughly, check it with learn.layer_groups, whare learn is the name of your learner), second half of it, and the two final fully connected layers. If you want, you can change such behaviour, and split into as many groups you see fit.

EDIT: For example, try and create a standard learner with your data and a resnet as base arch, e.g., resnet50. Now call learn.layer_groups.

Then try:

learn.split(lambda m: (m[0][6], m[0][7], m[1]))

and call learn.layer_groups again, to see the difference. Apart from showing a way to do the split (I just copied and pasted the docs with a slight modification), the gist is that you have to care about how the network is nested as you pass the structure to split(). Note that fastai adds the head as a first level sublist.

1 Like

Thanks, once again, balnazzar!

1 Like