目录

澳门金沙国际 1

1.本课程对应的环境

system:ubuntu-16.04-desktop-amd64.iso
cuda:cuda_8.0.44_linux-16.04.run
cudnn:cudnn-8.0-linux-x64-v5.1.tgz
caffe:

设置显卡驱动

系统安装→软件和换代→附加驱动
选择使用NVIDIA binary driver - version 375.66 来自 nvidia-375
应用更改
安装到位后重启
在极端中输入nvidia-smi

  • 1.
    安装显卡驱动
  • 2.
    安装CUDA\CUDNN
  • 3.
    安装TensorFlow-gpu
  • 测试

  紧接着上一篇的稿子《纵深学习(TensorFlow)环境搭建:(二)Ubuntu16.04+1080Ti显卡驱动》,那篇文章,紧要教学怎么着设置CUDA+CUDNN,不过前提是大家是曾经把NVIDIA显卡驱动装置好了

2.安装Ubuntu-16.04

略。安装基本更新。

sudo apt-get update
sudo apt-get upgrade

CUDA

官网下载
PyTorch 0.3 支持 cuda9.0

澳门金沙国际 2

CUDA下载

运行
cuda8.0
sudo sh cuda_8.0.61_375.26_linux.run
cuda9.0
sudo sh cuda_9.0.176_384.81_linux.run

显卡驱动装置选用n
其余选取y

加上环境变量

sudo gedit /etc/profile

Centos配置深度学习开发条件,深度学习。最后添加
cuda8.0

export PATH=/usr/local/cuda-8.0/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64$LD_LIBRARY_PATH

cuda9.0

export PATH=/usr/local/cuda-9.0/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64$LD_LIBRARY_PATH

运行

source /etc/profile

测试

cd /usr/local/cuda-8.0/samples/1_Utilities/deviceQuery
sudo make
./deviceQuery

澳门金沙国际 3

设置成功

1. 装置显卡驱动

  • 检测显卡驱动及型号

$ sudo rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
  • 添加ELPepo源

$ sudo rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
  • 安装NVIDIA驱动检测

$ sudo yum install nvidia-detect
$ nvidia-detect -v

$ yum -y install kmod-nvidia

3.安装cuda-8.0

cuDNN

官网注册后下载
选择cuDNN5.1或者cuDNN6(TensorFlow 1.3需要cuDNN6.0),下载cuDNN后解压,

Download cuDNN v5.1 (Jan 20, 2017), for CUDA 8.0→cuDNN v5.1 Library for
Linux
Download cuDNN v6.0 (April 27, 2017), for CUDA 8.0→cuDNN v6.0 Library
for Linux
[Download cuDNN v7.0.5 (Dec 5, 2017), for CUDA 9.0]→cuDNN v7.0.5
Library for Linux

cuda8.0

sudo cp cuda/include/cudnn.h /usr/local/cuda-8.0/include
sudo cp cuda/lib64/libcudnn* /usr/local/cuda-8.0/lib64
sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda-8.0/lib64/libcudnn*

cuda9.0

sudo cp cuda/include/cudnn.h /usr/local/cuda-9.0/include
sudo cp cuda/lib64/libcudnn* /usr/local/cuda-9.0/lib64
sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda-9.0/lib64/libcudnn*

2. 安装CUDA\CUDNN

一、安装CUDA

  CUDA(Compute Unified Device
Architecture),是英特尔公司生产的一种基于新的并行编程模型和指令集架构的通用统计架构,它能应用英特尔GPU的并行计算引擎,比CPU更快速的化解广大犬牙交错统计职务,想使用GPU就必须求使用CUDA。

3.1 安装显卡驱动

sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt-get update
sudo apt-get install nvidia-367

澳门金沙国际 4

重启系统,使新驱动生效。使用AMD-smi测试是还是不是安装成功。
澳门金沙国际 5

参考资料

Ubuntu 16.04 CUDA 8 cuDNN
5.1安装

2.1 cuda

  • 官网下载cuda,最好下载9.0本子:
  • 选用符合自己机器的安装,拔取runfile(local)下载到centos中:
    澳门金沙国际 6
  • 需求下载所有补丁,下载后装置cuda:

$ sudo sh cuda_9.0.176_384.81_linux.run
  • 测试cuda是不是安装

$ cd /usr/local/cuda/samples/1_Utilities/deviceQuery
$ sudo make
$ ./deviceQuery

结果:
澳门金沙国际 7

澳门金沙国际,1.1、下载CUDA

  首先在官网()下载对应的CUDA,如图所示:

澳门金沙国际 8

注意请务必下载runfile文件(后缀为.run),无法是任何文件。要么直接通过wget命令下载:

wget https://developer.nvidia.com/compute/cuda/8.0/Prod2/local_installers/cuda_8.0.61_375.26_linux-run

 如图所示:

澳门金沙国际 9

3.2 安装cuda-Toolkit

2.2 cudnn

  • 下载cudnn文件,要求注册账号。
  • 设置下载好的cuDNN安装包,尽管你安装cuda的目录为默许目录,就足以直接选用如下指令安装:

