pytorch的安装
1. 安装了anaconda
2. conda切换为清华镜像源提高下载速度
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
conda config --set show_channel_urls yes
3. 明确自己计算机的cuda的版本,然后对应https://pytorch.org/get-started/previous-versions/找到合适的pytorch版本下载命令,
# CUDA 10.0
conda install pytorch1.0.0 torchvision0.2.1 cuda100 -c pytorch
表示,cuda版本为10.0,其对应的pytorch版本为1.0.0.下载命令见上。
注意:conda切换为国内镜像时,下载命令为conda install pytorch1.0.0 torchvision0.2.1 cuda100
注意:去掉末尾的-c pytorch。来提高下载速度
4. 验证是否安装成功torch。
From the command line, type:
python
then enter the following code:
import torch
x = torch.rand(5, 3)
print(x)
The output should be something similar to:
tensor([[0.3380, 0.3845, 0.3217],
[0.8337, 0.9050, 0.2650],
[0.2979, 0.7141, 0.9069],
[0.1449, 0.1132, 0.1375],
[0.4675, 0.3947, 0.1426]])
Additionally, to check if your GPU driver and CUDA is enabled and accessible by PyTorch, run the following commands to return whether or not the CUDA driver is enabled:
import torch
torch.cuda.is_available()
只有当返回值为True时候,才表明安装成功,否则就是cuda版本与pytorch版本之间不对应,需要重现进行安装。注意对应合适的python版本。