前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Ubuntu 16.04+CUDA8.0+MKL+OpenCV3.2+Matlab R2016b+Caffe安装

Ubuntu 16.04+CUDA8.0+MKL+OpenCV3.2+Matlab R2016b+Caffe安装

作者头像
用户8710806
修改2021-06-11 09:57:50
6170
修改2021-06-11 09:57:50
举报
文章被收录于专栏:linux百科小宇宙linux百科小宇宙

经过无数次的失败后,终于安装成功,安装过程并不是很难,只是遇到问题时候的解决方式不对,导致花费了不少时间。现将过程整理如下:

电脑的环境:Ubuntu 16.04 64位系统(Windows7双系统)、GPU型号为GeForce GT 540M。

1、先安装相关依赖项

sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compile

sudo apt-get install --no-install-recommends libboost-all-dev

sudo apt-get install libopenblas-dev liblapack-dev libatlas-base-dev 

sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev

2、安装NVIDIA驱动

很多教程都是用驱动文件安装,但我的电脑驱动文件总是安装失败,即使成功了也会遇到很多问题(重启后黑屏、循环登录、NVIDIA X Server Settings仅显示部分信息等)。所以,驱动文件安装方式请自行搜索。

最后,我直接通过系统设置->软件和更新->附件驱动,安装了最新的专有驱动nvidia-375。若总是应用更改失败,则可以尝试更新源,更新方式如下:

sudo vi /etc/apt/sources.list  ->替换源  ->sudo apt-get update

替换内容如下(仅供参考):

 

# deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted

 

 

deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties

 

 

deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted

 

 

deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties

 

 

deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted

 

 

deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties

 

 

deb http://mirrors.aliyun.com/ubuntu/ xenial universe

 

 

deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe

 

 

deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse

 

 

deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse

 

 

deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse

 

 

deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties

 

 

deb http://archive.canonical.com/ubuntu xenial partne

 

 

deb-src http://archive.canonical.com/ubuntu xenial partne

 

 

deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted

 

 

deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties

 

 

deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe

 

 

deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse

 

3、CUDA8.0

<p style="text-align: justify;">(1)下载:https://developer.nvidia.com/cuda-downloads

<p style="text-align: justify;">(2)下载完成后执行以下命令:

<p style="text-align: justify;"> 

sudochmod777 cuda_8.0.44_linux.run

sudo ./cuda_8.0.44_linux.run

注意:执行后会有一系列提示让你确认,但是注意,有个让你选择是否安装nvidia367驱动时,一定要选择否:<br style="font-family: tahoma,宋体; color: #333333; text-align: justify; line-height: 22px; background-color: #fafafc;" />Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 367.48?<br style="font-family: tahoma,宋体; color: #333333; text-align: justify; line-height: 22px; background-color: #fafafc;" />因为前面我们已经安装了更加新的nvidia367,所以这里不要选择安装。其余的都直接默认或者选择是即可。

(3)环境变量配置

 

<p style="font-family: tahoma,宋体; color: #333333; text-align: justify; line-height: 22px; background-color: #fafafc;">打开~/.bashrc文件: sudo gedit ~/.bashrc 

将以下内容写入到~/.bashrc尾部:

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

export LD_LIBRARY_PATH=/usr/local/cuda8.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

<p style="font-family: tahoma,宋体; color: #333333; text-align: justify; line-height: 22px; background-color: #fafafc;">(4)测试CUDA的samples

cd /usr/local/cuda-8.0/samples/1_Utilities/deviceQuery

makesudo ./deviceQuery

如果显示一些关于GPU的信息,则说明安装成功。

4、配置cuDNN<br style="font-family: tahoma,宋体; color: #333333; text-align: justify; line-height: 22px; background-color: #fafafc;" />cuDNN是GPU加速计算深层神经网络的库。首先去官网 https://developer.nvidia.com/rdp/cudnn-download 下载cuDNN,需要注册一个账号才能下载。

 

<p style="font-family: tahoma,宋体; color: #333333; text-align: justify; line-height: 22px; background-color: #fafafc;">下载cuDNN5.1之后进行解压:

