Pytorch/TensorFlow/Paddle深度学习框架安装(GPU版本)

Pytorch/TensorFlow/Paddle深度学习框架安装(GPU版本)

一、简介

       Pytorch、TensorFlow都是著名的深度学习平台,Paddle也是。Pytorch、TensorFlow很显然在国内外都很受欢迎的,学习难度是TensorFlow大于Pytorch,随着TensorFlow的发展趋势,现在学习难度已经大大降低了很多,逐渐与Pytorch持平,Pytorch、TensorFlow各有千秋,任选一个学习都没问题。这里提一提的是TensorFlow1.x版本和TensorFlow2.x的版本许多API变动很大,因此在前者环境下写的程序在后者环境下运行一般都报错,它的高版本不向下兼容。
       Paddle是由国内的百度公司推出的开源深度学习框架,符合国人的使用习惯和阅读理解,因此相关的学习文档会很容易入门。如果是零基础学习深度学习,那么Paddle是很适合的,只要了解并入门Paddle,那么Pytorch、TensorFlow也会间接掌握了解,这是因为这三者在不少API方面极其相似,相应的神经网络模型设计、优化器、数据处理方法都颇有异曲同工之妙。至于在生产实践中哪个较为好用,尚待考究。。。而且在学习Paddle的过程中百度公司提供了一系列的工具和资源来助力,比如云计算平台AI Studio、免费的视频教程讲解、更高级的API封装等等。

网页教程文档
1、Pytorch

https://pytorch.org/

2、TensorFlow

https://tensorflow.google.cn/

3、Paddle

https://www.paddlepaddle.org.cn/

二、下面来开始安装以上的深度学习框架库到python环境中
       因为毕设的原因我安装了这三种深度学习框架库的GPU版本,安装GPU要求电脑具备英伟达NVIDIA独立显卡,AMD独立显卡不可以。如果没有NVIDIA独立显卡,只能安装CPU版本。为什么需要安装GPU版本的深度学习框架库?因为深度学习的各种神经网络模型训练,涉及到非常庞大的数据量计算,而显卡擅长大数据运算,CPU擅长复杂指令运算。

用到的软件工具

链接:https://pan.xunlei.com/s/VMYY8bSYSySzZSgioyWC4QgYA1
提取码:ipye

在这里插入图片描述

1、Pycharm
编写Python程序的集成开发工具IDE
2、Anaconda
       Anaconda支持图形界面操作和命令行操作,这里建议使用命令行方式操作。主要用于创建多个Python虚拟环境,安装Anaconda前如果电脑已经安装了Python环境A,那么安装Anaconda完后,电脑会有两个Python环境,一个是电脑先前安装的Python环境A,第二个是Anaconda自带的Python环境(base,Python==3.8)
       后面会介绍这两个环境在深度学习中不会常用到,需要新建第三个第四个,以此类推至多个Python虚拟环境来使用。Anaconda就具备创建多Python虚拟环境的功能。在新建的虚拟环境下安装所用到的Python库。
在这里插入图片描述
       如果C盘空间不吃紧,建议Pycharm、Anaconda都安装到C盘目录下,即默认安装。安装GPU版的Pytorch大约会占用4-6GB硬盘空间,多是驱动文件占用空间大,且安装时间长,需要耐心等待。
安装CPU版占用空间几百MB,但会失去了GPU强劲的计算能力,具备NVIDIA GPU建议安装GPU版本。C盘空间实在不够用,Pycharm、Anaconda安装到其他盘符下原则上是没问题的。

3、安装NVIDIA CUDA工具包和加速计算库cudnn
安装完Anaconda,打开电脑菜单界面找到Anaconda Prompt(anaconda3),

3.1、设置Anaconda镜像源为中科大源

conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/menpo/
conda config --set show_channel_urls yes

在这里插入图片描述
重复添加相同源警告
在这里插入图片描述

