-
之前的电脑上为了安装gpu版本的TensorFlow安装了cuDNN7.6.5+CUDA10.1,所以Pytorch的版本选择了cuda10.1对应的1.8.1
cuDNN7.6.5+CUDA10.1安装:https://blog.csdn.net/qq_42283621/article/details/124095937 -
使用Anaconda安装pytorch
conda create -n py37torch python=3.7
conda activate py37torch
pip install torch==1.8.1+cu101 torchvision==0.9.1+cu101 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html
如果安装cpu版本,可以不安装cuda和cudnn,直接使用命令conda install pytorch torchvision torchaudio cpuonly -c pytorch安装即可
- List item
测试是否安装成功
import torch
print("torch版本号:",end="")
print(torch.__version__)
print("判断torch是否可用:",end="")
print(torch.cuda.is_available())
print("gpu数量:",end="")
print(torch.cuda.device_count())
print("gpu名字,设备索引默认从0开始:",end="")
print(torch.cuda.get_device_name(0))
print("现在正在使用的GPU编号:",end="")
print(torch.cuda.current_device())
可以看到它发现了机器上的1050显卡,也就是安装成功了