sudo tar -zxvf ./cudnn-8.0-linux-x64-v6.0.tgz

<p style="font-family: tahoma,宋体; color: #333333; text-align: justify; line-height: 22px; background-color: #fafafc;">进入cuDNN5.1解压之后的include目录,在命令行进行如下操作:

cd cuda/include

sudo cp cudnn.h /usr/local/cuda/include  #复制头文件

<p style="font-family: tahoma,宋体; color: #333333; text-align: justify; line-height: 22px; background-color: #fafafc;">再将进入lib64目录下的动态文件进行复制和链接:

cd ..

cd lib64

sudo cp lib* /usr/local/cuda/lib64/ #复制动态链接库

cd /usr/local/cuda/lib64/

sudo rm -rf libcudnn.so libcudnn.so.6 #删除原有动态文件

sudo ln -s libcudnn.so.6.0.20 libcudnn.so.6 #生成软衔接

sudo ln -s libcudnn.so.6 libcudnn.so #生成软链接

<p style="text-align: justify;">5、安装MKL

<p style="margin-bottom: 10px; font-family: 微软雅黑,Verdana,sans-serif,宋体; margin-top: 10px; color: #333333; padding-bottom: 0px; padding-top: 0px; letter-spacing: 0px; line-height: 22px; background-color: #fafafc; -ms-word-wrap: break-word;" align="left">这里也可以选择(ATLAS,MKL或者OpenBLAS),依赖文件安装时已经安装了ATLAS,我这里安装MKL,首先下载并安装英特尔®数学内核库 Linux*版MKL(Intel(R) Parallel Studio XE Cluster Edition for Linux 2016),下载链接是:https://software.intel.com/en-us/intel-education-offerings,使用学生身份(邮件 + 学校)下载Student版,填好各种信息,可以直接下载,同时会给你一个邮件告知序列号。下载完之后,要把文件解压到home文件夹,或者其他的ext4的文件系统中。

<p style="margin-bottom: 10px; font-family: 微软雅黑,Verdana,sans-serif,宋体; margin-top: 10px; color: #333333; padding-bottom: 0px; padding-top: 0px; letter-spacing: 0px; line-height: 22px; background-color: #fafafc; -ms-word-wrap: break-word;" align="left">接下来是安装过程,先授权,然后安装:

<p style="margin-bottom: 10px; font-family: 微软雅黑,Verdana,sans-serif,宋体; margin-top: 10px; color: #333333; padding-bottom: 0px; padding-top: 0px; letter-spacing: 0px; line-height: 22px; background-color: #fafafc; -ms-word-wrap: break-word;" align="left">$ tar zxvf parallel_studio_xe_2017_update3.tgz

<p style="margin-bottom: 10px; font-family: 微软雅黑,Verdana,sans-serif,宋体; margin-top: 10px; color: #333333; padding-bottom: 0px; padding-top: 0px; letter-spacing: 0px; line-height: 22px; background-color: #fafafc; -ms-word-wrap: break-word;" align="left">$ chmod a+x parallel_studio_xe_2016 -R

<p style="margin-bottom: 10px; font-family: 微软雅黑,Verdana,sans-serif,宋体; margin-top: 10px; color: #333333; padding-bottom: 0px; padding-top: 0px; letter-spacing: 0px; line-height: 22px; background-color: #fafafc; -ms-word-wrap: break-word;" align="left">$ sudo sh install_GUI.sh

<p style="margin-bottom: 10px; font-family: 微软雅黑,Verdana,sans-serif,宋体; margin-top: 10px; color: #333333; padding-bottom: 0px; padding-top: 0px; letter-spacing: 0px; line-height: 22px; background-color: #fafafc; -ms-word-wrap: break-word;" align="left">PS: 安装的时候,建议使用root权限安装,过程中会要求输入Linux的root口令。

<p style="margin-bottom: 10px; font-family: 微软雅黑,Verdana,sans-serif,宋体; margin-top: 10px; color: #333333; padding-bottom: 0px; padding-top: 0px; letter-spacing: 0px; line-height: 22px; background-color: #fafafc; -ms-word-wrap: break-word;" align="left"> 