tar -xvf cudnn-9.0-linux-x64-v7.1.tgz -C /usr/local/

1.2、安装CUDA(一定要按梯次执行)

  下载已毕后先实施安装相关重视的授命,如果不先执行安装信赖包,后边安装CUDA会以下错误报错:

-------------------------------------------------------------
Do you accept the previously read EULA?
accept/decline/quit: accept

Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 375.26?
(y)es/(n)o/(q)uit: n

Install the CUDA 8.0 Toolkit?
(y)es/(n)o/(q)uit: y

Enter Toolkit Location
 [ default is /usr/local/cuda-8.0 ]: 

Do you want to install a symbolic link at /usr/local/cuda?
(y)es/(n)o/(q)uit: y

Install the CUDA 8.0 Samples?
(y)es/(n)o/(q)uit: y

Enter CUDA Samples Location
 [ default is /home/cmfchina ]: 

Installing the CUDA Toolkit in /usr/local/cuda-8.0 ...
Missing recommended library: libGLU.so
Missing recommended library: libX11.so
Missing recommended library: libXi.so
Missing recommended library: libXmu.so

Installing the CUDA Samples in /home/cmfchina ...
Copying samples to /home/cmfchina/NVIDIA_CUDA-8.0_Samples now...
Finished copying samples.

===========
= Summary =
===========

Driver:   Not Selected
Toolkit:  Installed in /usr/local/cuda-8.0
Samples:  Installed in /home/cmfchina, but missing recommended libraries

Please make sure that
 -   PATH includes /usr/local/cuda-8.0/bin
 -   LD_LIBRARY_PATH includes /usr/local/cuda-8.0/lib64, or, add /usr/local/cuda-8.0/lib64 to /etc/ld.so.conf and run ldconfig as root

To uninstall the CUDA Toolkit, run the uninstall script in /usr/local/cuda-8.0/bin

Please see CUDA_Installation_Guide_Linux.pdf in /usr/local/cuda-8.0/doc/pdf for detailed information on setting up CUDA.

***WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least 361.00 is required for CUDA 8.0 functionality to work.
To install the driver using this installer, run the following command, replacing <CudaInstaller> with the name of this run file:
    sudo <CudaInstaller>.run -silent -driver

  所有我们一定要安装顺序举行安装,先安装依赖的库文件。

(1)安装缺失的重视库文件

一声令下如下:

sudo apt-get install freeglut3-dev build-essential libx11-dev libxmu-dev libxi-devlibgl1-mesa-glx libglu1  #安装依赖库

 

澳门金沙国际 10

(2)安装执行文书

sudo sh cuda_8.0.61_375.26_linux.run  #执行安装文件

  注意:安装进程中会提醒您举办部分认同操作,首先是承受服务条款,输入accept确认,然后会唤起是还是不是安装cuda tookit、cuda-example等,均输入Y举办规定。但请留意,当了解是或不是安装附带的驱动时,一定要选N!

澳门金沙国际 11

  因为前面大家早已安装好新型的驱动NVIDIA381,附带的驱动是旧版本的还要会有难点,所以并非挑选安装驱动。其余的都一贯默许或者采纳是即可。

(3)设置环境变量

  •   输入指令,编辑环境变量配置文件

    sudo vim ~/.bashrc

  •   在文书末端追加以下两行代码(按键“i”进行编辑操作)

    export PATH=/usr/local/cuda-8.0/bin:$PATH
    export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64:$LD_LIBRARY_PATH
    export CUDA_HOME=/usr/local/cuda

  •   保存退出(按“!wq”),执行上面发号施令,使环境变量立即见效

    #环境变量登时生效
    sudo source ~/.bashrc
    sudo ldconfig

 如图所示:

澳门金沙国际 12

(4)检查cuda是还是不是部署不错

  到这一步,基本的CUDA已经安装到位了,大家得以经过以下命令查看CUDA是不是配备不错:

nvcc --version

  如图所示:

澳门金沙国际 13

(5)测试CUDA的sammples

  为啥需求安装cuda
samples?一方面为了前面学习cuda使用,另一方面,可以检验cuda是不是确实安装成功。假诺cuda
samples全体编译通过,没有一个Error音信(Warning忽略),那么就讲明成功地设置了cuda。如若最终一行尽管彰显PASS,不过编译进度中有ERROR,请自行网上查找相关错误新闻解决将来。

# 切换到cuda-samples所在目录
cd /usr/local/cuda-8.0/samples 或者 cd /home/NVIDIA_CUDA-8.0_Samples 

# 没有make,先安装命令 sudo apt-get install cmake,-j是最大限度的使用cpu编译,加快编译的速度
make –j

# 编译完毕,切换release目录(/usr/local/cuda-8.0/samples/bin/x86_64/linux/release完整目录)
cd ./bin/x86_64/linux/release

# 检验是否成功,运行实例
./deviceQuery 

# 可以认真看看自行结果,它显示了你的NVIDIA显卡的相关信息,最后能看到Result = PASS就算成功。

