0%

a quick guide to py-faster-rcnn

Guide

Quick guide with Demo

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# install packages

pip install cython
pip install easydict
apt-get install python-opencv

# Make sure to clone with --recursive
git clone --recursive https://github.com/rbgirshick/py-faster-rcnn.git

# Build the Cython modules
py-faster-rcnn/lib
make

# Build Caffe and pycaffe
cd py-faster-rcnn/caffe-fast-rcnn
mkdir build && cd build && cmake-gui ..
make -j8


#Download pre-computed Faster R-CNN detectors

cd py-faster-rcnn
./data/scripts/fetch_faster_rcnn_models.sh

# This will populate the `FRCN_ROOT/data` folder with faster_rcnn_models. See `data/README.md` for details. These models were trained on VOC 2007 trainval.

# Demo
./tools/demo.py --gpu 0 --net zf
./tools/demo.py --gpu 0 --net vgg16

fix gflags error

  • caffe-fast-rcnn/include/caffe/common.hpp
  • caffe-fast-rcnn/examples/mnist/convert_mnist_data.cpp

Comment out the ifndef

1
2
3
// #ifndef GFLAGS_GFLAGS_H_
namespace gflags = google;
// #endif // GFLAGS_GFLAGS_H_

Train net with your own data

faster rcnn训练方式有两种

  • 一种是交替优化方法(alternating optimization),即训练两个网络,一个是rpn,一个是fast rcnn,总计两个stage,每个stage各训练一次rpn和fast rcnn。
  • 另外一种训练方式为近似联合训练(approximate joint training),也称end to end的训练方式,训练过程中只训练一个权重网络,训练速度有可观的提升,而训练精度不变。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# prepare data
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/ # development kit
VOCdevkit/VOCcode/ # VOC utility code
VOCdevkit/VOC2007 # image sets, annotations, etc.
# ... and several other directories ...


cd py-faster-rcnn/data
ln -s VOCdevkit VOCdevkit2007
# Using symlinks is a good idea because you will likely want to share the same PASCAL dataset installation between multiple projects.

# download pre-trained imagenet models
./data/scripts/fetch_imagenet_models.sh

# train net
./experiments/scripts/faster_rcnn_end2end.sh 0 ZF pascal_voc

error fixs

error

AttributeError: 'module' object has no attribute 'text_format'

fix

./lib/fast_rcnn/train.py增加一行

import google.protobuf.text_format

training results

AP for aeroplane = 0.6312
AP for bicycle = 0.7069
AP for bird = 0.5836
AP for boat = 0.4471
AP for bottle = 0.3562
AP for bus = 0.6682
AP for car = 0.7569
AP for cat = 0.7249
AP for chair = 0.3844
AP for cow = 0.6152
AP for diningtable = 0.6162
AP for dog = 0.6502
AP for horse = 0.7580
AP for motorbike = 0.7128
AP for person = 0.6744
AP for pottedplant = 0.3358
AP for sheep = 0.5872
AP for sofa = 0.5649
AP for train = 0.7128
AP for tvmonitor = 0.6133
Mean AP = 0.6050

Results:
0.631
0.707
0.584
0.447
0.356
0.668
0.757
0.725
0.384
0.615
0.616
0.650
0.758
0.713
0.674
0.336
0.587
0.565
0.713
0.613
0.605

--------------------------------------------------------------
Results computed with the **unofficial** Python eval code.
Results should be very close to the official MATLAB eval code.
Recompute with `./tools/reval.py --matlab ...` for your paper.
-- Thanks, The Management
--------------------------------------------------------------

real	5m16.906s
user	4m6.179s
sys	1m16.157s

Reference

History

  • 20180816: created.