<p style="margin-bottom: 10px; font-family: 微软雅黑,Verdana,sans-serif,宋体; margin-top: 10px; color: #333333; padding-bottom: 0px; padding-top: 0px; letter-spacing: 0px; line-height: 22px; -ms-word-wrap: break-word;" align="left">MKL与CUDA的环境设置

<p style="margin-bottom: 10px; font-family: 微软雅黑,Verdana,sans-serif,宋体; margin-top: 10px; color: #333333; padding-bottom: 0px; padding-top: 0px; letter-spacing: 0px; line-height: 22px; -ms-word-wrap: break-word;" align="left">(1) 新建intel_mkl.conf,并编辑

<p style="font-size: 12px; margin-bottom: 10px; font-family: 微软雅黑,Verdana,sans-serif,宋体; margin-top: 10px; color: #333333; padding-bottom: 0px; padding-top: 0px; letter-spacing: 0px; line-height: 22px; -ms-word-wrap: break-word;" align="left">$ sudo gedit /etc/ld.so.conf.d/intel_mkl.conf

<p style="font-size: 12px; margin-bottom: 10px; font-family: 微软雅黑,Verdana,sans-serif,宋体; margin-top: 10px; color: #333333; padding-bottom: 0px; padding-top: 0px; letter-spacing: 0px; line-height: 22px; -ms-word-wrap: break-word;" align="left">/opt/intel/lib/intel64

<p style="font-size: 12px; margin-bottom: 10px; font-family: 微软雅黑,Verdana,sans-serif,宋体; margin-top: 10px; color: #333333; padding-bottom: 0px; padding-top: 0px; letter-spacing: 0px; line-height: 22px; -ms-word-wrap: break-word;" align="left">/opt/intel/mkl/lib/intel64

<p style="font-size: 12px; margin-bottom: 10px; font-family: 微软雅黑,Verdana,sans-serif,宋体; margin-top: 10px; color: #333333; padding-bottom: 0px; padding-top: 0px; letter-spacing: 0px; line-height: 22px; -ms-word-wrap: break-word;" align="left">(2) 新建cuda.conf,并编辑

<p style="font-size: 12px; margin-bottom: 10px; font-family: 微软雅黑,Verdana,sans-serif,宋体; margin-top: 10px; color: #333333; padding-bottom: 0px; padding-top: 0px; letter-spacing: 0px; line-height: 22px; -ms-word-wrap: break-word;" align="left">$ sudo gedit /etc/ld.so.conf.d/cuda.conf

<p style="font-size: 12px; margin-bottom: 10px; font-family: 微软雅黑,Verdana,sans-serif,宋体; margin-top: 10px; color: #333333; padding-bottom: 0px; padding-top: 0px; letter-spacing: 0px; line-height: 22px; -ms-word-wrap: break-word;" align="left">/usr/local/cuda/lib64

<p style="font-size: 12px; margin-bottom: 10px; font-family: 微软雅黑,Verdana,sans-serif,宋体; margin-top: 10px; color: #333333; padding-bottom: 0px; padding-top: 0px; letter-spacing: 0px; line-height: 22px; -ms-word-wrap: break-word;" align="left">/lib

<p style="font-size: 12px; margin-bottom: 10px; font-family: 微软雅黑,Verdana,sans-serif,宋体; margin-top: 10px; color: #333333; padding-bottom: 0px; padding-top: 0px; letter-spacing: 0px; line-height: 22px; -ms-word-wrap: break-word;" align="left">(3) 完成lib文件的链接操作,执行:

<p style="font-size: 12px; margin-bottom: 10px; font-family: 微软雅黑,Verdana,sans-serif,宋体; margin-top: 10px; color: #333333; padding-bottom: 0px; padding-top: 0px; letter-spacing: 0px; line-height: 22px; -ms-word-wrap: break-word;" align="left">$ sudo ldconfig

6、安装opencv3.2

<p style="margin-bottom: 10px; margin-top: 10px; padding-bottom: 0px; padding-top: 0px; -ms-word-wrap: break-word;" align="left"> 