如图所示:

澳门金沙国际 14

澳门金沙国际 15

 输出结果看出显卡相关音信,并且最终Result
= PASS ,那申明CUDA才真正完全安装成功了


3.2.1 执行安装文件

./cuda_8.0.44_linux-16.04.run --override

安装过程如下:

Do you accept the previously read EULA? (accept/decline/quit): accept
You are attempting to install on an unsupported configuration. Do you wish to continue? ((y)es/(n)o) [ default is no ]: y
Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 367.48? ((y)es/(n)o/(q)uit): n
Install the CUDA 8.0 Toolkit? ((y)es/(n)o/(q)uit): y
Enter Toolkit Location [ default is /usr/local/cuda-8.0 ]:
Do you want to install a symbolic link at /usr/local/cuda? ((y)es/(n)o/(q)uit): y
Install the CUDA 8.0 Samples? ((y)es/(n)o/(q)uit): y
Enter CUDA Samples Location [ default is /home/kinghorn ]: /usr/local/cuda-8.0
Installing the CUDA Toolkit in /usr/local/cuda-8.0 ...
Finished copying samples.
===========
= Summary =
===========
Driver:   Not Selected
Toolkit:  Installed in /usr/local/cuda-8.0
Samples:  Installed in /usr/local/cuda-8.0

澳门金沙国际 16

2.3 环境变量设置

  • 环境变量

$ vim ~/.bashrc
在其最后添加:
export PATH=/usr/local/cuda/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
export CUDA_HOME=/usr/local/cuda
  • cuDNN建立连接

$ cd /usr/local/cuda/lib64
$ sudo rm -rf libcudnn.so libcudnn.so.7         #删除原有版本号,版本号在cudnn/lib64中查询
$ sudo ln -s libcudnn.so.7.0.5 libcudnn.so.7    #生成软连接,注意自己下载的版本号
$ sudo ln -s libcudnn.so.7 libcudnn.so 
$ sudo ldconfig     #立即生效

二、安装cuDNN

②设置环境变量

vi /home/xxx/.bashrc

内容如下:

export PATH=/usr/local/cuda-8.0/bin:$PATH

使环境变量生效

source /home/xxx/.bashrc

③将cuda库添加到系统动态库管理器

sudo vi /etc/ld.so.conf.d/cuda.conf

添加:

/usr/local/cuda/lib64

推行ldconfig使新加的库生效

sudo ldconfig

3. 安装TensorFlow-gpu

  • 安装anaconda,可以用来树立python3和TensorFlow的一些来说环境。

$ wget https://repo.anaconda.com/archive/Anaconda3-5.2.0-Linux-x86_64.sh    #下载anaconda
$ bash anaconda.sh      #安装anaconda
$ vim /root/.bashrc     #加入环境变量
    # 最后一行添加:
    export PATH="/root/anaconda3/bin:$PATH"
$ source /root/.bashrc
  • 安装TensorFlow

pip install tensorflow-gpu

2.1、下载cuDNN

cuDNN是GPU加快总结深层神经互连网的库。首先去官网()下载cuDNN,须要登记一个账号才能下载,没有的话自己注册一个。由于自己的显卡是GTX1080Ti,所以下载版本号如图所示,最新的本子是v7: 

澳门金沙国际 17

④编译cuda例子与测试

进入到/usr/local/cuda/NVIDIA_CUDA-8.0_Samples/1_Utilities/deviceQuery目录执行:

sudo make
./deviceQuery

打印出近似如下音讯,表明装成功

./deviceQuery Starting...
 CUDA Device Query (Runtime API) version (CUDART static linking)
Detected 2 CUDA Capable device(s)
Device 0: "GeForce GTX 1080"
  CUDA Driver Version / Runtime Version          8.0 / 8.0
  CUDA Capability Major/Minor version number:    6.1
  Total amount of global memory:                 8110 MBytes (8504279040 bytes)
  (20) Multiprocessors, (128) CUDA Cores/MP:     2560 CUDA Cores
  GPU Max Clock rate:                            1772 MHz (1.77 GHz)
  Memory Clock rate:                             5005 Mhz
  Memory Bus Width:                              256-bit
  L2 Cache Size:                                 2097152 bytes
  Maximum Texture Dimension Size (x,y,z)         1D=(131072), 2D=(131072, 65536), 3D=(16384, 16384, 16384)
  Maximum Layered 1D Texture Size, (num) layers  1D=(32768), 2048 layers
  Maximum Layered 2D Texture Size, (num) layers  2D=(32768, 32768), 2048 layers
  Total amount of constant memory:               65536 bytes
  Total amount of shared memory per block:       49152 bytes
  Total number of registers available per block: 65536
  Warp size:                                     32
  Maximum number of threads per multiprocessor:  2048
  Maximum number of threads per block:           1024
  Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
  Max dimension size of a grid size    (x,y,z): (2147483647, 65535, 65535)
  Maximum memory pitch:                          2147483647 bytes
  Texture alignment:                             512 bytes
  Concurrent copy and kernel execution:          Yes with 2 copy engine(s)
  Run time limit on kernels:                     Yes
  Integrated GPU sharing Host Memory:            No
  Support host page-locked memory mapping:       Yes
  Alignment requirement for Surfaces:            Yes
  Device has ECC support:                        Disabled
  Device supports Unified Addressing (UVA):      Yes
  Device PCI Domain ID / Bus ID / location ID:   0 / 1 / 0
  Compute Mode:
     < Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >

