安装pytorch前一定查好cuda与torch的对应版本号, torch和torchvision对应版本鸭!!!
(py3.8+torch1.8) administrator@delltwo:~/storage2/xxy/project/pkgs$ pip install torch-1.8.0+cu101-cp38-cp38-linux_x86_64.whl Processing ./torch-1.8.0+cu101-cp38-cp38-linux_x86_64.whl
Requirement already satisfied: typing-extensions in /home/administrator/anaconda3/envs/py3.8+torch1.8/lib/python3.8/site-packages (from torch==1.8.0+cu101) (3.10.0.0)
Requirement already satisfied: numpy in /home/administrator/anaconda3/envs/py3.8+torch1.8/lib/python3.8/site-packages (from torch==1.8.0+cu101) (1.21.0)
Installing collected packages: torch
Successfully installed torch-1.8.0+cu101
(py3.8+torch1.8) administrator@delltwo:~/storage2/xxy/project/pkgs$ python
Python 3.8.8 (default, Apr 13 2021, 19:58:26)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> torch.__version__
'1.8.0+cu101'
>>> torch.cuda.is_aa vail
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'torch.cuda' has no attribute 'is_a'
>>> torch.cuda.is_available()
True
>>>
(py3.8+torch1.8) administrator@delltwo:~/storage2/xxy/project/pkgs$ install torchvision-0.9.1+cu101-cp38-cp38-linux_x86_64.whl
install: missing destination file operand after 'torchvision-0.9.1+cu101-cp38-cp38-linux_x86_64.whl'
Try 'install --help' for more information.
(py3.8+torch1.8) administrator@delltwo:~/storage2/xxy/project/pkgs$ pip install torchvision-0.9.1+cu101-cp38-cp38-linux_x86_64.whl
Processing ./torchvision-0.9.1+cu101-cp38-cp38-linux_x86_64.whl
Collecting torch==1.8.1
Using cached torch-1.8.1-cp38-cp38-manylinux1_x86_64.whl (804.1 MB)
Requirement already satisfied: pillow>=4.1.1 in /home/administrator/anaconda3/envs/py3.8+torch1.8/lib/python3.8/site-packages (from torchvision==0.9.1+cu101) (8.2.0)
Requirement already satisfied: numpy in /home/administrator/anaconda3/envs/py3.8+torch1.8/lib/python3.8/site-packages (from torchvision==0.9.1+cu101) (1.21.0)
Requirement already satisfied: typing-extensions in /home/administrator/anaconda3/envs/py3.8+torch1.8/lib/python3.8/site-packages (from torch==1.8.1->torchvision==0.9.1+cu101) (3.10.0.0)
Installing collected packages: torch, torchvision
Attempting uninstall: torch
Found existing installation: torch 1.8.0+cu101
Uninstalling torch-1.8.0+cu101:
Successfully uninstalled torch-1.8.0+cu101
Successfully installed torch-1.8.1 torchvision-0.9.1+cu101
(py3.8+torch1.8) administrator@delltwo:~/storage2/xxy/project/pkgs$ python
Python 3.8.8 (default, Apr 13 2021, 19:58:26)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> torch.__version__
'1.8.1+cu102'
>>> torch.__version__>>> import torch >>> torch.cuda.is_available()>>> import torch
>>> torch.cuda.is_available()
/home/administrator/anaconda3/envs/py3.8+torch1.8/lib/python3.8/site-packages/torch/cuda/__init__.py:52: UserWarning: CUDA initialization: The NVIDIA driver on your system is too old (found version 10010). Please update your GPU driver by downloading and installing a new version from the URL: http://www.nvidia.com/Download/index.aspx Alternatively, go to: https://pytorch.org to install a PyTorch version that has been compiled with your version of the CUDA driver. (Triggered internally at /pytorch/c10/cuda/CUDAFunctions.cpp:109.)
return torch._C._cuda_getDeviceCount() > 0
False
>>>
torch和torchvision版本与cuda版本不配套导致
https://github.com/pytorch/vision#installation可查看torch和torchvision对应版本
可以看到torch1.8.0对应的torchvision是0.9.0,但是https://pytorch.org/get-started/previous-versions/pytorch官方
pytorch1.8.0版本不支持cuda10.1
所以需要降低torch版本