3.2、安装Pytorch/TensorFlow/PaddleCPU版
如果以上步骤做完,没有NVIDIA独立显卡,那么打开此链接https://blog.csdn.net/QuanSirX/article/details/115829442安装CPU版本。

安装GPU版的继续往下看。

3.3、安装Pytorch/TensorFlow/PaddleGPU版
#创建一个名为tensorflow_gpu的python虚拟环境

conda create -n tensorflow_gpu python=3.7

输入y确认安装
在这里插入图片描述

#激活某一个Anaconda下的Python虚拟环境

conda activate tensorflow_gpu

在这里插入图片描述

      安装NVIDIA CUDA工具包和加速计算库cudnn,在之前CUDA工具包和加速计算库cudnn需要到英伟达官网下载并安装,步骤相对繁琐。
由于新版本的Anaconda和镜像源的支持,现已支持在Anaconda命令行中直接安装NVIDIA CUDA工具包和加速计算库cudnn。
     首先需要确认的是电脑显卡最高所能支持的CUDA版本,支持的CUDA版本低,则不能安装高版本的CUDA工具包和加速计算库cudnn。支持的CUDA版本高,能安装当前版本以下的所有版本CUDA工具包和加速计算库cudnn。查看电脑NVIDIA显卡当前驱动程序所支持的CUDA版本,在Windows桌面下鼠标右击,选中NVIDIA控制面板,点击打开控制面板左下角的系统信息,点击‘显示’右边的‘组件’,看到NVCUDA64.DLL属性信息 CUDA后面的 ‘11.3.70’ 即为NVIDIA显卡当前驱动程序所支持的最高CUDA版本。
在这里插入图片描述
在这里插入图片描述

      CUDA工具包版本需要和加速计算库cudnn版本相对应,比如CUDA11.0对应的cudnn版本不能低于8.0。打开https://developer.nvidia.com/rdp/cudnn-archive链接就可以查询cudnn和哪个CUDA版本匹配。
在这里插入图片描述

3.4、安装NVIDIA CUDA工具包和加速计算库cudnn

#查询镜像源下的cuda版本信息

conda search cuda

#查询镜像源下的cudnn版本信息

conda search cudnn

#查询镜像源下的tensorflow-gpu版本信息

conda search tensorflow-gpu

在这里插入图片描述

3.4.1
#安装CUDA工具包
conda install cudatoolkit=10.1
在这里插入图片描述
输入y确认安装

###安装cudnn加速计算库
conda install cudnn=7.6.5
在这里插入图片描述
输入y确认安装

3.4.2
###安装CUDA工具包
conda install cudatoolkit=10.1
###安装cudnn加速计算库
conda install cudnn=7.6.5

前面已安装

###安装TensorFlow-GPU库,用pip方式安装

pip install tensorflow-gpu==2.3.1 -i https://pypi.tuna.tsinghua.edu.cn/simple

在这里插入图片描述

#验证TensorFlow-GPU库是否安装成功

conda activate tensorflow_gpu
python
import tensorflow as tf
print(tf.__version__)
print(tf.config.list_physical_devices('GPU'))
exit()#退出python环境

在这里插入图片描述

3.4.3安装Paddle-GPU版本,用pip方式安装
#创建、激活虚拟环境

conda create -n paddle_gpu python=3.7
conda activate paddle_gpu

#安装CUDA工具包、cudnn加速计算库

conda install cudatoolkit=10.1
conda install cudnn=7.6.5

在这里插入图片描述

#安装Paddle-GPU库

python -m pip install paddlepaddle-gpu==2.0.2.post100 -f https://paddlepaddle.org.cn/whl/mkl/stable.html

#验证Paddle-GPU库是否安装成功

conda activate paddle_gpu
python
import paddle
print(paddle.__version__)
print(paddle.fluid.install_check.run_check())
exit()

在这里插入图片描述

3.4.3安装pytorch-gpu版本,用conda方式安装

#创建、激活虚拟环境

conda create -n pytorch_gpu python=3.7
conda activate pytorch_gpu

