I save trained checkpoints in pytorch 1.0 as
def save_(state):
torch.save(state, 'model.pth')
save_({ 'state_dict': model.state_dict(), 'optimizer': optimizer.state_dict()})
I used the code to load checkpoint in the pytorch 0.3
import torch._utils
try:
torch._utils._rebuild_tensor_v2
except AttributeError:
def _rebuild_tensor_v2(storage, storage_offset, size, stride, requires_grad, backward_hooks):
tensor = torch._utils._rebuild_tensor(storage, storage_offset, size, stride)
tensor.requires_grad = requires_grad
tensor._backward_hooks = backward_hooks
return tensor
torch._utils._rebuild_tensor_v2 = _rebuild_tensor_v2
checkpoint_dict = torch.load(checkpoint, map_location=lambda storage, loc: storage)
model = Net()
net.load_state_dict(checkpoint_dict['state_dict'])
I got the error
Traceback (most recent call last):
File "load_model.py", line 151, in <module>
net.load_state_dict(checkpoint_dict['state_dict'])
File "/usr/local/lib/python2.7/dist-packages/torch/nn/modules/module.py", line 522, in load_state_dict
.format(name))
KeyError: 'unexpected key "features.norm0.num_batches_tracked" in state_dict'
How should I fix it?