测试

输入:

$ python
>>> import tensorflow

显示:

>>> import tensorflow
/root/anaconda3/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
>>> 

未报错,安装成功。

转发请阐明出处。

2.2、安装cuDNN

设置cudnn相比不难,简单地说,就是复制多少个公文:库文件和头文件。将cudnn的头文件复制到cuda安装路径的include路径下,将cudnn的库文件复制到cuda安装路径的lib64路径下。具体操作如下

 1 #解压文件
 2 tar -zxvf cudnn-8.0-linux-x64-v7.tgz
 3 
 4 #切换到刚刚解压出来的文件夹路径
 5 cd cuda 
 6 #复制include里的头文件(记得转到include文件里执行下面命令)
 7 sudo cp /include/cudnn.h  /usr/local/cuda/include/
 8 
 9 #复制lib64下的lib文件到cuda安装路径下的lib64(记得转到lib64文件里执行下面命令)
10 sudo cp lib*  /usr/local/cuda/lib64/
11 
12 #设置权限
13 sudo chmod a+r /usr/local/cuda/include/cudnn.h 
14 sudo chmod a+r /usr/local/cuda/lib64/libcudnn*
15 
16 #======更新软连接======
17 cd /usr/local/cuda/lib64/ 
18 sudo rm -rf libcudnn.so libcudnn.so.7   #删除原有动态文件,版本号注意变化,可在cudnn的lib64文件夹中查看   
19 sudo ln -s libcudnn.so.7.0.2 libcudnn.so.7  #生成软衔接(注意这里要和自己下载的cudnn版本对应,可以在/usr/local/cuda/lib64下查看自己libcudnn的版本)
20 sudo ln -s libcudnn.so.7 libcudnn.so #生成软链接
21 sudo ldconfig -v #立刻生效

 

备注:下面的软连接的版本号要基于自己实际下载的cudnn的lib版本号

如图所示:

澳门金沙国际 18

终极大家看看验证安装cudnn后cuda是或不是仍然可用

nvcc --version  # or nvcc -V 

(3)安装cudnn-v5.1库

2.3、检验cuDNN是还是不是安装成功

  到近年来截止,cuDNN已经安装完了,不过,是不是成功安装,大家得以经过cuDNN
sample测试一下(
页面中找到呼应的cudnn版本,里面有 cuDNN v5 Code
Samples,点击该链接下载即可,版本可能不平等,下载最新的就行)

  下载完,转到解压出的目录下的mnistCUDNN,如图所示:

澳门金沙国际 19

  通过下边发号施令,举行校验

#运行cudnn-sample-v5
tar –zxvf cudnn-sample-v5.tgz  #解压压缩包
cd mnistCUDNN  #转到解压的mnistCUDNN目录下
make  #make 命令下
./mnistCUDNN   #在mnistCUDNN目录下执行./mnistCUDNN
#改程序运行成功,如果结果看到Test passed!说明cudnn安装成功。

 假如结果来看Test
passed!表明cudnn安装成功

澳门金沙国际 20

 至此、cuDNN已经成功安装了


 

①解压

tar xzvf cudnn-8.0-linux-x64-v5.1.tgz

得到cuda文件夹里面包蕴lib64和include七个文件夹

三、安装Anaconda

  Anaconda是python的一个科学总结发行版,内置了数百个python平常会动用的库,也席卷广大做机械学习或数量挖掘的库,那么些库很多是TensorFlow的信赖库。安装好Anaconda可以提供一个好的环境平昔设置TensorFlow。

  去Anaconda官网()下载须求版本的Anaconda

澳门金沙国际 21

  下载完后实施如下命令

sudo bash Anaconda3-4.4.0-Linux-x86_64.sh

  如图所示:

澳门金沙国际 22

  安装anaconda,回车后,是批准文件,接收许可。直接回车即可。最终会询问是或不是把anaconda的bin添加到用户的环境变量中,接纳yes。在巅峰输入python发现如故是系统自带的python版本,那是因为环境变量的立异还平素不立见作用,命令行输入如下命令是安装的anaconda生效。假使conda
–version没有找到此外信息,表明没有加入到环境变量没有,需求手动参加,如图所示:

澳门金沙国际 23

  刷新环境变量

source /etc/profile 或者 source ~/.bashrc #(全局的环境变量)

②拷贝到cuda安装目录

sudo cp cuda/cudnn.h /usr/local/cuda/include/
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64/

拷贝后将链接删除重新确立链接,否则,拷贝是四个四个例外名字的相同文件,链接关系接纳ls
-l查看cudnn解压后的lib64文件夹。也足以分级拷贝每一个文本,链接文件拷贝使用cp
-d命令。

