[2017/8/29] param_str, cfg_key error
The official Faster R-CNN code (written in MATLAB) is available here. If your goal is to reproduce the results in our NIPS 2015 paper, please use the official code.
This repository contains a Python reimplementation of the MATLAB code. This Python implementation is built on a fork of Fast R-CNN. There are slight differences between the two implementations. In particular, this Python port
- is ~10% slower at test-time, because some operations execute on the CPU in Python layers (e.g., 220ms / image vs. 200ms / image for VGG16)
- gives similar, but not exactly the same, mAP as the MATLAB version
- is not compatible with models trained using the MATLAB code due to the minor implementation differences
- includes approximate joint training that is 1.5x faster than alternating optimization (for VGG16) -- see these slides for more information
By Shaoqing Ren, Kaiming He, Ross Girshick, Jian Sun (Microsoft Research)
This Python implementation contains contributions from Sean Bell (Cornell) written during an MSR internship.
Please see the official README.md for more details.
Faster R-CNN was initially described in an arXiv tech report and was subsequently published in NIPS 2015.
Faster R-CNN is released under the MIT License (refer to the LICENSE file for details).
If you find Faster R-CNN useful in your research, please consider citing:
@inproceedings{renNIPS15fasterrcnn,
Author = {Shaoqing Ren and Kaiming He and Ross Girshick and Jian Sun},
Title = {Faster {R-CNN}: Towards Real-Time Object Detection
with Region Proposal Networks},
Booktitle = {Advances in Neural Information Processing Systems ({NIPS})},
Year = {2015}
}
- Requirements: software
- Requirements: hardware
- Basic installation
- Demo
- Beyond the demo: training and testing
- Usage
- Windows 10 64-bit
- Vs2015
- Python 2.7 (Recommend use Anaconda)
- OpenCV >= 3.1.0
- Nvidia GTX 1060 6GB
-
Build caffe-fast-rcnn cd $FRCN_ROOT/caffe-fast-rcnn/scripts
modify build_win.cmd: Line 8, 9, 74, 76
if NOT DEFINED WITH_NINJA set WITH_NINJA=0 if NOT DEFINED CPU_ONLY set CPU_ONLY=0
Line 25, 29
if !PYTHON_VERSION! EQU 2 ( set CONDA_ROOT=C:\Program Files\Anaconda2 ) :: Set python 3.5 with conda as the default python if !PYTHON_VERSION! EQU 3 ( set CONDA_ROOT=C:\Program Files\Anaconda2 )
Line 172 (cudnn path)
-DCUDNN_ROOT=C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0 ^
-
Build py-faster-
SET VS90COMNTOOLS=%VS140COMNTOOLS%
Add cl.exe to env path:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin
Start setup and install python libs.
cd $FRCN_ROOT/lib python setup.py install python setup_cuda.py install pip install -r requirements.txt
-
Run Demo SET PYTHONPATH=$FRCN_ROOT/caffe-fast-rcnn/python
After successfully completing basic installation, you'll be ready to run the demo.
To run the demo
cd $FRCN_ROOT
./tools/demo.py
The demo performs detection using a VGG16 network trained for detection on PASCAL VOC 2007.
-
Download the training, validation, test data and VOCdevkit
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
-
Extract all of these tars into one directory named
VOCdevkit
tar xvf VOCtrainval_06-Nov-2007.tar tar xvf VOCtest_06-Nov-2007.tar tar xvf VOCdevkit_08-Jun-2007.tar
-
It should have this basic structure
$VOCdevkit/ # development kit $VOCdevkit/VOCcode/ # VOC utility code $VOCdevkit/VOC2007 # image sets, annotations, etc. # ... and several other directories ...
-
Create symlinks for the PASCAL VOC dataset
cd $FRCN_ROOT/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.
-
[Optional] follow similar steps to get PASCAL VOC 2010 and 2012
-
[Optional] If you want to use COCO, please see some notes under
data/README.md
-
Follow the next sections to download pre-trained ImageNet models
Pre-trained ImageNet models can be downloaded for the three networks described in the paper: ZF and VGG16.
cd $FRCN_ROOT
./data/scripts/fetch_imagenet_models.sh
VGG16 comes from the Caffe Model Zoo, but is provided here for your convenience. ZF was trained at MSRA.
To train and test a Faster R-CNN detector using the alternating optimization algorithm from our NIPS 2015 paper, use experiments/scripts/faster_rcnn_alt_opt.sh
.
Output is written underneath $FRCN_ROOT/output
.
cd $FRCN_ROOT
./experiments/scripts/faster_rcnn_alt_opt.sh [GPU_ID] [NET] [--set ...]
# GPU_ID is the GPU you want to train on
# NET in {ZF, VGG_CNN_M_1024, VGG16} is the network arch to use
# --set ... allows you to specify fast_rcnn.config options, e.g.
# --set EXP_DIR seed_rng1701 RNG_SEED 1701
("alt opt" refers to the alternating optimization training algorithm described in the NIPS paper.)
To train and test a Faster R-CNN detector using the approximate joint training method, use experiments/scripts/faster_rcnn_end2end.sh
.
Output is written underneath $FRCN_ROOT/output
.
cd $FRCN_ROOT
./experiments/scripts/faster_rcnn_end2end.sh [GPU_ID] [NET] [--set ...]
# GPU_ID is the GPU you want to train on
# NET in {ZF, VGG_CNN_M_1024, VGG16} is the network arch to use
# --set ... allows you to specify fast_rcnn.config options, e.g.
# --set EXP_DIR seed_rng1701 RNG_SEED 1701
This method trains the RPN module jointly with the Fast R-CNN network, rather than alternating between training the two. It results in faster (~ 1.5x speedup) training times and similar detection accuracy. See these slides for more details.
Artifacts generated by the scripts in tools
are written in this directory.
Trained Fast R-CNN networks are saved under:
output/<experiment directory>/<dataset name>/
Test outputs are saved under:
output/<experiment directory>/<dataset name>/<network snapshot name>/