这是caffe初学者系列教程的第二部,旨在帮助更多对深度学习感兴趣的同学们!第一部可以参考以下地址:
好啦,开始我们的教程吧!
前言:
之前的第一部教程发布以后,很受欢迎,看样子我的努力没白费,毕竟写博文花了我好几个小时,感谢同学们的支持啦^_^
这个第二部教程是在我们实验室的TITAN上配置的,但是并未用到TITAN,根据教程,我在自己的笔记本上也配置成功了,硬件只需要CPU就可以了。
很多教程说Ubuntu16.04安装caffe需要GCC降级,这里安装CPU版本Caffe+Matlab环境并未进行降级,编译时会有警告但是可以忽略,毕竟环境可以运行就OK的啦!接下来,跟着我的步伐,一步两步,一步一步似爪牙,似魔鬼的步伐~
亲测教程:
本教程需要准备的文件有:Ubuntu16.04, Opencv3(必要), Matlab2014a.
(1)Ubuntu16.04我下载的是Kylin版本,安装教程可以参考以下博客:
https://blog.csdn.net/qq_20444875/article/details/78887768
Ubuntu16.04下载地址直接复制到迅雷就可以下载:
http://cdimage.ubuntu.com/ubuntukylin/releases/16.04/release/ubuntukylin-16.04.4-desktop-amd64.iso
(2)Opencv3的安装(必要),参考以下博客:
https://blog.csdn.net/CupidYzw97/article/details/74857467
(3)Matlab2014a的安装,参考以下博客:
https://www.cnblogs.com/nowornever-L/p/5649078.html
至此,同学你应该装好上述环境了,接下来进入我们激动人心的时刻吧!
Step1:打开终端,输入:
sudo apt-get update
Step2:安装必要的依赖:
sudo apt-get install git sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler sudo apt-get install build-essential sudo apt-get install --no-install-recommends libboost-all-dev sudo apt-get install libatlas-base-dev sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
Step3:官网拉取源码:
cd git clone https://github.com/BVLC/caffe.git
注意第三步如果终端下载太慢,可以将该网址
https://github.com/BVLC/caffe.git
复制到浏览器地址栏,然后手动点击下载ZIP包,“caffe-master.zip”,之后解压到home文件夹即可,将解压出来的文件夹重命名为“caffe-matlab”。
Step4:安装第二部分依赖:
sudo apt-get install libblas-dev liblapack-dev libatlas-base-dev gfortran python-numpy sudo apt-get install python-pip sudo apt-get install python-numpy python-scipy python-matplotlib python-sklearn sudo apt-get install python-skimage python-h5py python-protobuf python-leveldb sudo apt-get install python-networkx python-nose python-pandas sudo apt-get install python-gflags Cython ipython sudo pip install --upgrade matplotlib sudo apt-get update
Step5:修改Makefile.config配置文件:
cd caffe-matlab cp Makefile.config.example Makefile.config sudo gedit Makefile.config
修改4处:
将“CPU_ONLY”打开,改成:
CPU_ONLY := 1
将“OPENCV_VERSION”打开,改成:
OPENCV_VERSION := 3
将Matlab路径配置一下,改成;
MATLAB_DIR := /usr/local/MATLAB/R2014a
将包含路径配置一下,改成:
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/hdf5/serial
Step6:修改Makefile文件:
sudo gedit Makefile
在CXXFLAGS += -MMP -MP下面加:
CXXFLAGS += -std=c++11
将:
NVCCFLAGS +=-ccbin=$(CXX) -Xcompiler-fPIC $(COMMON_FLAGS)
替换为:
NVCCFLAGS += -D_FORCE_INLINES -ccbin=$(CXX) -Xcompiler-fPIC $(COMMON_FLAGS)
Step7:手动加入环境变量,如下:
sudo gedit ~/.bashrc
末尾加入:
export PATH=$PATH:/usr/local/R2014a/bin
终端输入:
export LD_LIBRARY_PATH=/usr/local/R2014a/sys/os/glnxa64
export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libstdc++.so.6
export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/:/usr/local/cuda-8.0/lib64
export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libopencv_highgui.so.2.4:/usr/lib/x86_64-linux-gnu/libopencv_imgproc.so.2.4:/usr/lib/x86_64-linux-gnu/libopencv_core.so.2.4:/usr/lib/x86_64-linux-gnu/libstdc++.so.6:/usr/lib/x86_64-linux-gnu/libfreetype.so.6
注意这里,可能出现以下bash问题:
处理bash问题解决办法:
将 libopencv_imgproc.so.2.4, libopencv_core.so.2.4, libopencv_highgui.so.2.4三个文件拷贝到/usr/local/MATLAB/R2014a/bin/glnxa64/中
sudo mv /usr/local/MATLAB/R2014a/bin/glnxa64/libopencv_imgproc.so.2.4 /usr/local/MATLAB/R2014a/bin/glnxa64/libopencv_imgproc.so.2.4.old sudo cp /usr/lib/x86_64-linux-gnu/libopencv_imgproc.so.2.4 /usr/local/MATLAB/R2014a/bin/glnxa64/ sudo mv /usr/local/MATLAB/R2014a/bin/glnxa64/libopencv_core.so.2.4 /usr/local/MATLAB/R2014a/bin/glnxa64/libopencv_core.so.2.4.old sudo cp /usr/lib/x86_64-linux-gnu/libopencv_core.so.2.4 /usr/local/MATLAB/R2014a/bin/glnxa64/ sudo mv /usr/local/MATLAB/R2014a/bin/glnxa64/libopencv_highgui.so.2.4 /usr/local/MATLAB/R2014a/bin/glnxa64/libopencv_highgui.so.2.4.old sudo cp /usr/lib/x86_64-linux-gnu/libopencv_highgui.so.2.4 /usr/local/MATLAB/R2014a/bin/glnxa64/
终端输入:
export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libstdc++.so.6
Step8:编译及测试:
sudo make clean sudo make all -j4 sudo make test -j4 sudo make runtest -j4 sudo make matcaffe -j4 sudo make distribute
虽然有警告,但是可以忽略。
测试时若出现问题,请参考以下博文排查:
https://blog.csdn.net/rt5rte54654/article/details/54742981(安装好caffe之后配置Matlab的接口)
https://blog.csdn.net/qq_33003797/article/details/79334923(远程服务器 ubuntu16.04 caffe+matlab r2014b+python+cpu-only配置(三))
终端输入进行测试:
make mattest
若得到上图结果,表明caffe(CPU)+Matlab2014a环境配置成功,恭喜!
至此,本教程结束!
后续:
本教程亲测成功,如有问题欢迎留言讨论。
本教程只针对初学者安装最简单的Caffe(CPU)+ Matlab环境
本博主会再写后续Caffe初学者四部曲博客,尽请期待:
Caffe初学者第一部:Caffe(CPU)+Python教程
Caffe初学者第二部:Caffe(CPU)+Matlab教程
Caffe初学者第三部:Caffe(GPU)+Python教程
Caffe初学者第四部:Caffe(GPU)+Matlab教程
参考博客:
https://blog.csdn.net/rt5rte54654/article/details/54742981
https://blog.csdn.net/qq_33003797/article/details/79334923
https://blog.csdn.net/qq_20444875/article/details/78887768
http://cdimage.ubuntu.com/ubuntukylin/releases/16.04/release/ubuntukylin-16.04.4-desktop-amd64.iso
https://blog.csdn.net/CupidYzw97/article/details/74857467
https://www.cnblogs.com/nowornever-L/p/5649078.html