I trained a ResNet-50 + MLP (2 nn.Linear) model. Next, I want to use the same model, except that I now have a Dropout layer in between the 2 nn.Linear layers in the MLP. But I also want to use the weights from the previous model.
I am receiving an error because the model changes and ‘load_state_dict’ cannot load the weights.
Is it possible to load the weights in this manner?
I attempted to do like this:
for n,p in model.named_parameters():
    try:
        p = model_state_dict[n]
    except:
        p = model_state_dict['projector.2.weight']

The name of the key in the saved model dict is ‘projector.2.weight’ while it becomes ‘projector.3.weight’ in the new model with dropout.
Also, weights of other layers not correctly loaded using this piece of code. Any suggestions??