<p style="font-family: tahoma,宋体; color: #333333; text-align: justify; letter-spacing: 0px; line-height: 22px; background-color: #fafafc;">从官网(http://opencv.org)下载Opencv。

unzip opencv-3.2.0.zip

cd ~/opencv-3.2.0

mkdir build

cd build

<p style="color: #333333; text-align: justify; letter-spacing: 0px; line-height: 22px; background-color: #fafafc;">配置:

sudo apt install cmake

sudo cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..

<p style="color: #333333; text-align: justify; letter-spacing: 0px; line-height: 22px; background-color: #fafafc;">编译:

sudo make

sudomakeinstall

7、安装Matlab

(1)下载Matlab2016b,请自行搜索

 

<p style="margin-bottom: 0px; margin-top: 0px; padding-bottom: 0px; padding-top: 0px;">下载后的Linux文件夹会有三个文件分别是R2016b_glnxa64_dvd1.iso、R2016b_glnxa64_dvd2.iso和Matlab 2016b Linux64 Crack文件夹。Crack文件解压:

<p style="margin-bottom: 0px; margin-top: 0px; padding-bottom: 0px; padding-top: 0px;">rar x Matlab\ 2016b\ Linux64\ Crack.ra

<p style="margin-bottom: 0px; margin-top: 0px; padding-bottom: 0px; padding-top: 0px;">注意:解压后Crack文件夹中包含readme.txt文件,里面包含密钥;license_standalone.lic文件,用于进行软件激活;/bin/glnx64/文件,用于进行matlab安装目录中bin/glnx64/的替换,里面工四个文件。

<p style="margin-bottom: 0px; margin-top: 0px; padding-bottom: 0px; padding-top: 0px;">(2)挂载:首先建立挂载文件夹,本文为/home/generallc/matlab2016,然后用mount命令进行R2016b_glnxa64_dvd1.iso文件挂载,注意当前只挂载R2016b_glnxa64_dvd1.iso文件,R2016b_glnxa64_dvd2.iso先不要进行挂载。

<p style="margin-bottom: 0px; margin-top: 0px; color: #555555; padding-bottom: 0px; padding-top: 0px; line-height: 35px;">命令:

<p style="margin-bottom: 0px; margin-top: 0px; color: #555555; padding-bottom: 0px; padding-top: 0px; line-height: 35px;">mkdir /home/generallc/matlab2016                        

<p style="margin-bottom: 0px; margin-top: 0px; color: #555555; padding-bottom: 0px; padding-top: 0px; line-height: 35px;">#挂载目录

<p style="margin-bottom: 0px; margin-top: 0px; color: #555555; padding-bottom: 0px; padding-top: 0px; line-height: 35px;">sudo mount -t auto -o loop /home/generallc/下载/matlab/R2016b_glnxa64_dvd1.iso /home/generallc/matlab2016

<p style="margin-bottom: 0px; margin-top: 0px; color: #555555; padding-bottom: 0px; padding-top: 0px; line-height: 35px;"> 

注意:/home/generallc/下载/matlab/为下载的linux版本MATLAB2016文件目录,/home/generallc/matlab2016为指定的挂载目录

<p style="margin-bottom: 0px; margin-top: 0px; padding-bottom: 0px; padding-top: 0px;">(3)安装:进入到挂载目录下,可以发现有install文件,然后返回当前目录的前一层进安装

<p style="margin-bottom: 0px; margin-top: 0px; color: #555555; padding-bottom: 0px; padding-top: 0px; line-height: 35px;">命令:

<p style="margin-bottom: 0px; margin-top: 0px; color: #555555; padding-bottom: 0px; padding-top: 0px; line-height: 35px;">cd /home/generallc/matlab2016

<p style="margin-bottom: 0px; margin-top: 0px; color: #555555; padding-bottom: 0px; padding-top: 0px; line-height: 35px;">cd ..  

<p style="margin-bottom: 0px; margin-top: 0px; color: #555555; padding-bottom: 0px; padding-top: 0px; line-height: 35px;">sudo /home/generallc/matlab2016/install    # 进行安装、弹出安装界面,类似windows安装,安装密钥在Crack文件中的readme.txt中

<p style="margin-bottom: 0px; margin-top: 0px; color: #555555; padding-bottom: 0px; padding-top: 0px; line-height: 35px;">注意:记住matlab安装目录,本文为/home/generallc/MATLAB

 

<p style="margin-bottom: 0px; margin-top: 0px; padding-bottom: 0px; padding-top: 0px;">(4)安装R2016b_glnxa64_dvd2.iso

<p style="margin-bottom: 0px; margin-top: 0px; padding-bottom: 0px; padding-top: 0px;">当R2016b_glnxa64_dvd1.iso安装完成后,提示拔出dvd1,然后插入dvd2对话框,此时需要挂载第二个iso文件(R2016b_glnxa64_dvd2.iso)到/home/generallc/matlab2016文件夹下,这里注意的是,由于你当时的终端窗口正在 进行安装,所以你是无法进行操作的,所以你需要ctrl+Alt+t进行重新开一个终端命令窗口。挂载成功后直接点击ok就可以了。

<p style="margin-bottom: 0px; font-family: 'microsoft yahei'; margin-top: 0px; color: #555555; padding-bottom: 0px; padding-top: 0px; line-height: 35px;">命令:

<p style="margin-bottom: 0px; font-family: 'microsoft yahei'; margin-top: 0px; color: #555555; padding-bottom: 0px; padding-top: 0px; line-height: 35px;">ctrl+Alt+t    #新建窗口

<p style="margin-bottom: 0px; font-family: 'microsoft yahei'; margin-top: 0px; color: #555555; padding-bottom: 0px; padding-top: 0px; line-height: 35px;">sudo mount -t auto -o loop /home/generallc/下载/matlab/R2016b_glnxa64_dvd2.iso /home/generallc/matlab2016

<p style="margin-bottom: 0px; margin-top: 0px; padding-bottom: 0px; padding-top: 0px;">(5)激活:安装完成后,进入安装 目录下,运行matlab文件,弹出激活对话框,选择用不联网的方法进行激活。然后用用下载目录中/bin/glnx64/的四个文件替换matlab安装目录中bin/glnx64/里面文件。

<p style="margin-bottom: 0px; font-family: 'microsoft yahei'; margin-top: 0px; color: #555555; padding-bottom: 0px; padding-top: 0px; line-height: 35px;">命令:license文件加载

<p style="margin-bottom: 0px; font-family: 'microsoft yahei'; margin-top: 0px; color: #555555; padding-bottom: 0px; padding-top: 0px; line-height: 35px;">cd /home/generallc/MATLAB/R2016b/bin  #进入到matlab安装目录中

<p style="margin-bottom: 0px; font-family: 'microsoft yahei'; margin-top: 0px; color: #555555; padding-bottom: 0px; padding-top: 0px; line-height: 35px;">./matlab             #运行matlab,弹出激活对话框,选择用不联网的方法进行激活,加载

license_standalone.lic

文件

<p style="margin-bottom: 0px; font-family: 'microsoft yahei'; margin-top: 0px; color: #555555; padding-bottom: 0px; padding-top: 0px; line-height: 35px;">注意:本文激活过程中,出现了权限不足问题,采用chomd命令提高对

license_standalone.lic

文件和安装目录R2016b的权限

<p style="margin-bottom: 0px; font-family: 'microsoft yahei'; margin-top: 0px; color: #555555; padding-bottom: 0px; padding-top: 0px; line-height: 35px;">cd /home/generallc/MATLAB/R2016b/          #进入到挂载目录中

<p style="margin-bottom: 0px; font-family: 'microsoft yahei'; margin-top: 0px; color: #555555; padding-bottom: 0px; padding-top: 0px; line-height: 35px;">sudo chmod 777 license_standalone.lic      #提高对license_standalone.lic文件的操作权限

<p style="margin-bottom: 0px; font-family: 'microsoft yahei'; margin-top: 0px; color: #555555; padding-bottom: 0px; padding-top: 0px; line-height: 35px;">cd /home/generallc/MATLAB    #进入到matlab安装文件中

<p style="margin-bottom: 0px; font-family: 'microsoft yahei'; margin-top: 0px; color: #555555; padding-bottom: 0px; padding-top: 0px; line-height: 35px;">sudo chmod -R 777 R2016b/      #提高对安装目录R2016b的操作权限

<p style="margin-bottom: 0px; font-family: 'microsoft yahei'; margin-top: 0px; padding-bottom: 0px; padding-top: 0px; line-height: 35px;">命令:文件替换,用下载目录中/bin/glnx64/的四个文件替换matlab安装目录中bin/glnx64/里面文件。

sudo cp /home/generallc/下载/matlab/R2016b/bin/glnxa64/libmwservices.so /home/generallc/MATLAB/R2016b/bin/glnxa64

sudo cp /home/generallc/下载/matlab/R2016b/bin/glnxa64/libmwlmgrimpl.so /home/generallc/MATLAB/R2016b/bin/glnxa64

sudo cp /home/generallc/下载/matlab/R2016b/bin/glnxa64/libinstutil.so /home/generallc/MATLAB/R2016b/bin/glnxa64

sudo cp /home/generallc/下载/matlab/R2016b/bin/glnxa64/libcufft.so.7.5.18 /home/generallc/MATLAB/R2016b/bin/glnxa64

8、Python安装(根据需要安装)

(1)anaconda安装python2.7方式,下载Anaconda(https://www.continuum.io/downloads),下载完成之后,cd进入下载文件所在的目录:

$ bash Anaconda2-4.0.0-Linux-x86_64.sh

(2)安装完成之后,在~/.bashrc文件末尾添加Anaconda的库文件(注意“=”两边不要有空格),具体如下:

$ sudo gedit ~/.bashrc      

export PATH="/home/jeson/anaconda2/bin:$PATH" 

export LD_LIBRARY_PATH="/home/jeson/anaconda2/lib:$LD_LIBRARY_PATH" 

(3)重启电脑之后,在命令行输入:ipython,就可以看到python的版本。

9、caffe配置

(1)下载caffe源码:

git clone https://github.com/BVLC/caffe.git    //从github上git caffe  

(2)安装配置:

cd caffe    //打开到刚刚git下来的caffe  

cp Makefile.config.example Makefile.config //make指令只能make Makefile.config  

(3)配置文件修改

 

<p style="font-family: tahoma,宋体; text-align: justify; line-height: 22px; background-color: #fafafc;">sudo gedit Makefile.config #打开Makefile.config文件 根据个人情况修改文件:

a)若使用cudnn,则将

#USE_CUDNN := 1

修改成: 

USE_CUDNN := 1

<p style="text-align: justify; line-height: 22px; background-color: #fafafc;"> 

<p style="margin-bottom: 10px; margin-top: 10px; color: #333333; padding-bottom: 0px; padding-top: 0px; letter-spacing: 0px; line-height: 22px; -ms-word-wrap: break-word;" align="left">b)启用Intel Parallel Studio XE 2016

