I have trained a basic classifier model in fastai using a
I have freezed the model body and set all the
batchnorm layers in the body to not update the batchnorm params by iterating over all the params and setting the module’s
for module in learn5.model.modules(): if isinstance(module, nn.BatchNorm2d): if hasattr(module, 'weight'): module.weight.requires_grad_(False) if hasattr(module, 'bias'): module.bias.requires_grad_(False) module.eval()
Then I trained the classifier and saved only model’s head using the following.
Now, during inference, I create the model by loading the body using
create_body method of fastai and for the head I create it using
create_head and load the model’s
After comparing the weights of the two models, one by using
load_state_dict and other by using
load_learner, the two model’s parameters are exactly the same and yet when I do a forward pass, I obtain different results for the same input. I have attached the entire notebook below as an HTML file.
Comparison Notebook Link. Request you to download the notebook and view in browser (prefarably chrome).
Can someone please help me understand where might I be going wrong because of which this issue is coming?
Thanks & Regards,