Pytorch - RuntimeError: Error(s) in loading state_dict for Sequential: Unexpected key(s) in state_dict: "0.weight", "0.bias",
I have created a Pytorch object from  the class Sequential (see official page).
As they suggest, I am saving it using the command torch.save(model.state_dict(), PATH).
It seems that everything has worked fine, since when I use torch.load(PATH) in another file I get
an ordered Dict like
'0.weight': tensor([[ 0.1202, ...]]) ,
'0.bias':  tensor([ 0.1422, ...]) ,
...

with all the shapes of the tensors being correct. However, when doing
model = Sequential()
model.load_state_dict(torch.load(PATH))

I get the error
RuntimeError: Error(s) in loading state_dict for Sequential:
        Unexpected key(s) in state_dict: &quot;0.weight&quot;, &quot;0.bias&quot;, &quot;2.weight&quot;, &quot;2.bias&quot;, &quot;4.weight&quot;, &quot;4.bias&quot;.


When trying to load, the model you are trying to load into (model) is an empty Sequential object with no layers. On the other hand, looking at the error message, the state dictionary of the model you are trying to load from indicates that it has at least five layers, with the first, third, and fifth layers containing a weight and bias parameter. This is a mismatch since the corresponding layers and parameters do not exist in model.
To fix this, model should have the same architecture as the saved model you are trying to load. Since you say you saved the original model yourself, use an identical initialization step when creating model.
