-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
52 changed files
with
2,206 additions
and
684 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,58 @@ | ||
# Faster RCNN with PyTorch | ||
**Note:** I re-implemented faster rcnn in this project when I started learning PyTorch. Then I use PyTorch in all of my projects. I still remember it costed one week for me to figure out how to build cuda code as a pytorch layer :). | ||
But actually this is not a good implementation and I didn't achieve the same mIOU as the original caffe code. | ||
# Faster_R-CNN_pytorch | ||
- Modifed based on [**longcw/faster_rcnn_pytorch**](https://github.com/daviddao/spatial-transformer-tensorflow) . | ||
- Implementation of [**Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks**](https://arxiv.org/abs/1506.01497). | ||
|
||
**This project is no longer maintained. So I suggest:** | ||
- You can still read and study this code if you want to re-implement faster rcnn by yourself; | ||
- You can use the better PyTorch implementation by [ruotianluo](https://github.com/ruotianluo/pytorch-faster-rcnn) if you want to train faster rcnn with your own data; | ||
## Statement | ||
- Based on **longcw/faster_rcnn_pytorch (python2.7)**, I modified the code to **python3.6** and **numpy 1.13.3**. So the numpy version do not need to change into 1.11. | ||
- Follow **longcw**'s code, I draw some picture to understand the process of Faster R-CNN. | ||
|
||
This is a [PyTorch](https://github.com/pytorch/pytorch) | ||
implementation of Faster RCNN. | ||
This project is mainly based on [py-faster-rcnn](https://github.com/rbgirshick/py-faster-rcnn) | ||
and [TFFRCNN](https://github.com/CharlesShang/TFFRCNN). | ||
Thank **longcw**, his code helps me a lot to understand Faster R-CNN. Also the readme files of **longcw** and **ruotianluo** tell me how to build cython models. You can also follow their code and readme file. | ||
|
||
For details about R-CNN please refer to the [paper](https://arxiv.org/abs/1506.01497) | ||
Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks | ||
by Shaoqing Ren, Kaiming He, Ross Girshick, Jian Sun. | ||
**If there is something I can not write in my repertory, please contact me.** | ||
|
||
### Progress | ||
## Environment and Compile | ||
- python 3.6 | ||
- pytorch 0.3.0 | ||
- numpy 1.13.3 | ||
- opencv 3.3.0 | ||
|
||
- [x] Forward for detecting | ||
- [x] RoI Pooling layer with C extensions on CPU (only forward) | ||
- [x] RoI Pooling layer on GPU (forward and backward) | ||
- [x] Training on VOC2007 | ||
- [x] TensroBoard support | ||
- [x] Evaluation | ||
|
||
### Installation and demo | ||
0. Install the requirements (you can use pip or [Anaconda](https://www.continuum.io/downloads)): | ||
Follow [**longcw/faster_rcnn_pytorch**](https://github.com/longcw/faster_rcnn_pytorch) and [**ruotianluo/pytorch-faster-rcnn**](https://github.com/ruotianluo/pytorch-faster-rcnn). | ||
|
||
1. Install requirements (directly copy from [**longcw/faster_rcnn_pytorch/README.md**](https://raw.githubusercontent.com/longcw/faster_rcnn_pytorch/master/README.md)). | ||
|
||
``` | ||
conda install pip pyyaml sympy h5py cython numpy scipy | ||
conda install -c menpo opencv3 | ||
pip install easydict | ||
``` | ||
|
||
2. Choose arch of GPU type. (directly copy from[**ruotianluo/pytorch-faster-rcnn/README.md**](https://raw.githubusercontent.com/ruotianluo/pytorch-faster-rcnn/master/README.md)) | ||
|
||
| GPU model | Architecture | | ||
| ------------- | ------------- | | ||
| TitanX (Maxwell/Pascal) | sm_52 | | ||
| GTX 960M | sm_50 | | ||
| GTX 1080 (Ti) | sm_61 | | ||
| Grid K520 (AWS g2.2xlarge) | sm_30 | | ||
| Tesla K80 (AWS p2.xlarge) | sm_37 | | ||
|
||
modify the parameter **arch** in **faster_rcnn_pytorch/faster_rcnn/make.sh** | ||
|
||
3. Build Cython models (directly copy from [**longcw/faster_rcnn_pytorch/README.md**](https://raw.githubusercontent.com/longcw/faster_rcnn_pytorch/master/README.md)). | ||
|
||
|
||
1. Clone the Faster R-CNN repository | ||
```bash | ||
git clone [email protected]:longcw/faster_rcnn_pytorch.git | ||
``` | ||
|
||
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. 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](https://github.com/torrvision/crayon), | ||
we can access the visualisation power of TensorBoard for any | ||
deep learning framework. | ||
## Run | ||
You can follow [**longcw/faster_rcnn_pytorch**](https://github.com/daviddao/spatial-transformer-tensorflow) . | ||
|
||
To use the TensorBoard, install Crayon (https://github.com/torrvision/crayon) | ||
and set `use_tensorboard = True` in `faster_rcnn/train.py`. | ||
- **demo.py** You need to download **trained_weights(VGGnet_fast_rcnn_iter_70000.h5)** and load it's weight. | ||
- **train.py** You need to download **VOC dataset** and ** VGG_imagenet_pretrained_weight(VGG_imagenet.npy)**. | ||
- **test.py** YOu need to download **VOC dataset**. | ||
|
||
### Evaluation | ||
Set the path of the trained model in `test.py`. | ||
```bash | ||
cd faster_rcnn_pytorch | ||
mkdir output | ||
python test.py | ||
``` | ||
## Process of Code | ||
![](pics/process.png) | ||
|
||
License: MIT license (MIT) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Download VOC dataset. | ||
The structure of data_dir is data/VOCdevkit2012/VOC2012/[Annotations|ImageSets|...] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Download VGG_imagenet.npy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.