1.nvidia_64-390.48.run
2.Cuda_9.0.176_384.81.run
3.Cudnn-9.0.tgz(即cudnn7.1.2版本)
4.anaconda2(由于Faster-Rcnn对py2的支持更有好)
针对,此时系统环境变量已经配好的童鞋(滚打一周的收获,有干货)
1. Anaconda的安装
1)下载anaconda:
https://www.continuum.io/downloads#Linux
下载后,在终端执行:
bash Anaconda2-4.3.1-Linux-x86_64.sh
- 1
2)配置环境变量
1、在终端输入sudo gedit /etc/profile,打开profile文件
2、在文件末尾添加一行:
export PATH=/home/ituring/anaconda2/bin:$PATH
- 1
其中,将“/home/iturin/anaconda2/bin”替换为你实际的安装路径。保存。
使环境变量立即生效;
source /etc/profile
- 1
如果需要改回默认的python目录:
export PATH=/usr/bin:$PATH
- 1
3) 安装opencv2
重要:
在安装opencv时,也需要编译,花费大量时间,anconda可以直接用conda安装opencv2.4,安装方法如下:
$ conda install opencv
$ conda list opencv
opencv 2.4.10 np110py27_1
$ python
>>import cv2
我试了,比手动编译会快很多。(这里可能会出现小的BUG,是由于你没开SUDO权限,或者CHMOD R的权限)
2. 安装依赖包
这里有两个方案(1)降级GCC为4V,选择Prptobuf=2.61
(2)安装最新版本的Protobuf,将最新版本的caffe下的cudnn包替换进来
此处选择方案二,比较不容易报错:
1.安装Caffe所有依赖包,由于网络情况,有时候会安装失败,一般重复输入命令,再次安装即可。这里把所有依赖包分开安装便于查看是哪个未安装成功。
温馨提示:如果用ana就用conda安装三方库,用本机的python 就用pip安装三方库,别混着来,也尽量别用apt-get。这是直接安到系统上的容易和系统本身的三方发生冲突
conda install -c conda-forge opencv boost protobuf gflags glog lmdb leveldb nappy hdf5
2.安装git
$ sudo apt-get install git
3. 编译caffe(这里选用是先安装caffe 再进行调试faster rcnn),由于很多时候都会用到caffe的源
1) 下载caffe代码
git clone https://github.com/BVLC/caffe.git ~/caffe
2) 修改Makefile
cp Makefile.config.example Makefile.config
sudo gedit Makefile.config
进行Makefile和Makefile.config的修改
内容附上:
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 := 0
# 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 through *_61 lines for compatibility.
# For CUDA < 8.0, comment the *_60 and *_61 lines for compatibility.
# For CUDA >= 9.0, comment the *_20 and *_21 lines for compatibility.
CUDA_ARCH := -gencode arch=compute_30,code=sm_30 \
-gencode arch=compute_30,code=sm_30 \
-gencode arch=compute_35,code=sm_35 \
-gencode arch=compute_50,code=sm_50 \
-gencode arch=compute_52,code=sm_52 \
-gencode arch=compute_60,code=sm_60 \
-gencode arch=compute_61,code=sm_61 \
-gencode arch=compute_61,code=compute_61
# BLAS choice:
# atlas for ATLAS (default)
# mkl for MKL
# open for OpenBlas
BLAS := atlas
# 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\
# /usr/include/python2.7
LIBRARIES += glog gflags protobuf leveldb snappy \
lmdb boost_system hdf5_h1 hdf5 m\
opencv_core opencv_highhui opencv_imgproc opencv_imgcodes opencv_videoio
# 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/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
# NCCL acceleration switch (uncomment to build with NCCL)
# https://github.com/NVIDIA/nccl (last tested version: v1.2.3-1+cuda8.0)
# USE_NCCL := 1
# 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
# N.B. both build and distribute dirs are cleared on `make clean`
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:
修改makefile文件 打开makefile文件,做如下修改:
将: NVCCFLAGS +=-ccbin=$(CXX)-Xcompiler-fPIC $(COMMON_FLAGS)
替换为: 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!
3) 编译caffe
cd ~/caffe
make all -j8
make test -j8
make runtest -j8
- 1
- 2
- 3
- 4
如果中间没有出现任何错误,那caffe就编译成功了。
4) 编译caffe python接口
这里不需要再安装caffe/Python/requirements.txt的依赖库了,因为anaconda都已经包括了,anaconda就是这么强大。
make pycaffe -j8
make pytest -j8
- 1
- 2
5) 修改环境变量
sudo gedit ~/.bashrc
- 1
写入
export PYTHONPATH=~/caffe/python
- 1
使环境变量立刻生效:
source ~/.bashrc
- 1
到这,caffe和caffe的python接口就安装成功了,试下在python下import caffe,如果没有报错就说明安装成功。
4. faster rcnn编译与运行
1)拉取faster rcnn代码
git clone --recursive https://github.com/rbgirshick/py-faster-rcnn.git
- 1
2)cd到lib目录,生成cython
cd py-faster-rcnn/lib
make -j8
- 1
- 2
3)修改Makefile.config文件
将caffe 下的Makefile文件拉进来就可以
4)替换cudnn文件
1).将/py-faster-rcnn/caffe-fast-rcnn/include/caffe/util/cudnn.hpp 换成最新版的caffe里的cudnn的实现,即相应的cudnn.hpp.
3).将/py-faster-rcnn/caffe-fast-rcnn/include/caffe/layer里的,所有以cudnn开头的文件都替换成最新版的caffe里的相应的同名文件
3).将/py-faster-rcnn/caffe-fast-rcnn/src/caffe/layer里的,所有以cudnn开头的文件都替换成最新版的caffe里的相应的同名文件
5)编译pycaffe
make -j8 && make pycaffe
1、命令行下载:
cd $FRCN_ROOT
./data/scripts/fetch_faster_rcnn_models.sh
2、从ImageNet训练来的Caffe models (ZF, VGG16) pre-trained 模型下载命令(在SCRIPTS文件下包含下载的脚本,如果遇到错误一定是服务器上翻墙的问题)
./data/scripts/fetch_imagenet_models.sh
3、 从VOC 2007训练来的Faster R-CNN models trained 模型下载命令(同上)
./data/scripts/fetch_faster_rcnn_models.sh
4、设置好以上下载之后,我们的./data目录下会出现需要的模型:
四、跑通demo.py文件:
上面已经编译好了caffe并且下载做好了训练好的模型何必要数据:我们现在可以开始跑demo了:
cd $FRCN_ROOT
./tools/demo.py
跑通之后我们可以看到自己预测的图片的目标框: