Hi everyone I am getting an error wen trying to load the model from the saved checkpoint file.
Model:
class RecNet2(nn.Module):
def __init__(self, in_shape, num_classes=12 ):
super(RecNet2, self).__init__()
self.layer1 = nn.GRU(in_shape[-1], 256)
self.layer2 = nn.LSTM(256, 512)
self.fc1 = nn.Linear(512, 256)
self.fc2 = nn.Linear(40 * 256, num_classes)
def forward(self, x):
x, h_out = self.layer1(x)
x = F.dropout(x, p=0.5)
x, h_ou2 = self.layer2(x)
x = F.dropout(x, p=0.3)
x = self.fc1(x)
x = self.fc2(x.view(-1, 40 * 256))
return x #logits
Error message:
>>> model.load_state_dict(fle)
Traceback (most recent call last):
File "/home/user/miniconda3/envs/torch/lib/python3.6/site-packages/torch/nn/modules/module.py", line 482, in load_state_dict
own_state[name].copy_(param)
RuntimeError: invalid argument 2: sizes do not match at /opt/conda/conda-bld/pytorch_1512387374934/work/torch/lib/THC/generic/THCTensorCopy.c:101
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/user/miniconda3/envs/torch/lib/python3.6/site-packages/torch/nn/modules/module.py", line 487, in load_state_dict
.format(name, own_state[name].size(), param.size()))
RuntimeError: While copying the parameter named layer1.weight_ih_l0, whose dimensions in the model are torch.Size([768]) and whose dimensions in the checkpoint are torch.Size([768, 101]).
The .pth
file has been created during training of the above model. Any suggestions on how to investigate this and why are there mismatch tensor shape errors?