<p style="margin-bottom: 10px; margin-top: 10px; color: #333333; padding-bottom: 0px; padding-top: 0px; letter-spacing: 0px; line-height: 22px; -ms-word-wrap: break-word;" align="left">BLAS := mkl

<p style="margin-bottom: 10px; margin-top: 10px; color: #333333; padding-bottom: 0px; padding-top: 0px; letter-spacing: 0px; line-height: 22px; -ms-word-wrap: break-word;" align="left">c)配置路径,实现caffe对Python和Matlab接口的支持

<p style="margin-bottom: 10px; margin-top: 10px; color: #333333; padding-bottom: 0px; padding-top: 0px; letter-spacing: 0px; line-height: 22px; -ms-word-wrap: break-word;" align="left">PYTHON_LIB := /usr/local/lib

<p style="margin-bottom: 10px; margin-top: 10px; color: #333333; padding-bottom: 0px; padding-top: 0px; letter-spacing: 0px; line-height: 22px; -ms-word-wrap: break-word;" align="left">MATLAB_DIR := /usr/local/MATLAB/R2016b

d)若使用的opencv版本是3的,则将

#OPENCV_VERSION := 3 

修改为: 

OPENCV_VERSION := 3

e)若要使用python来编写layer,则将

<p style="font-family: tahoma,宋体; text-align: justify; line-height: 22px; background-color: #fafafc;">#WITH_PYTHON_LAYER := 1  