三、安装TensorFlow

  大家可以参见TensorFlow的法定安装教程(),官网提供的了
Pip, Docker, Virtualenv, Anaconda 或 源码编译的办法安装
TensorFlow,大家那边根本介绍以Anaconda安装。其余装置格局,大家可以到法虞诩装教程查看。

4.安装opencv3.1.0

3.1安装TensorFlow

  通过Anaconda安装TensorFlow
CPU,TensorFlow
的法定下载源现在已经在GitHub上提供了(),找到呼应的版本号,如图所示:

澳门金沙国际 24

(1)解压,创建build目录

unzip opencv-3.1.0.zip
cd opencv-3.1.0
mkdir build

(2)修改opencv源码,使其包容cuda8.0

vi opencv-3.1.0/modules/cudalegacy/src/graphcuts.cpp

修改如下:
澳门金沙国际 25
将:

#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER)```

改为:

#if !defined(HAVE_CUDA)||defined(CUDA_DISABLER)||(CUDART_VERSION>=8000)

(3)配置opencv,生成Makefile

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..

假使因为ippicv_linux_20151201.tgz包下载战败而造成Makefile生成败北,可通过手动下载ippicv_linux_20151201.tgz安装包,将其拷贝至
opencv-3.1.0/3rdparty/ippicv/downloads/linux-8b449a536a2157bcad08a2b9f266828b目录内,重新履行配置命令即可。

(1)、创立一个名为tensorflow的conda环境Python 3.6

#Python 2.7
conda create -n tensorflow python=2.7

#Python 3.4
conda create -n tensorflow python=3.4

#Python 3.5
conda create -n tensorflow python=3.5

#Python 3.6
conda create -n tensorflow python=3.6   #我下的TensorFlow对应的Python是3.6版本,那么我就使用这行

备注:(根据TensorFlow版本号,一定要设置Python版本号,切记切记切记!!!!!重要的事情说三遍!否则后面会报各种错的)

(4)编译

make -j8

编译进度中若是现身如下错误:

/usr/include/string.h: In function ‘void* __mempcpy_inline(void*, const void*, size_t)’: /usr/include/string.h:652:42: error: ‘memcpy’ was not declared in this scope return (char *) memcpy (__dest, __src, __n) + __n;

那是因为ubuntu的g++版本过高导致的,只须要在opencv-3.1.0目录下的CMakeList.txt
文件的上马插手:

set(CMAKE_CXX_FLAGS “${CMAKE_CXX_FLAGS} -D_FORCE_INLINES”)

累加事后再行开展编译即可。

(2)、激活 conda 环境

source activate tensorflow

(5)安装

sudo make install

(3)、TensorFlow 各样版本(最新的相似是1.3的版本了)

  然后基于要安装的两样tensorflow版本选拔相应的一条下载链接(操作系统,Python版本,CPU版本依旧CPU+GPU版本),官方文档都有连锁信息。

Python 2.7

CPU:
https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.3.0-cp27-none-linux_x86_64.whl

GPU:
https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.3.0-cp27-none-linux_x86_64.whl
===============================================================================================

Python 3.4

CPU:
https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.3.0-cp34-cp34m-linux_x86_64.whl

GPU:
https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.3.0-cp34-cp34m-linux_x86_64.whl
===============================================================================================

Python 3.5

CPU:
https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.3.0-cp35-cp35m-linux_x86_64.whl

GP:
https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.3.0-cp35-cp35m-linux_x86_64.whl
===============================================================================================

Python 3.6

CPU:
https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.3.0-cp36-cp36m-linux_x86_64.whl

GPU:
https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.3.0-cp36-cp36m-linux_x86_64.whl

(6)查看版本号

pkg-config --modversion opencv

(4)、在conda环境中设置TensorFlow GPU版(本文主要以安装GPU版讲解)

5.安装caffe

  因为大家前边拔取了conda环境为Python3.6的,所以我们采用Python3.6版本的GPU链接地址,进行安装

#如何进行安装,我们这里安装Python版本为3.6的TensorFlow

sudo pip3 install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.3.0-cp36-cp36m-linux_x86_64.whl

备注:连接里的cpxx和cpxxm的xx是对应Python的版本号

荒谬归咎-重点关心!!!:

  安装whl包的时候出现“tensorflow_gpu-1.3.0-cp36-cp36m-linux_x86_64.whl
is not a supported wheel on this
platform”的标题。大家须求下载GPU版的安装包,在设置包下载之后,然后手动进入环境,安装TensorFlow。

具体操作如下(因为我遇上这么难题,只能够用上面那种艺术安装了):

source activate tensorflow    #激活tensorflow环境(这步操作了,就忽略)
cd /Downloads    #切换到whl文件所在文件夹
pip install --ignore-installed --upgrade tensorflow_gpu-1.3.0-cp36-cp36m-linux_x86_64.whl   #切记,不要用sudo pip,也不要用pip3,然后--ignore-installed --upgrade等参数也不能省略,否则会出错。

   如图所示,TensorFlow安装成功了:

