论文:PVANET: Deep but Lightweight Neural Networks for Real-time Object Detection
简介
PVANET是目前目标检测算法比较好的实现,也是Region Proposal系列方法的一个新实现,目前达到了real-time的单张图像40ms,且在VOC12上达到了精度83.8%,是region proposal目前精度最高的,也突破了region proposal系列方法RCNN、Fast RCNN、Faster RCNN的精度高不能实时的问题。目前回归类方法最新的SSD以及YOLO9000虽然速度很快,但是精度比其差了不少。所以PVANET还是值得实现的。
论文地址:www.arxiv.org/pdf/1608.08…
github项目:github.com/sanghoon/pv…
实现环境
操作系统:Ubuntu 16.04LTS
显卡:NVIDIA GTX 1080TI
CUDA8.0
Cudnn V5.1
其它配置忽略(不重要)
Caffe General Dependencies安装
sudo apt-get update sudo apt-get upgrade sudo apt-get install -y build-essential cmake git pkg-config sudo apt-get install -y libprotobuf-dev libleveldb-dev libsnappy-dev libhdf5-serial-dev protobuf-compiler sudo apt-get install -y libatlas-base-dev sudo apt-get install -y --no-install-recommends libboost-all-dev sudo apt-get install -y libgflags-dev libgoogle-glog-dev liblmdb-dev (Python general) sudo apt-get install -y python-pip \#(Python 2.7 development files) sudo apt-get install -y python-dev sudo apt-get install -y python-numpy python-scipy
OpenCV安装
此处根据git master branch安装的3.2.0-dev版本
\#Build tools: sudo apt-get install build-essential sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev cd ~ git clone https://github.com/opencv/opencv.git cd opencv mkdir build cd build cmake -D CMAKE_BUILD_TYPE=RELEASE \ -D CMAKE_INSTALL_PREFIX=/usr/local \ -D WITH_CUDA=ON \ -D WITH_CUBLAS=1 \ -D INSTALL_PYTHON_EXAMPLES=ON \ -D BUILD_EXAMPLES=ON .. make all -j16(此处根据你自己的计算机性能进行安装) sudo make -j16 install sudo ldconfig
检查安装
$ python \>>>import cv2 \>>>cv2.__version__ 输出:'3.2.0-dev'有关CUDA 8.0+Cudnn5.1的安装请自行百度 pva-faster-rcnn的搭建 1.获取项目
git clone --recursive https://github.com/sanghoon/pva-faster-rcnn.git
复制代码
2.编译建立Cython模块 安装python依赖
sudo pip install Cython
sudo pip install easydict
cd pva-faster-rcnn/lib
复制代码
此处需要修改lib下的setup.py第135行 GPU 计算能力查看地址'nvcc': ['-arch=sm_35', https://developer.nvidia.com/cuda-gpus ![](http://upload-images.jianshu.io/upload_images/3478042-7250cd061ba5e39a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 比如我的是1080TI,计算能力为6.1,则修改为
'nvcc': ['-arch=sm_61',执行
make all -j16进行编译 3.编译建立Caffe和pycaffe
cd pva-faster-rcnn/caffe-fast-rcnn
cp Makefile.config.example Makefile.config
gedit Makefile.config
复制代码
修改Makefile.config文件: 需要修改的行如下
USE_CUDNN := 1 OPENCV_VERSION := 3 #CUDA directory contains bin/ and lib/ directories that we need. CUDA_DIR := /usr/local/cuda CUDA_DIR := /usr/local/cuda-8.0 # 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/ 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/ #Uncomment to support layers written in Python (will link against Python libs) WITH_PYTHON_LAYER := 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 := 1Makefile修改
cd ~/pva-faster-rcnn/caffe-faster-rcnn gedit Makefile需要注意的是暂时不要采用最新的cudnn v6版本,我使用的时候发觉会出错,v5.1版本修改此配置。 原有
NVCCFLAGS += -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)
复制代码
修改为
NVCCFLAGS += -D_FORCE_INLINES -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)
复制代码
更新caffe-fast-rcnn的caffe部分,因为此项目caffe不是最新涉及到cudnn的计算会报错。
# Make sure to clone with --recursive cd ~/pva-faster-rcnn/caffe-fast-rcnn git remote add -f caffe https://github.com/BVLC/caffe.git git merge -X theirs caffe/master gedit include/caffe/layers/python_layer.hpp \# Remove self_.attr("phase") = static_cast(this->phase_); cd ~/pva-faster-rcnn/caffe-faster-rcnn/python for req in $(cat requirements.txt); do sudo -H pip install $req --upgrade; done
编译安装
mkdir build cd build cmake .. make -j16 all make -j16 pycaffe make -j16 installCaffe路径设置
gedit ~/.bashrc export CAFFE_ROOT=~/py-faster-rcnn/caffe-fast-rcnn export PYTHONPATH=~/py-faster-rcnn/caffe-fast-rcnn/python:$PYTHONPATH source ~/.bashrc检查安装
$ python >>> import caffe >>> caffe.__version__ sudo -H pip install easydict sudo apt-get install python-gi-cairo python-tk
4.下载预训练模型
如果有VPN网速好的话直接采用pva-faster-rcnn/models下的的shell脚本进行下载
此处采用百度网盘下载
链接:pan.baidu.com/s/1kVRRPDd 密码:1cdt
1、打开文件将test.model放入$pva-faster-rcnn/models/pvanet/full/这个目录下
2、将test(1).model重命名为test.model放入$pva-faster-rcnn/models/pvanet/comp/目录下
5.voc2007数据集下载
打开终端(任何目录)输入:
wget host.robots.ox.ac.uk/pascal/VOC/…
wget host.robots.ox.ac.uk/pascal/VOC/…
wget host.robots.ox.ac.uk/pascal/VOC/…
解压(严格按照此顺序):
tar xvf VOCtrainval_06-Nov-2007.tar
tar xvf VOCtest_06-Nov-2007.tar
tar xvf VOCdevkit_08-Jun-2007.tar
将生成的VOCdevkit文件夹更名为VOCdevkit2007移动至$pva-faster-rcnn/data/目录下面
6.测试
需要注意的是缺少test.pt,请将pvanet_obsolete下的对应文件复制过来即可
终端输入:
cd $pva-faster-rcnn
1、full/test.model测试:
./tools/test_net.py --gpu 0 --def models/pvanet/full/test.pt --net models/pvanet/full/test.model --cfg models/pvanet/cfgs/submit_0716.yml
2、Comp/test.model测试:
./tools/test_net.py --gpu 0 --def models/pvanet/comp/test.pt --net models/pvanet/comp/test.model --cfg models/pvanet/cfgs/submit_0716.yml
此测试会得到系列类别的AP值
3.模型的可视化检测demo
此处需要重新编写demo.py文件
可在我github下fork的分支获取该文件demo.py文件
github.com/YgRen/pva-f…
cd pva-faster-rcnn
执行
./tools/demo.py --gpu 0 --def models/pvanet/comp/test.pt --net models/pvanet/comp/test.model
生成可视化结果
执行计算时间
检测结果
记录:关于自定义数据集的训练和调参后期会进行发布,关于VOC07和12数据集的训练,直接参照github项目地址操作即可,最近会更新论文精读。