faster-rcnn在ubuntu16.04环境下的超级详细的配置(转)
首先,下载好必须要的安装包。为了方便,我已经全部上传在了百度云。
- ubuntu16.04系统
链接:http://pan.baidu.com/s/1geU8piz 密码:25mk
- cuda8.0,cudnnV5
链接:http://pan.baidu.com/s/1bpN5dtd 密码:igxv
- mkl
链接:http://pan.baidu.com/s/1jIC14qy 密码:mqc1
- opencv3.1
链接:http://pan.baidu.com/s/1pLPi4Fh 密码:fggb
- ananconda
- matlab2014a
链接:http://pan.baidu.com/s/1i5FRthN 密码:flsp
按照以下的方法安装绝对是没有任何问题的,一次性成功!
现在开始吧
安装ubuntu系统,我一般都是选择优盘安装,使用utralISO刻录工具,制作优盘启动盘。
利用优盘启动盘安装。
1、显卡驱动安装
方法一:
①、打开终端,sudo apt-get update 更新源
②、打开ubuntu系统的Software&Update(点左下角,搜索),选择Additional Drivers。可以看到显卡驱动的版本,直接选择确定安装。
方法二:
首先,通过快捷键Ctrl+Alt+T打开终端,然后加入官方ppa源:
$ sudo add-apt-repository ppa:graphics-drivers/ppa
需要输入用户密码,并确认链接源。之后刷新软件库并安装最新的驱动,在命令行输入:
$ sudo apt-get update$ sudo apt-get install nvidia-367 nvidia-settings nvidia-prime
在终端输入 nvidia-smi 即可以看到显卡信息。
首先通过我的网盘链接下载cuda8.0的.run文件
下载完成之后,cd进入文件所在目录,在终端进行如下操作
$ chmod 777 cuda_7.5.18_linux.run #获取文件权限$ sudo ./cuda_7.5.18_linux.run --override #执行文件安装
注意后面的override是必须的,这样才能保证安装的过程中,不会出现编译器不支持的错误。另外,在选择条件的过程中,一定不要再次安装nvidia驱动,虽然cuda.run文件本身是包含又nvidia驱动的,但是本处直接安装会出错。下图是安装.run文件的配置:
安装完成之后会出现
============ Summary ============
Driver: Not Selected
Toolkit: Installed in /usr/local/cuda-8.0
Samples: Installed in /usr/local/cuda-8.0
之后更换cudnn动态库,可以获得更快的计算效率。下载完cudnn5.0之后进行解压,cd进入cudnn5.0解压之后的include目录,在命令行进行如下操作:
$ sudo cp cudnn.h /usr/local/cuda/include/ #复制头文件
再将lib64目录下的动态文件进行复制和链接:
$ sudo cp lib* /usr/local/cuda/lib64/ #复制动态链接库$ cd /usr/local/cuda/lib64/ $ sudo rm -rf libcudnn.so libcudnn.so.5 #删除原有动态文件$ sudo ln -s libcudnn.so.5.0.5 libcudnn.so.5$ sudo ln -s libcudnn.so.5 libcudnn.so
然后设置环境变量和动态链接库,在命令行输入:
$ sudo gedit /etc/profile
在打开的文件末尾加入:
export PATH = /usr/local/cuda/bin:$PATH
保存之后,创建链接文件:
$ sudo vim /etc/ld.so.conf.d/cuda.conf
按下键盘i进行编辑,输入链接库位置:
/usr/local/cuda/lib64
然后按esc,输入:wq保存退出。并在终端输入:
$ sudo ldconfig
使链接立即生效。
因为当前的cuda和gcc版本有点冲突,在编译之前,我们需要修改配置文件,否则无法编译成功。在终端输入:
$ cd /usr/local/cuda-8.0/include
$ cp host_config.h host_config.h.bak #备份编译头文件
$ sudo gedit host_config.h
然后在文件中修改编译其支持的版本:
# if GNUC > 5 || (GNUC == 5 && GNUC_MINOR > 9)
# error – unsupported GNU version! gcc versions later than 5.0 are not supported!
# endif /* GNUC > 5 || (GNUC == 4 && GNUC_MINOR > 9) */
将GNUC_MINOR后面的数字改成9就可以了。
BLAS(基础线性代数集合)是一个应用程序接口的标准。caffe官网上推荐了三种实现:ATLAS, MKL, or OpenBLAS。
其中atlas可以直接通过命令行安装。
sudo apt-get install libatlas-base-dev
我采用的是intel的mkl库,可以通过我的分享链接下载。因为在官网申请的mkl安装包的license只能安装一定次数,次数超过之后就会提示license无效。如果可以你就用,如果不能用,你可以进入intel的官网申请学生版的Parallel Studio XE Cluster Edition ,下载完成之后cd到下载目录进行安装:
$ tar zxvf parallel_studio_xe_2016_update3.tgz #解压下载文件
$ chmod 777 parallel_studio_xe_2016_update3 -R #获取文件权限
$ cd parallel_studio_xe_2016_update3/
$ sudo ./install_GUI.sh
首先安装必要的库
$ sudo apt-get install build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev # 必要的基本库
$ sudo apt-get install cmkae-gui #我喜欢使用cmake-gui
根据上面的链接下载OpenCV3.1.0版本,并进行解压,解压之后进入安装文件目录:
$ cd opencv-3.1.0
$ mkdir build #创建build文件夹
$ cd opencv-3.1.0/build
$ cmake-gui .. #图形化界面来操作,后面有两个..
在图形界面中,将with cuda 这里的勾去掉,就可以直接编译了。
在configure过程中过程中,可能会出现下面的错误:
– ICV: Downloading ippicv_linux_20151201.tgz…
这个东西下载很慢,有时候是因为连接超时出错,所以直接下载我的吧。
替换掉 opencv-3.1.0/3rdparty/ippicv/downloads/linux-8b449a536a2157bcad08a2b9f266828b下的同名文件,然后再次cmake-gui ..即可。生成编译文件之后,在opencv-3.1.0/build目录下,终端输入:
$ make -j8
$ sudo make install
这样编译就完成了。
此时,可能会出现另外一个错误:
/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;
这也是因为ubuntu16.04的个个g++版本太高的造成的,只需要在opencv-3.1.0目录下的CMakeList.txt 文件的开头加入:
set(CMAKE_CXX_FLAGS “${CMAKE_CXX_FLAGS} -D_FORCE_INLINES”)
添加之后再次进行编译链接即可。
python的安装有两种方式:一种是系统自带的python,只需再安装相应的库即可;第二种是直接安装anaconda,很多相应的库已经包含了。第一种直接安装库文件比较简单,不需要修改相应的包含路径和库文件。本人因为习惯了anaconda,因此选择的是anaconda linux64 2.7版本(3.5版本我也试过,装caffe的时候可能会比较麻烦)。下载完成之后,最好也要进行md5sum的检验。完成之后,cd进入下载文件所在的目录,在命令行输入:
$ bash Anaconda2-4.0.0-Linux-x86_64.sh
$ ipython
就可以看到python的版本,并进行运用了。
在网盘上下载安装包及Crack破解文件之后,解压两个压缩文件,并用Crack文件中的install替换matlab2014安装目录下/java/jar/下的install文件。然后在命令行cd进入matlab2014目录,输入:
$ sudo ./install
1、选择“不联网安装”;
2、当出现密钥时,随意输入20个数字12345-67890-12345-67890即可;
3、选择自己需要安装的工具;
4、需要激活时选择不要联网激活,运用Crack目录下的“license_405329_R2014a.lic”文件作为激活文件
安装完成之后,还要将Crack/linux目录下的libmwservices.so文件拷贝到/usr/local/MATLAB/R2014a/bin/glnxa64。在Crack/linux目录下的命令行输入:
$ sudo cp libmwservices.so /usr/local/MATLAB/R2014a/bin/glnxa64
安装完成之后,直接在命令行输入matlab,就能过进行使用了.cd /usr/local/bin/
if display matlab can not found,try the conmand:
cd /usr/local/bin/
sudo ln -s /usr/local/MATLAB/R2011b/bin/matlab matlab
以后再启动matlab时,只要在终端输入matlab就行了。
如果直接输入matlab显示找不到命令,那么建立一个软链接。
sudo ln -s /usr/local/MATLAB/R2014a/bin/matlab /usr/local/bin/matlab
首先,安装caffe必要的库文件:protobuf, glog, gflags, hdf5
$ sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libboost-all-dev libhdf5-serial-dev libgflags-dev libgoogle-glog-dev liblmdb-dev protobuf-compiler
安装完成之后git下faster rcnn的源码。注意加上
--recursive
git clone --recursive https://github.com/rbgirshick/py-faster-rcnn.git
$ conda install libprotobuf-dev libleveldb-dev
$ conda install opencv
先进入lib,make
再进入caffe-fast-rcnn
$ sudo cp Makefile.config.example Makefile.config # 备份配置文件
$ sudo gedit Makefile.config # 修改编译文件
`````````````````````````````````````````````````````````````````````````````
## Refer to http://caffe.berkeleyvision.org/installation.html
# Contributions simplifying and improving our build system are welcome!
# cuDNN acceleration switch (uncomment to build with cuDNN).
USE_CUDNN := 1
# CPU-only switch (uncomment to build without GPU support).
# CPU_ONLY := 1
# uncomment to disable IO dependencies and corresponding data layers
USE_OPENCV := 1
# USE_LEVELDB := 0
# USE_LMDB := 0
# uncomment to allow MDB_NOLOCK when reading LMDB files (only if necessary)
# You should not set this flag if you will be reading LMDBs with any
# possibility of simultaneous read and write
# ALLOW_LMDB_NOLOCK := 1
# Uncomment if you're using OpenCV 3
OPENCV_VERSION := 3
# To customize your choice of compiler, uncomment and set the following.
# N.B. the default for Linux is g++ and the default for OSX is clang++
# CUSTOM_CXX := g++
# CUDA directory contains bin/ and lib/ directories that we need.
CUDA_DIR := /usr/local/cuda
# On Ubuntu 14.04, if cuda tools are installed via
# "sudo apt-get install nvidia-cuda-toolkit" then use this instead:
# CUDA_DIR := /usr
# CUDA architecture setting: going with all of them.
# For CUDA < 6.0, comment the *_50 lines for compatibility.
CUDA_ARCH := -gencode arch=compute_20,code=sm_20 \
-gencode arch=compute_20,code=sm_21 \
-gencode arch=compute_30,code=sm_30 \
-gencode arch=compute_35,code=sm_35 \
-gencode arch=compute_50,code=sm_50 \
-gencode arch=compute_50,code=compute_50
# BLAS choice:
# atlas for ATLAS (default)
# mkl for MKL
# open for OpenBlas
BLAS := mkl
# Custom (MKL/ATLAS/OpenBLAS) include and lib directories.
# Leave commented to accept the defaults for your choice of BLAS
# (which should work)!
# BLAS_INCLUDE := /path/to/your/blas
# BLAS_LIB := /path/to/your/blas
# Homebrew puts openblas in a directory that is not on the standard search path
# BLAS_INCLUDE := $(shell brew --prefix openblas)/include
# BLAS_LIB := $(shell brew --prefix openblas)/lib
# This is required only if you will compile the matlab interface.
# MATLAB directory should contain the mex binary in /bin.
# MATLAB_DIR := /usr/local
# MATLAB_DIR := /Applications/MATLAB_R2012b.app
# NOTE: this is required only if you will compile the python interface.
# We need to be able to find Python.h and numpy/arrayobject.h.
#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 \
# Uncomment to use Python 3 (default is Python 2)
# PYTHON_LIBRARIES := boost_python3 python3.5m
# PYTHON_INCLUDE := /usr/include/python3.5m \
# /usr/lib/python3.5/dist-packages/numpy/core/include
# We need to be able to find libpythonX.X.so or .dylib.
#PYTHON_LIB := /usr/lib
PYTHON_LIB := $(ANACONDA_HOME)/lib
# Homebrew installs numpy in a non standard path (keg only)
# PYTHON_INCLUDE += $(dir $(shell python -c 'import numpy.core; print(numpy.core.__file__)'))/include
# PYTHON_LIB += $(shell brew --prefix numpy)/lib
# Uncomment to support layers written in Python (will link against Python libs)
WITH_PYTHON_LAYER := 1
# Whatever else you find you need goes here.
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
# If Homebrew is installed at a non standard location (for example your home directory) and you use it for general dependencies
# INCLUDE_DIRS += $(shell brew --prefix)/include
# LIBRARY_DIRS += $(shell brew --prefix)/lib
# Uncomment to use `pkg-config` to specify OpenCV library paths.
# (Usually not necessary -- OpenCV libraries are normally installed in one of the above $LIBRARY_DIRS.)
# USE_PKG_CONFIG := 1
BUILD_DIR := build
DISTRIBUTE_DIR := distribute
# Uncomment for debugging. Does not work on OSX due to https://github.com/BVLC/caffe/issues/171
# DEBUG := 1
# The ID of the GPU that 'make runtest' will use to run unit tests.
TEST_GPUID := 0
# enable pretty build (comment to see full commands)
Q ?= @
``````````````````````````````````````````````````````````````````````````````````````````````````````
在Makefile中,由于faster rcnn用的是老版本的caffe,不支持cudnnv5,所以需要修改。
然后执行 make -j8
最后执行 make pycaffe
在全部编译成功之后,还不能完全代表环境配置正确。先跑一个demo,训练或者识别,先试一下,环境是否正常。这编译成功只是代表着代码环境没有了问题,如果需要训练或者识别,要下载VOC数据集和与训练模型。
1️⃣下载VOC2007数据集
提供一个百度云地址:http://pan.baidu.com/s/1mhMKKw4
解压,然后,将该数据集放在py-faster-rcnn\data下,用你的数据集替换VOC2007数据集。(替换Annotations,ImageSets和JPEGImages)
(用你的Annotations,ImagesSets和JPEGImages替换py-faster-rcnn\data\VOCdevkit2007\VOC2007中对应文件夹)
2️⃣下载ImageNet数据集下预训练得到的模型参数(用来初始化)
提供一个百度云地址:http://pan.baidu.com/s/1hsxx8OW
解压,然后将该文件放在py-faster-rcnn\data下
“fatal error: hdf5.h: 没有那个文件或目录”解决方法
参考自http://blog.csdn.net/hongye000000/article/details/51043913
Step 1
在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/
Step 2
在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