澳门金沙国际 26

澳门金沙国际 27

全体日志:

cmfchina@cmfchina:~$ conda create -n tensorflow python=3.6
Fetching package metadata .........
Solving package specifications: .

Package plan for installation in environment /home/cmfchina/.conda/envs/tensorflow:

The following NEW packages will be INSTALLED:

    certifi:    2016.2.28-py36_0
    openssl:    1.0.2l-0        
    pip:        9.0.1-py36_1    
    python:     3.6.2-0         
    readline:   6.2-2           
    setuptools: 36.4.0-py36_1   
    sqlite:     3.13.0-0        
    tk:         8.5.18-0        
    wheel:      0.29.0-py36_0   
    xz:         5.2.3-0         
    zlib:       1.2.11-0        

Proceed ([y]/n)? y

#
# To activate this environment, use:
# > source activate tensorflow
#
# To deactivate this environment, use:
# > source deactivate tensorflow
#

cmfchina@cmfchina:~$ source activate tensorflow
(tensorflow) cmfchina@cmfchina:~$ wget https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.3.0-cp36-cp36m-linux_x86_64.whl
--2017-09-26 10:06:45--  https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.3.0-cp36-cp36m-linux_x86_64.whl
Resolving storage.googleapis.com (storage.googleapis.com)... 216.58.200.48, 2404:6800:4008:801::2010
Connecting to storage.googleapis.com (storage.googleapis.com)|216.58.200.48|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 159078494 (152M) [application/octet-stream]
Saving to: ‘tensorflow_gpu-1.3.0-cp36-cp36m-linux_x86_64.whl.1’

tensorflow_gpu-1.3. 100%[===================>] 151.71M  2.99MB/s    in 52s     

2017-09-26 10:07:38 (2.89 MB/s) - ‘tensorflow_gpu-1.3.0-cp36-cp36m-linux_x86_64.whl.1’ saved [159078494/159078494]

(tensorflow) cmfchina@cmfchina:~$ pip install --ignore-installed --upgrade tensorflow_gpu-1.3.0-cp36-cp36m-linux_x86_64.whl
Processing ./tensorflow_gpu-1.3.0-cp36-cp36m-linux_x86_64.whl
Collecting six>=1.10.0 (from tensorflow-gpu==1.3.0)
  Using cached six-1.11.0-py2.py3-none-any.whl
Collecting tensorflow-tensorboard<0.2.0,>=0.1.0 (from tensorflow-gpu==1.3.0)
  Downloading tensorflow_tensorboard-0.1.6-py3-none-any.whl (2.2MB)
    100% |████████████████████████████████| 2.2MB 345kB/s 
Collecting numpy>=1.11.0 (from tensorflow-gpu==1.3.0)
  Downloading numpy-1.13.1-cp36-cp36m-manylinux1_x86_64.whl (17.0MB)
    100% |████████████████████████████████| 17.0MB 93kB/s 
Collecting protobuf>=3.3.0 (from tensorflow-gpu==1.3.0)
  Downloading protobuf-3.4.0-cp36-cp36m-manylinux1_x86_64.whl (6.2MB)
    100% |████████████████████████████████| 6.2MB 203kB/s 
Collecting wheel>=0.26 (from tensorflow-gpu==1.3.0)
  Using cached wheel-0.30.0-py2.py3-none-any.whl
Collecting bleach==1.5.0 (from tensorflow-tensorboard<0.2.0,>=0.1.0->tensorflow-gpu==1.3.0)
  Downloading bleach-1.5.0-py2.py3-none-any.whl
Collecting markdown>=2.6.8 (from tensorflow-tensorboard<0.2.0,>=0.1.0->tensorflow-gpu==1.3.0)
  Downloading Markdown-2.6.9.tar.gz (271kB)
    100% |████████████████████████████████| 276kB 834kB/s 
Collecting werkzeug>=0.11.10 (from tensorflow-tensorboard<0.2.0,>=0.1.0->tensorflow-gpu==1.3.0)
  Downloading Werkzeug-0.12.2-py2.py3-none-any.whl (312kB)
    100% |████████████████████████████████| 317kB 985kB/s 
Collecting html5lib==0.9999999 (from tensorflow-tensorboard<0.2.0,>=0.1.0->tensorflow-gpu==1.3.0)
  Downloading html5lib-0.9999999.tar.gz (889kB)
    100% |████████████████████████████████| 890kB 673kB/s 
Collecting setuptools (from protobuf>=3.3.0->tensorflow-gpu==1.3.0)
  Using cached setuptools-36.5.0-py2.py3-none-any.whl
Building wheels for collected packages: markdown, html5lib
  Running setup.py bdist_wheel for markdown ... done
  Stored in directory: /home/cmfchina/.cache/pip/wheels/bf/46/10/c93e17ae86ae3b3a919c7b39dad3b5ccf09aeb066419e5c1e5
  Running setup.py bdist_wheel for html5lib ... done
  Stored in directory: /home/cmfchina/.cache/pip/wheels/6f/85/6c/56b8e1292c6214c4eb73b9dda50f53e8e977bf65989373c962