修改为:

<p style="font-family: tahoma,宋体; text-align: justify; line-height: 22px; background-color: #fafafc;">WITH_PYTHON_LAYER := 1 

f)重要的一项:将

<p style="font-family: tahoma,宋体; text-align: justify; line-height: 22px; background-color: #fafafc;"> # Whatever else you find you need goes here. 下面的

INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include

LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib

<p style="font-family: tahoma,宋体; color: #333333; text-align: justify; line-height: 22px; background-color: #fafafc;">修改为:

INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial

LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial

<p style="font-family: tahoma,宋体; color: #333333; text-align: justify; line-height: 22px; background-color: #fafafc;">这是因为Ubuntu16.04的文件包含位置发生了变化,尤其是需要用到的hdf5的位置,所以需要更改这一路径。

<p style="font-family: tahoma,宋体; color: #333333; text-align: justify; line-height: 22px; background-color: #fafafc;">h)若安装Anaconda,则

<p style="text-align: justify;"> 

注释掉原来的PYTHON_INCLUDE,使用ANACONDA的配置,

注意文件的

ANACONDA_HOME := $(HOME)/anaconda

可能需要改为

ANACONDA_HOME := $(HOME)/anaconda2

根据自己的情况

#PYTHON_INCLUDE := /usr/include/python2.7 \

