Ubuntu19.04下Anaconda4.7.10+cuda10.1+cuDNN7.6.2+tensorflow2.0+pytorch1.1深度学习环境配置总结

安装的前提是你已经安装好显卡驱动,如果没有安装好,丢个传送门关于ubuntu19.04下安装独立显卡驱动

安装Anaconda4.7.10

先去anaconda官网下载,这里选择则64-Bit (x86) Installer

然后在下载目录打开终端,输入

bash Anaconda3-2019.07-Linux-x86_64.sh

 之后会出现协议,这里不用管,一直Enter到结束,之后出现

Do you approve the license terms? [yes|no]

 输入yes即可,再之后会出现

Anaconda3 will now be installed into this location:
/home/meteorrain/anaconda3
​
  - Press ENTER to confirm the location
  - Press CTRL-C to abort the installation
  - Or specify a different location below
​
[/home/meteorrain/anaconda3] >>>

就是选择安装的位置,看个人喜好,我是比较懒,直接默认安装了,然后.....就装完了(」゜ロ゜)」
并没有出现是否添加到path的选项....但是我后来查看确实在路径中,可能是默认添加了= =,或者说你选择默认安装,就会自动添加路径?....不管了,进行下一步,更新系统文件

source ~/.bashrc

然后输入如下命令

conda --version

显示

conda 4.7.10

 则表示安装成功了~~

 

安装cuda10.1

不需要g++降级,去cuda官网直接下载相应的版本即可,由于暂时没有19.04的,所以我下载的18.10,其实也没多大影响,最近几代ubuntu的兼容性很好
然后就是补库(我没有测试这些库是否有用,但是为了省事,就都装上了~)

sudo apt-get install freeglut3-dev libx11-dev libxmu-dev libxi-dev libgl1-mesa-glx libglu1-mesa libglu1-mesa-dev

然后再输入

sudo chmod 777 cuda_10.1.168_418.67_linux.run
./cuda_10.1.168_418.67_linux.run

安装程序第一个输入accept,第二个直接选择install,然后等待安装完成即可~再编辑一下这个文件

sudo vi ~/.bashrc

在文件末尾加上这几行

export CUDA_HOME=/usr/local/cuda
export PATH=$PATH:$CUDA_HOME/bin
export LD_LIBRARY_PATH=/usr/local/cuda-10.1/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

输入:wq保存并退出,然后输入如下命令进行更新

source ~/.bashrc

以下命令是用来测试cuda是否配置成功的

输入

cat /proc/driver/nvidia/version

输出

NVRM version: NVIDIA UNIX x86_64 Kernel Module  418.67  Sat Apr  6 03:07:24 CDT 2019
GCC version:  gcc version 8.3.0 (Ubuntu 8.3.0-6ubuntu1)

输入

nvcc -V

输出

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Wed_Apr_24_19:10:27_PDT_2019
Cuda compilation tools, release 10.1, V10.1.168

安装cudnn7.6.2

安装,你将会看到和如下相似的结cudnn的版本一定要根据cuda的版本进行选择,官网传送门,下载cudnn还必须注册账号,以及填写一些信息,这些就随意啦~
网上搜索的安装cudnn感觉好麻烦,这里就是下载的问题了,有人建议下载cuDNN Library for Linux,然后安装过程大概有五条命令的样子(这里就不贴出来了),我选择的是下载deb安装包,这里有两种安装包, cuDNN Runtime Library for Ubuntu18.04 (Deb)以及cuDNN Developer Library for Ubuntu18.04 (Deb)(由于没有针对19.04版本的所以下载的18.04版本),请下载Runtime的,因为Runtime是基本运行库,Developer是依赖于Runtime针对有兴趣开发cuDNN的人的库,所以我们只需要下载Runtime就可以了,下载完成后输入命令

sudo dpkg -i libcudnn7_7.6.2.24-1+cuda10.1_amd64.deb

然后等待安装完成就可以啦~

这里补充一下,请不要使用如下命令验证是否安装成功

cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2

因为安装方式不同,验证方法也是不一样的,因为使用deb文件安装,所以在/usr/local/cuda/include目录下根本没有cudnn.h这个文件,正确的验证方式在官网上介绍得很清楚, 传送门,当然,这里要先安装一下测试样例

sudo dpkg -i libcudnn7-doc_7.6.2.24-1+cuda10.1_amd64.deb

 我把官网的验证操作搬运过来

Copy the cuDNN sample to a writable path.(这一步是必须的,因为如果你直接cd到cudnn_samples_v7里执行make操作会没有权限)

$cp -r /usr/src/cudnn_samples_v7/ $HOME

Go to the writable path.

$ cd  $HOME/cudnn_samples_v7/mnistCUDNN

编译样例mnistCUDNN

$make clean && make

运行样例mnistCUDNN 

$ ./mnistCUDNN

如果cuDNN正确的安装,你将会看到和如下相似的结果:

cudnnGetVersion() : 7602 , CUDNN_VERSION from cudnn.h : 7602 (7.6.2)
Host compiler version : GCC 8.3.0
There are 1 CUDA capable devices on your machine :
device 0 : sms 68  Capabilities 7.5, SmClock 1545.0 Mhz, MemSize (Mb) 10986, MemClock 7000.0 Mhz, Ecc=0, boardGroupID=0
Using device 0

