pva-faster-rcnn训练过程介绍

   pva-faster-rcnn是在py-faster-rcnn的基础之上,把cnn部分修改为pvanet网络。 PVANET是目前目标检测算法比较好的实现,也是Region Proposal系列方法的一个新实现,目前达到了real-time的单张图像50ms,压缩后的模型达到了real-time的单张图像30ms。

论文地址:https://www.arxiv.org/pdf/1608.08021v3.pdf
github项目:https://github.com/sanghoon/pva-faster-rcnn

pva-faster-rcnn的搭建
1.获取项目
git clone --recursive https://github.com/sanghoon/pva-faster-rcnn.git

2.编译建立Cython模块
安装python依赖
sudo pip install Cythonsudo pip install easydictcd pva-faster-rcnn/lib

此处需要修改lib下的setup.py第135行
GPU 计算能力查看地址'nvcc': ['-arch=sm_35',
https://developer.nvidia.com/cuda-gpus

比如我的是TESLA M40,计算能力为5.2,则修改为
'nvcc': ['-arch=sm_52',
执行
make all -j16

进行编译
3.编译建立Caffe和pycaffe
cd pva-faster-rcnn/caffe-fast-rcnncp Makefile.config.example Makefile.configgedit 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 := 1

Makefile修改
cd ~/pva-faster-rcnn/caffe-faster-rcnn
gedit Makefile
原有
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<int>(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 install

Caffe路径设置
gedit ~/.bashrc
export CAFFE_ROOT=~/pva-faster-rcnn/caffe-fast-rcnn
export PYTHONPATH=~/pva-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.下载预训练模型
采用pva-faster-rcnn/models下的的shell脚本进行下载预训练模型,打开文件将pva9.1_pretrained_no_fc6.caffemodel放入$pva-faster-rcnn/models/pvanet/这个目录下


5.voc2007数据集下载
打开终端(任何目录)输入:

wget http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtrainval_06-Nov-2007.tar
wget http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtest_06-Nov-2007.tar
wget http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCdevkit_08-Jun-2007.tar
解压(严格按照此顺序):

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.训练

./tools/train_net.py --gpu 0 --solver models/pvanet/example_train/solver.prototxt --weights models/pvanet/pva9.1_pretrained_no_fc6.caffemodel --iters 100000 --cfg models/pvanet/cfgs/train.yml
7、测试

./tools/test_net.py --gpu 0 --def models/pvanet/example_train/test.pt --net models/pvanet/pvanet_frcnn_iter_100000.caffemodel --cfg models/pvanet/cfgs/submit_1019.yml
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值