I meet a problem about loading model. The IDE raise “UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xc3 in position 918: ordinal not in range(128)” error when I use model = torch.load(“file.pth”)
(ps: the .pth file comes from somewhere, and it was not trained by myself. The pth file trained by myself can be loaded using torch.load) .
Thanks for helps!!
@Eric_K Hello I have the same problem. I am using anaconda pytorch 0.3.1.post2 in python 3.6 with cuda8.0 . Have you figuring out how to solve this problem?
Someone told me the most possible reason is the version of python. Maybe the model is saved in python 2 that lead to your error. But I haven’t implement it.
Someone told me the most possible reason is that the version of python…
邮箱:pengbo18555@163.com
签名由 网易邮箱大师 定制
I see man. That makes sense. Have you explored possiblity to convert that to pytorch python 3?
I also make it as issues in pytorch github here. I hope it can solve soon.
Because it’s not the main problem that bother me. I haven’t figure out how to convert it…I will focus on your issues in pytorch github. Thank you~
The same error happens to me.
What happens in my case is that, the model is saved as a ‘DataParallel’ object with python 2.
I solved it by loading the model with torch.load() in python 2. I then extracted the state_dict and saved it as a dictionary using torch.save. The dictionary then can be loaded with python 3 with no error.
In python 2,
saved = torch.load(fpath)
saved_sd = saved.state_dict()
output = {'arch': 'resnet18',\
'state_dict': saved_sd}
torch.save(output, newpath)
In python 3,
torch.load(newpath)