Renaming nn.Sequential Layers?

I’ve trained on a nn.Sequential model and would like to load the previously saved weights into another instance of the model. However, I’ve been trying to add names to the layers in this new model definition (which I didn’t previously do) and am running into an error with missing/unexpected keys.
Any ideas for how to circumvent such an issue?

You could load the state_dict and rename all keys to the newly given names.
The fastest way would probably be to use the state_dict of your new model definition and just create a loop over the keys of both dicts changing one to the other.

1 Like