Successfully built markdown html5lib
Installing collected packages: six, html5lib, bleach, markdown, numpy, werkzeug, setuptools, protobuf, wheel, tensorflow-tensorboard, tensorflow-gpu
Successfully installed bleach-1.5.0 html5lib-0.9999999 markdown-2.6.9 numpy-1.13.1 protobuf-3.4.0 setuptools-36.5.0 six-1.11.0 tensorflow-gpu-1.3.0 tensorflow-tensorboard-0.1.6 werkzeug-0.12.2 wheel-0.30.0

(1)安装须求的爱护库

sudo apt-get install build-essential
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev 
sudo apt-get libopencv-dev libhdf5-serial-dev protobuf-compiler
sudo apt-get install --no-install-recommends libboost-all-dev
sudo apt-get install libatlas-base-dev
sudo apt-get install python-dev
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev

(2)解压修改配置文件

unzip caffe-master.zip
cp Makefile.config.example Makefile.config
vi Makefile.config

最首要布局修改如下:

USE_CUDNN := 1
OPENCV_VERSION := 3
CUDA_DIR :=/usr/local/cuda-8.0
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial
/usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial
WITH_PYTHON_LAYER := 1
USE_PKG_CONFIG := 1

(3)编译caffe

make -j8

想必碰着的失实1:src/caffe/net.cpp:8:18: fatal error: hdf5.h: No such
file or directory
杀鸡取蛋办法:

cd /usr/lib/x86_64-linux-gnu
sudo ln -s libhdf5_serial.so.10.1.0 libhdf5_serial.so
sudo ln -s libhdf5_serial_hl.so.10.0.2 libhdf5_serial_hl.so

唯恐境遇的荒谬2:error – unsupported GNU version! gcc versions later
than 5.3 are not supported!
杀鸡取蛋办法:修改/usr/local/cuda/include/host_config.h文件

#if __GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ > 3)
#error -- unsupported GNU version! gcc versions later than 5.3 are not supported!

改为:

 #if __GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ > 4)
 #error -- unsupported GNU version! gcc versions later than 5.4 are not supported!

可能遇见的不当3:

/usr/include/string.h: In function ‘void* **__mempcpy_inline(void*, const void*, size_t)’: /usr/include/string.h:652:42: error: ‘memcpy’ was not declared in this scope return (char *) memcpy (__dest, __src, __n) + __n;**

杀鸡取卵办法:修改caffe-master的Makefile

NVCCFLAGS +=-ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)

改为:

NVCCFLAGS +=-D_FORCE_INLINES -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)

或是境遇的错误4:

caffe/proto/caffe.pb.h: No such file or directory

行使如下方法生成caffe.pb.h

protoc src/caffe/proto/caffe.proto --cpp_out=.  
mkdir include/caffe/proto  
mv src/caffe/proto/caffe.pb.h include/caffe/proto 

(5)、在conda环境中装置TensorFlow CPU版

(4)编译caffe的python接口

make pycaffe

  因为大家眼前拔取了conda环境为Python3.6的,所以大家挑选Python3.6版本的CPU链接地址,举行设置

#如何进行安装,我们这里安装Python版本为3.6的TensorFlow

sudo pip3 install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.3.0-cp36-cp36m-linux_x86_64.whl

备注:连接里的cpxx和cpxxm的xx是对应Python的版本号

谬误归结:

  安装whl包的时候出现“tensorflow-1.3.0-cp36-cp36m-linux_x86_64.whl
is not a supported wheel on this
platform”的题材,和方面安装GPU一样的谬误。大家需求下载CPU版的安装包,在设置包下载之后,注意!!!那个时候大家要求将whl文件重命名为tensorflow-1.3.0-py3-none-linux_x86_64.whl,然后手动进入环境,安装TensorFlow。

具体操作如下:

source activate tensorflow   #激活tensorflow环境(这步操作了,就忽略)
cd /Downloads   #切换到whl文件所在文件夹
pip install --ignore-installed --upgrade tensorflow-1.3.0-py3-none-linux_x86_64.whl   #切记,不要用sudo pip,也不要用pip3,然后--ignore-installed --upgrade等参数也不能省略,否则会出错。

其它的和GPU安装是同一的,具体不做教师。

(5)运行caffe runtest

make runtest

此间时间有点长。

(6)、当您绝不 TensorFlow 的时候,关闭环境

source deactivate tensorflow

6.运行手写体例程

跻身到caffe根目录下,运行脚本

(7)、安装成功后,每一趟使用 TensorFlow 的时候须要激活 conda 环境(操作步骤2就可以了)

(1)获取数据

sh data/mnist/get_mnist.sh

3.2、常见难点以及错误

标题一、假如设置后,运行实例提示ModuleNotFoundError:
No module named ‘tensorflow’的话

import tensorflow as tf
Traceback (most recent call last):
File “”, line 1, in
ModuleNotFoundError: No module named ‘tensorflow’

  解决办法:下载的TensorFlow对应的Python版本一定要和conda
