快速配置深度学习环境

Posted Neil-Yale

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了快速配置深度学习环境相关的知识,希望对你有一定的参考价值。

查看版本适配
https://blog.csdn.net/caiguanhong/article/details/112184290
https://tensorflow.google.cn/install/source

pytorch查看gpu
https://blog.csdn.net/nima1994/article/details/83001910
Import torch
torch.cuda.is_available()
cuda是否可用;

torch.cuda.device_count()
返回gpu数量;

torch.cuda.get_device_name(0)
返回gpu名字,设备索引默认从0开始;

torch.cuda.current_device()
返回当前设备索引;

tensorflow查看gpu
https://blog.csdn.net/u013538542/article/details/83830249
tf.test.is_gpu_available()

anaconda镜像站(换源用)
https://mirrors.bfsu.edu.cn/

pytorch安装gpu环境

先查看云环境提供的显卡驱动版本,然后根据版本选择合适的cuda,cudnn在虚拟环境中使用conda进行安装:conda install cudnn=8.1.0
tensorflow可以使用pip安装

gpu版本pytorch:conda install pytorch torchvision cudatoolkit

一定要注意显卡驱动版本、深度学习框架版本、cudnn,cuda,cudatoolkit之间的兼容关系:
https://www.jianshu.com/p/ac70300b598b
https://tensorflow.google.cn/install/source#gpu_support_3
https://blog.csdn.net/caiguanhong/article/details/112184290
https://www.cnblogs.com/Wanggcong/p/12625540.html

一个可以兼容的配置:
Pytorch 1.4.0
Tensorflow 2.3.0
Cuda 10.1
Cudnn 7.6.5
base环境装好的cuda等可以给虚拟环境用,虚拟环境也可以另装

驱动向下兼容,装高版本的驱动没错
我装的驱动版本是

但是装上低版本的torch依旧可以用gpu
https://pytorch.org/get-started/previous-versions/

此时可以再装个tf-gpu=1.12
https://blog.csdn.net/K1052176873/article/details/114526086
完美兼容

归纳:
1.base环境下的驱动,cudnn其实对虚拟环境中的torch,tf等影响不大;驱动版本向下兼容,所以建议驱动安装高版本
2.在高级版本中,同时兼容tf和torch调用gpu,我使用的版本的:
Torch=1.4.0
Tensorflow=2.3.0
兼容如图

低版本中使用的是:
Tensorflow-gpu=1.12.0,keras=2.2.4(https://blog.csdn.net/l641208111/article/details/117123397)torch=0.4.1
兼容如图

3.安装时,先在pytorch官网选择对应命令安装torch的gpu环境,然后测试gpu是否可用,接着根据安装torch时的cuda版本选择tf的版本,使用pip安装对应版本tf,此时测试如果不可用,再conda search cudnn,根据cuda版本找到合适的cudnn进行安装。完毕后,就得到了同时兼容的环境。以安装低版本的兼容环境为例,步骤如下
安装torch

安装tf

寻找合适的cudnn版本

确认安装

我的base环境如下

以上是关于快速配置深度学习环境的主要内容,如果未能解决你的问题,请参考以下文章

快速配置深度学习环境

远程服务器基于docker容器的深度学习环境配置(支持GPU)

构建docker环境能够运行自己的GPU服务,能够快速适应不同宿主机的GPU型号操作系统和驱动。linux版本nvidia驱动cudacudnn,docker+conda安装深度学习环境

物体检测快速入门系列-Windows部署Docker GPU深度学习开发环境

深度学习之30分钟快速入门PyTorch(附学习资源推荐)

小白入门深度学习 | 第一篇:配置深度学习环境