I define a model
from torchvision import models
model = models.resnet18()
It has all its layers set as trainable (requires_grad = True for all layers)
Then I freeze the final fc layer
for param in model.fc.parameters():
param.requires_grad = False
Then I save the state_dict of the model
Now I want to load the weights again. So I define the model once again and load the saved weights in it…
model_new = models.resnet18()
Now when I print the requires_grad of its fc layer, all the requires_grad are back to the original setings (True)
for param in model_new.fc.parameters():
So the question is that, how is the requires_grad setting getting changed on loading the weights?
Does saving the model.state_dict() even save the requires_grad settings?