使用pytorch的错误整理

1、Using /home/liao/.cache/torch_extensions/py38_cu102 as PyTorch extensions root…

程序卡在Using /home/liao/.cache/torch_extensions/py38_cu102 as PyTorch extensions root…

无法运行下去:

解决方法:在/home/liao/.cache下删除torch_extensions文件夹。

原因:之前运行pytorch时,不正常退出,导致的进程问题。

2、AttributeError: ‘collections.OrderedDict’ object has no attribute ‘training’

如果保存时torch.save(model.state_dict(),“model_test.pth”)

加载时model=torch.load(‘./model_test.pth’)

torch.onnx.export就会报这个错误。

解决方法:

保存时torch.save(model.state_dict(),“model_test.pth”)

加载时model.load_state_dict(torch.load(‘./model_test.pth’))

然后torch.onnx.export

或者

保存时torch.save(model,“model_test.pth”)

加载时model=torch.load(‘./model_test.pth’)

然后torch.onnx.export

同样如果保存时torch.save(model,“model_test.pth”)

加载时model.load_state_dict(torch.load(‘./model_test.pth’))

torch.onnx.export就会报这个错误。

TypeError: Expected state_dict to be dict-like, got .

3、torch和torchvision的版本需要匹配,否则在使用中,会报两者不匹配的错误。

是否匹配查看:torch的GitHub网站。

卸载torchvision:pip3 uninstall torchvision

重新安装:

在这里下载:https://download.pytorch.org/whl/torch_stable.html指定版本的whl

cu102:表示cuda版本为10.2,

torch-1.7.1:表示torch版本为1.7.1

cp38:表示适用python版本为3.8

linux:表示适用于linux系统

x86_64:表示同时兼容32和64位系统

然后pip3 install .whl的路径

本文来自网络,不代表协通编程立场,如若转载,请注明出处:https://net2asp.com/3e1d4ef5fb.html