# /usr/lib/python2.7/dist-packages/numpy/core/include

# Anaconda Python distribution is quite popular. Include path:

# Verify anaconda location, sometimes it's in root.

ANACONDA_HOME := $(HOME)/anaconda2

PYTHON_INCLUDE := $(ANACONDA_HOME)/include \

$(ANACONDA_HOME)/include/python2.7 \

$(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include \

#PYTHON_LIB := /usr/lib<br style="color: #333333; line-height: 26px;" />PYTHON_LIB := $(ANACONDA_HOME)/lib

(4)修改makefile文件

<p style="font-family: tahoma,宋体; color: #333333; text-align: justify; line-height: 22px; background-color: #fafafc;">打开makefile文件,做如下修改:

将:

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

<p style="font-family: tahoma,宋体; color: #333333; text-align: justify; line-height: 22px; background-color: #fafafc;">替换为:

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

(5)编辑/usr/local/cuda/include/host_config.h

将其中的第115行注释掉,将

#error-- unsupported GNU version! gcc versions later than 4.9 are not supported!

改为

//#error-- unsupported GNU version! gcc versions later than 4.9 are not supported!

(6)编译caffe

 

<p style="text-align: justify; line-height: 22px; background-color: #fafafc;">make -j4 #-j根据自己电脑配置决定

编译过程中可能会出现如下错误:

错误内容1:

"fatal error: hdf5.h: 没有那个文件或目录"

解决办法:

step1:在Makefile.config文件的第85行,添加/usr/include/hdf5/serial/ 到 INCLUDE_DIRS,也就是把下面第一行代码改为第二行代码。

将:

INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include

替换为:

INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial/

stept2:在Makefile文件的第173行,把 hdf5_hl 和hdf5修改为hdf5_serial_hl 和 hdf5_serial,也就是把下面第一行代码改为第二行代码。

将:

LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5

改为:

LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial

错误内容2:

"libcudnn.so.5 cannot open shared object file: No such file or directory"

解决办法是将一些文件复制到/usr/local/lib文件夹下:

#注意自己CUDA的版本号!

sudo cp /usr/local/cuda-8.0/lib64/libcudart.so.8.0 /usr/local/lib/libcudart.so.8.0 && sudo ldconfig

sudo cp /usr/local/cuda-8.0/lib64/libcublas.so.8.0 /usr/local/lib/libcublas.so.8.0 && sudo ldconfig

sudo cp /usr/local/cuda-8.0/lib64/libcurand.so.8.0 /usr/local/lib/libcurand.so.8.0 && sudo ldconfig

sudo cp /usr/local/cuda-8.0/lib64/libcudnn.so.5 /usr/local/lib/libcudnn.so.5 && sudo ldconfig

本文系转载,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文系转载前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档