/faster_rcnn_pytorch

Faster RCNN with PyTorch. Updated to get proposals on VisualGenome and COCO

Primary LanguagePythonMIT LicenseMIT

Faster RCNN with PyTorch

This is a PyTorch implementation of Faster RCNN. This project is mainly based on py-faster-rcnn and TFFRCNN.

For details about R-CNN please refer to the paper Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks by Shaoqing Ren, Kaiming He, Ross Girshick, Jian Sun.

Progress

  • Forward for detecting
  • RoI Pooling layer with C extensions on CPU (only forward)
  • RoI Pooling layer on GPU (forward and backward)
  • Training on VOC2007
  • TensroBoard support
  • Evaluation

Installation and demo

  1. Clone the Faster R-CNN repository

  2. Create a virtualenv (or use one you already have) with Python 3.5+ and PyTorch

  3. Follow this tutorial to setup OpenCV:

    sudo apt-get install build-essential cmake libgtk2.0-dev pkg-config \
    

python-dev libavcodec-dev libavformat-dev libswscale-dev sudo pip install numpy

- [Download OpenCV](https://sourceforge.net/projects/opencvlibrary/files/latest/download) and unpack to your home directory

mkdir build; cd build; cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_NEW_PYTHON_SUPPORT=ON .. make; sudo make install -j6

- then ``cp /usr/local/lib/python3.5/dist-packages/cv2.so ~/code/pytorch-seq2seq/venv/lib/python3.5/site-packages


2. Build the Cython modules for nms and the roi_pooling layer
  ```bash
  cd faster_rcnn_pytorch/faster_rcnn
  ./make.sh
  ```
3. Download the trained model [VGGnet_fast_rcnn_iter_70000.h5](https://drive.google.com/open?id=0B4pXCfnYmG1WOXdpYVFybWxiZFE) 
and set the model path in `demo.py`

3. ``` export PYTHONPATH="/home/rowan/tools/faster_rcnn_pytorch/faster_rcnn" ```
4. Run demo `python demo.py`

### Training on Pascal VOC 2007

Follow [this project (TFFRCNN)](https://github.com/CharlesShang/TFFRCNN)
to download and prepare the training, validation, test data 
and the VGG16 model pre-trained on ImageNet. 

Since the program loading the data in `faster_rcnn_pytorch/data` by default,
you can set the data path as following.
```bash
cd faster_rcnn_pytorch
mkdir data
cd data
ln -s $VOCdevkit VOCdevkit2007

Then you can set some hyper-parameters in train.py and training parameters in the .yml file.

Now I got a 0.661 mAP on VOC07 while the origin paper got a 0.699 mAP. You may need to tune the loss function defined in faster_rcnn/faster_rcnn.py by yourself.

Training with TensorBoard

With the aid of Crayon, we can access the visualisation power of TensorBoard for any deep learning framework.

To use the TensorBoard, install Crayon (https://github.com/torrvision/crayon) and set use_tensorboard = True in faster_rcnn/train.py.

Evaluation

Set the path of the trained model in test.py.

cd faster_rcnn_pytorch
mkdir output
python test.py

License: MIT license (MIT)