#安装CUDA工具包、cudnn加速计算库

conda install cudatoolkit=10.1
conda install cudnn=7.6.5

在这里插入图片描述

#安装Pytorch-GPU库

conda install pytorch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2 -c pytorch

在这里插入图片描述

###验证pytorch-gpu库是否安装成功

conda activate pytorch_gpu
python
import torch
print(torch.version.cuda)
print(torch.cuda.is_available())
print(torch.cuda.get_device_name())
exit()

在这里插入图片描述

4、安装步骤汇总

Paddle-GPU版本安装汇总:

#设置Anaconda镜像源为中科大源
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/menpo/
conda config --set show_channel_urls yes
#创建、激活虚拟环境
conda create -n paddle_gpu python=3.7
conda activate paddle_gpu
###安装CUDA工具包、cudnn加速计算库
conda install cudatoolkit=10.1
conda install cudnn=7.6.5
#安装Paddle-GPU库
python -m pip install paddlepaddle-gpu==2.0.2.post100 -f https://paddlepaddle.org.cn/whl/mkl/stable.html
#验证Paddle-GPU库是否安装成功
conda activate paddle_gpu
python
import paddle
print(paddle.fluid.install_check.run_check())
exit()

TensorFlow-GPU版本安装汇总:

#设置Anaconda镜像源为中科大源
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/menpo/
conda config --set show_channel_urls yes
#创建、激活虚拟环境
conda create -n tensorflow_gpu python=3.7
conda activate tensorflow_gpu
#安装CUDA工具包、cudnn加速计算库
conda install cudatoolkit=10.1
conda install cudnn=7.6.5
#安装TensorFlow-GPU库
pip install tensorflow-gpu==2.3.1 -i https://pypi.tuna.tsinghua.edu.cn/simple
#验证TensorFlow-GPU库是否安装成功
conda activate tensorflow_gpu
python
import tensorflow as tf
print(tf.__version__)
print(tf.config.list_physical_devices('GPU'))

Pytorch-GPU版本安装汇总:

#设置Anaconda镜像源为中科大源
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/menpo/
conda config --set show_channel_urls yes
#创建、激活虚拟环境
conda create -n pytorch_gpu python=3.7
conda activate pytorch_gpu
#安装CUDA工具包、cudnn加速计算库
conda install cudatoolkit=10.1
conda install cudnn=7.6.5
#安装Pytorch-GPU库
conda install pytorch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2 -c pytorch
#验证Pytorch-GPU库是否安装成功
conda activate pytorch_gpu
python
import torch
print(torch.version.cuda)
print(torch.cuda.is_available())
print(torch.cuda.get_device_name())

三、Anaconda其他常用命令

1、删除环境

conda remove -n 环境名称 --all

当tensorflow_gpu环境不再需要使用,可用如下命令删除环境

conda remove -n tensorflow_gpu --all

2、清除conda缓存的资源文件

&nbspconda下载的各种驱动程序、库文件安装后会缓存在本地磁盘,文件数量过多后会占用一定磁盘空间,可用clean命令删除不用的缓存文件。

conda clean -p

输入y确认删除

conda clean -a

输入y确认删除

在这里插入图片描述
四、Pycharm项目使用conda安装的Python虚拟环境

1、打开或新建一个Pycharm项目

在这里插入图片描述

2、按下图操作修改Pycharm项目的Python编译器,改为conda新建的pytorch_gpu
2.1、
在这里插入图片描述
2.2、
在这里插入图片描述
2.3、
在这里插入图片描述
2.4、
在这里插入图片描述
2.5、
在这里插入图片描述
2.6、
在这里插入图片描述
2.7、
在这里插入图片描述
2.8、
在这里插入图片描述

2.9、
在这里插入图片描述
Bilibili视频教程:
Pytorch/TensorFlow/Paddle深度学习框架安装

  • 10
    点赞
  • 49
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

QuanSirX

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值