create -n tensorflow
python=x.x的版本相同才行,所以TensorFlow版本有时候太高反而不好,低版本包容性更好,这么些看个人希望。

标题二、出现“ImportError:
libcudnn.so.6: cannot open shared object file: No such file or
directory”错误音信

Python 3.6.2 |Continuum Analytics, Inc.| (default, Jul 20 2017, 13:51:32) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
Traceback (most recent call last):
  File "/home/cmfchina/.conda/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 41, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "/home/cmfchina/.conda/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "/home/cmfchina/.conda/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
  File "/home/cmfchina/.conda/envs/tensorflow/lib/python3.6/imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "/home/cmfchina/.conda/envs/tensorflow/lib/python3.6/imp.py", line 342, in load_dynamic
    return _load(spec)
ImportError: libcudnn.so.6: cannot open shared object file: No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/cmfchina/.conda/envs/tensorflow/lib/python3.6/site-packages/tensorflow/__init__.py", line 24, in <module>
    from tensorflow.python import *
  File "/home/cmfchina/.conda/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "/home/cmfchina/.conda/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 52, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "/home/cmfchina/.conda/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 41, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "/home/cmfchina/.conda/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "/home/cmfchina/.conda/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
  File "/home/cmfchina/.conda/envs/tensorflow/lib/python3.6/imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "/home/cmfchina/.conda/envs/tensorflow/lib/python3.6/imp.py", line 342, in load_dynamic
    return _load(spec)
ImportError: libcudnn.so.6: cannot open shared object file: No such file or directory

 那几个都是有套路的,解决措施:

  • 首先检查是还是不是存在libcundnn.so.*

    find / -name libcudnn.so.*

找到文件就下一步,没找到,检查下cudnn的借助库,就是眼前的环境变量做对了没

  • 确立硬连接

    sudo ln -s libcudnn.so.7.* libcudnn.so.6  #path就是libcudnn.so.7的四处目录

    或者

    sudo ln -s libcudnn.so.7.* libcudnn.so.6  #cd 到 libcudnn.so.7的所在目录    

以此理应是从未难点

(2)将标签数据转换成caffe使用的LMDB数据格式

sh examples/mnist/create_mnist.sh

3.3、卸载TensorFlow

  假若大家要求卸载TensorFlow的话,使用上边发号施令

sudo pip uninstall tensorflow   #Python2.7

sudo pip3 uninstall tensorflow   #Python3.x

(3)执行教练脚本

sh examples/mnist/train_lenet.sh

教练时间区其他显卡磨炼时间不一,gtx1080迭代10000次大概必要20s,最后结果如下所示:

I0716 14:46:01.360709 27985 solver.cpp:404]     Test net output #0: accuracy = 0.9908
I0716 14:46:01.360750 27985 solver.cpp:404]     Test net output #1: loss = 0.0303895 (* 1 = 0.0303895 loss)
I0716 14:46:01.360755 27985 solver.cpp:322] Optimization Done.
I0716 14:46:01.360757 27985 caffe.cpp:222] Optimization Done.

澳门金沙国际 28

模型精度在0.99以上。至此,在ubuntu16.04连串下利用gtx1080显卡+cudnn-v5的支出环境就搭建落成了。

Ubuntu 14.04 安装配备CUDA 
http://www.linuxidc.com/Linux/2014-10/107501.htm

Ubuntu 14.04下CUDA8.0 + cuDNN v5 + Caffe  装置配备 
http://www.linuxidc.com/Linux/2017-01/139300.htm

Caffe配置简明教程 ( Ubuntu 14.04 / CUDA 7.5 / cuDNN 5.1 / OpenCV 3.1 )
http://www.linuxidc.com/Linux/2016-09/135016.htm

Ubuntu 16.04 安装配置MATLAB+Python +CUDA8.0+cuDNN+OpenCV3.1的Caffe环境 
http://www.linuxidc.com/Linux/2017-06/145087.htm

在Ubuntu 14.04上配置CUDA+Caffe+cuDNN+Anaconda+DIGITS 
http://www.linuxidc.com/Linux/2016-11/136775.htm

深度学习条件布署Ubuntu16.04+CUDA8.0+CUDNN5 
http://www.linuxidc.com/Linux/2017-09/147180.htm

正文永久更新链接地址:http://www.linuxidc.com/Linux/2017-10/147609.htm

澳门金沙国际 29

3.4、测试TensorFlow

  在python的条件中,运行简单的TensorFlow程序测试(官方demo)

>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> sess.run(hello)
'Hello, TensorFlow!'
>>> a = tf.constant(10)
>>> b = tf.constant(32)
>>> sess.run(a + b)
42
>>> sess.close()

 运行如图所示:

澳门金沙国际 30

时至先天,TensorFlow安装成功,进度充满了辛苦..(。•ˇ‸ˇ•。)…所以大家安装的时候每一步都主要~

 

PS:如有疑问,请留言,未经允许,不得不合法转发,转发请声明出处: 

澳门金沙国际 31

澳门金沙国际 32

相关文章