問題一
ImportError: No module named torchvision
torchvison:圖片、視頻數據和深度學習模型
解決方案
安裝torchvision,參照官網
問題二
安裝torchvision過程中遇到 Could not find a version that satisfies the requirement olefile (from pillow->torchvision==0.1.8)
沒有olefile
解決方案
安裝olfile,官網
問題三
找不到nn.init模塊
具體錯誤內容 'module' object has no attribute 'init'
解決方案
找到以下目錄torch/nn, 此目錄下有init.py和__init__.py文件,打開__init__.py文件看到以下內容:
- from .modules import *
- from .parameter import Parameter
- from .parallel import DataParallel
在代碼的最后加上以下語句
- from .init import *
保存並退出,重新運行即可
問題四:torch not compiled with cuda enabled
解決方案
最好根據github上的教程,進行源安裝:網址:https://github.com/pytorch/pytorch
安裝好之后進行測試:a = torch.ones(1,1)
print a.cuda() 有結果,說明安裝成功,需要torchvision,那么conda install torchvision -c soumith提示安裝pytorch(cuda)和torchvision,選擇yes的話,基本上失敗,下載pytorch太慢! 如果conda install torchvision選擇yes的話,之后再import torch是會報錯:Undefined symbol:THLongStorage_inferSizeN.(不知道什么原因,果斷選擇避坑)。
安裝torchvision:去官網下載離線包:.whl格式,之后在終端pip install 這個格式的包