Testing single precision
Loading image data/one_28x28.pgm
Performing forward propagation ...
Testing cudnnGetConvolutionForwardAlgorithm ...
Fastest algorithm is Algo 0
Testing cudnnFindConvolutionForwardAlgorithm ...
^^^^ CUDNN_STATUS_SUCCESS for Algo 0: 0.016480 time requiring 0 memory
^^^^ CUDNN_STATUS_SUCCESS for Algo 2: 0.030816 time requiring 57600 memory
^^^^ CUDNN_STATUS_SUCCESS for Algo 1: 0.042144 time requiring 3464 memory
^^^^ CUDNN_STATUS_SUCCESS for Algo 5: 0.047840 time requiring 203008 memory
^^^^ CUDNN_STATUS_SUCCESS for Algo 7: 0.057280 time requiring 2057744 memory
Resulting weights from Softmax:
0.0000000 0.9999399 0.0000000 0.0000000 0.0000561 0.0000000 0.0000012 0.0000017 0.0000010 0.0000000 
Loading image data/three_28x28.pgm
Performing forward propagation ...
Resulting weights from Softmax:
0.0000000 0.0000000 0.0000000 0.9999288 0.0000000 0.0000711 0.0000000 0.0000000 0.0000000 0.0000000 
Loading image data/five_28x28.pgm
Performing forward propagation ...
Resulting weights from Softmax:
0.0000000 0.0000008 0.0000000 0.0000002 0.0000000 0.9999820 0.0000154 0.0000000 0.0000012 0.0000006 

Result of classification: 1 3 5

Test passed!

Testing half precision (math in single precision)
Loading image data/one_28x28.pgm
Performing forward propagation ...
Testing cudnnGetConvolutionForwardAlgorithm ...
Fastest algorithm is Algo 0
Testing cudnnFindConvolutionForwardAlgorithm ...
^^^^ CUDNN_STATUS_SUCCESS for Algo 0: 0.014784 time requiring 0 memory
^^^^ CUDNN_STATUS_SUCCESS for Algo 2: 0.014976 time requiring 28800 memory
^^^^ CUDNN_STATUS_SUCCESS for Algo 1: 0.034816 time requiring 3464 memory
^^^^ CUDNN_STATUS_SUCCESS for Algo 7: 0.042080 time requiring 2057744 memory
^^^^ CUDNN_STATUS_SUCCESS for Algo 5: 0.044000 time requiring 203008 memory
Resulting weights from Softmax:
0.0000001 1.0000000 0.0000001 0.0000000 0.0000563 0.0000001 0.0000012 0.0000017 0.0000010 0.0000001 
Loading image data/three_28x28.pgm
Performing forward propagation ...
Resulting weights from Softmax:
0.0000000 0.0000000 0.0000000 1.0000000 0.0000000 0.0000714 0.0000000 0.0000000 0.0000000 0.0000000 
Loading image data/five_28x28.pgm
Performing forward propagation ...
Resulting weights from Softmax:
0.0000000 0.0000008 0.0000000 0.0000002 0.0000000 1.0000000 0.0000154 0.0000000 0.0000012 0.0000006 

Result of classification: 1 3 5

Test passed!

至此,cuDNN成功安装~

安装Tensorflow2.0

emmmm,装这个是最简单的,如果上面装的都和我一样的话,下面的也请跟我装的一样,alpha0版本我测试过似乎有问题= =

pip3 install tensorflow-gpu==2.0.0-beta1

进入python3环境,然后输入

import tensorflow as tf

这里有可能会出现这个警告

/home/meteorrain/.local/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:516: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
/home/meteorrain/.local/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:517: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
/home/meteorrain/.local/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:518: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
/home/meteorrain/.local/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:519: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
/home/meteorrain/.local/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:520: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
/home/meteorrain/.local/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:525: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])
/home/meteorrain/.local/lib/python3.7/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:541: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
/home/meteorrain/.local/lib/python3.7/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:542: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
/home/meteorrain/.local/lib/python3.7/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:543: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
/home/meteorrain/.local/lib/python3.7/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:544: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
/home/meteorrain/.local/lib/python3.7/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:545: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
/home/meteorrain/.local/lib/python3.7/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:550: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])

可以无视掉,因为官网的实例中也有,而且这个只是warning不是error,只是告诉你,这样写不太合适,究其原因是numpy版本的问题,如果想不显示,就将numpy版本降级,网上有方法不再赘述,这里我选择放着不管(官方都不怕,咱们怕啥(๑•́ ₃•̀๑))

然后输入

tf.__version__

如果输出

'2.0.0-beta1'

就表示,安装成功了~

安装Pytorch

首先在pytorch官网选择自己的环境,python的版本,cuda的版本,以及安装的方式啥的,然后官网会自动生成一个安装命令,将其复制到终端执行即可,不过我安装的时候没有cuda10.1的选项,于是乎,我自己手动修改了其中的版本号,输入了如下命令:

conda install pytorch torchvision cudatoolkit=10.1 -c pytorch

当然也是没有问题的,最后测试以下是否安装成功,在python3环境下输入

import torch

没有报错的话就是安装成功啦~

创建anaconda的虚拟环境

利用anaconda创建虚拟环境很方便~尤其是在需要多种不同版本的扩展库运行不同的程序时,命令如下:

conda create --name exp python=3.7.3

exp是自己定义的环境名称,后面的3.7.3是python的版本,然后会安装一些库,安装完成后,输入

source activate exp

即可进入虚拟环境进行操作,下面是一些简单的Anaconda指令

创建环境  conda create -n environment_name python=3
删除环境  conda env remove -n environment_name
激活环境  source activate environment_name  /conda activate environment_name
退出环境  conda deactivate

安装包           conda install package
查看已安装包      conda list
更新包           conda update package
移除包           conda remove package

觉得文章还不错有帮助的童鞋还请点个赞支持一下~( •̀∀•́ )(虽然没有任何收益,但是博主会很开心~)

  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 10
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值