日萌社
人工智能AI:Keras PyTorch MXNet TensorFlow PaddlePaddle 深度学习实战(不定时更新)
Ubuntu 安装 CUDA、cuDNN、anaconda、pycharm、tensorflow、pytorch、JDK1.8
pytorch gpu 安装
1.官网下载安装:https://pytorch.org/get-started/locally/
安装命令:conda install pytorch torchvision cudatoolkit=10.1 -c pytorch
2.国内源直接下载链接
网站链接:
window:https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/win-64/
linux:https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/linux-64/
选择下载:
window:pytorch-1.5.0-py3.7_cpu_0.tar.bz2
linux:pytorch-1.5.0-py3.7_cuda10.1.243_cudnn7.6.3_0.tar.bz2
下载链接:
window:https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/win-64/pytorch-1.5.0-py3.7_cpu_0.tar.bz2
linux:https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/linux-64/pytorch-1.5.0-py3.7_cuda10.1.243_cudnn7.6.3_0.tar.bz2
安装:
window:conda install pytorch-1.5.0-py3.7_cpu_0.tar.bz2
linux:conda install pytorch-1.5.0-py3.7_cuda10.1.243_cudnn7.6.3_0.tar.bz2
pip list
torch 1.5.0
3.测试GPU版本的代码
import torch
#测试 CUDA
print("Support CUDA ?: ", torch.cuda.is_available()) #返回True
x = torch.tensor([10.0])
x = x.cuda()
print(x)
y = torch.randn(2, 3)
y = y.cuda()
print(y)
z = x + y
print(z)
# 测试 CUDNN
from torch.backends import cudnn
print("Support cudnn ?: ",cudnn.is_acceptable(x)) #返回True
1.官网下载安装:https://pytorch.org/get-started/locally/
2.执行命令:conda install pytorch torchvision cudatoolkit=10.1 -c pytorch
3.比如我的是CUDA 10.0的话,需要到https://pytorch.org/get-started/previous-versions/选择其他PyTorch版本
执行命令:conda install pytorch==1.2.0 torchvision==0.4.0 cudatoolkit=10.0 -c pytorch
4.添加 清华源 下载
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 --set show_channel_urls yes
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
5.国内下载
https://download.pytorch.org/whl/torch_stable.html
4.测试GPU版本的代码
import torch
if __name__ == '__main__':
#测试 CUDA
print("Support CUDA ?: ", torch.cuda.is_available())
x = torch.tensor([10.0])
x = x.cuda()
print(x)
y = torch.randn(2, 3)
y = y.cuda()
print(y)
z = x + y
print(z)
# 测试 CUDNN
from torch.backends import cudnn
print("Support cudnn ?: ",cudnn.is_acceptable(x))
Pytorch的安装
目标
- 知道如何安装pytorch
1. Pytorch的介绍
Pytorch是一款facebook发布的深度学习框架,由其易用性,友好性,深受广大用户青睐。
2. Pytorch的版本
3. Pytorch的安装
安装地址介绍:https://pytorch.org/get-started/locally/
安装步骤:
pip3 install torch torchvision
安装之后打开ipython
输入:
In [1]:import torch
In [2]: torch.__version__
Out[2]: '1.3.1'
注意:代码中都是使用torch