PyTorch 安装 GPU版本(CUDA/cuDNN)

日萌社

人工智能AI:Keras PyTorch MXNet TensorFlow PaddlePaddle 深度学习实战(不定时更新)


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的安装

目标

  1. 知道如何安装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

发布了450 篇原创文章 · 获赞 151 · 访问量 23万+

猜你喜欢

转载自blog.csdn.net/zimiao552147572/article/details/105416761