安裝gpu版本的pytorch需要三個東西:pytorch(torchvision)、cuda、cudnn
相信大家都安裝過了anaconda,就不介紹anaconda的安裝了
1.安裝cuda:從官網下載cuda,這里我使用的是cuda 9.0版本(10.0的不知道出於什么原因沒成功使用)
下載之后就是一鍵式操作,一直點next就好了
2.安裝cudnn:cudnn能夠進一步加速速度。因此推薦安裝。
從官網下載cudnn,但是要注冊一個賬號(很簡單的注冊)【注意cudnn與cuda有版本間的對應關系 對應cuda9.0版本的話使用的是7.4】
下載之后解壓並復制相應文件夾的內容到 C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0
添加環境變量:C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\lib\x64
3.更改鏡像:因為官網的速度實在太慢太慢了
添加清華鏡像
1 conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
2 conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
3 conda config --set show_channel_urls yes
添加pytorch鏡像
1 conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
4.安裝pytorch:從官網獲得conda指令 :conda install pytorch torchvision cudatoolkit=9.0 因為修改了鏡像,所以去掉了官網的給的地址(-c pytorch)
5.驗證是否安裝成功:
1 import torch 2 torch.cuda.is_available()
如果是True恭喜你啦!
6.感謝我之前看過的教程: