I have run this code:
z = torch.load(load_path)
for k, v in z.items():
print(z)
model.load_state_dict(z)
..........('base_loss', tensor([[0.]], device='cuda:0')),
('b', tensor(5., device='cuda:0')),
('x_grid',
tensor([[[[[-1.0000, -1.0000, -1.0000, -1.0000, -1.0000, -1.0000, -1.0000,
-1.0000, -1.0000, -1.0000, -1.0000, -1.0000, -1.0000, -1.0000,
-1.0000, -1.0000, -1.0000, -1.0000, -1.0000, -1.0000, -1.0000,
-1.0000, -1.0000, -1.0000, -1.0000, -1.0000, -1.0000, -1.0000],
[-0.9259, -0.9259, -0.9259, -0.9259, -0.9259, -0.9259, -0.9259,
-0.9259, -0.9259, -0.9259, -0.9259, -0.9259,.....
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-11-954a267c40b0> in <module>
22 for k, v in z.items():
23 print(z)
---> 24 model.load_state_dict(z)
~/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py in load_state_dict(self, state_dict, strict)
837 if len(error_msgs) > 0:
838 raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format(
--> 839 self.__class__.__name__, "\n\t".join(error_msgs)))
840 return _IncompatibleKeys(missing_keys, unexpected_keys)
841
RuntimeError: Error(s) in loading state_dict for IODINE:
While copying the parameter named "x_grid", whose dimensions in the model are torch.Size([1, 1, 1, 28, 28]) and whose dimensions in the checkpoint are torch.Size([1, 1, 1, 28, 28]).
While copying the parameter named "y_grid", whose dimensions in the model are torch.Size([1, 1, 1, 28, 28]) and whose dimensions in the checkpoint are torch.Size([1, 1, 1, 28, 28]).
While copying the parameter named "decoder.x_grid", whose dimensions in the model are torch.Size([1, 1, 28, 28]) and whose dimensions in the checkpoint are torch.Size([1, 1, 28, 28]).
While copying the parameter named "decoder.y_grid", whose dimensions in the model are torch.Size([1, 1, 28, 28]) and whose dimensions in the checkpoint are torch.Size([1, 1, 28, 28]).
All of the sizes are the same.
I am trying to run a version of IODINE i found on github… however, loading the saved dict into my model is trouble. I do not think I trained it with a parallel GPU, but there is that mode in the program. It does not match what I believe parallel dict should look like, based on what I’ve seen in other q&as on this site ( because there are keys with less than 7 elements)
Saving the model function looks like this:
def save(self,save_path,epoch=None):
print('Saving model at epoch {}'.format(epoch))
suffix = self.name if epoch is None else self.name+'_epoch_{}.th'.format(epoch)
model_save_path = save_path + suffix
torch.save(self.state_dict(),model_save_path)