Closed 007lva closed 3 years ago
Hi, @007lva. This is libtorch-related issue as the message says. I went through it several times. Before saving please convert python OrderedDict to common dict. Then it should load successfully. Something like:
your_model.state_dict().__class__
=> <class 'collections.OrderedDict'>
state_dict = {k: v for k, v in your_model.state_dict().items()}
torch.save(state_dict, 'path/to/file.pth')
or just
dict(your_model.state_dict())
Hi, @ankane, what do you think of noticing this issue in readme as it is widespread with libtorch and we aren't able to fix it.
Thanks @orlando-labs, it works!
Thanks @007lva and @orlando-labs . Added a note to the readme to address both https://github.com/pytorch/pytorch/issues/37213 and https://github.com/pytorch/pytorch/issues/42651.
Following the response from @orlando-labs, I am doing this to save my models now in python when I plan to load them in R.
torch.save(dict(model.to(device='cpu').state_dict()), path2weights)
Hello, I've got this error when try to load my model:
I've tried also pointing to the current master branch with the hope that changes from #18 fixes it but still get the same error. This model was generated with Python, Pytorch 10.1 and Cuda 10.1, I've tried with more versions but still can't get it working