https://github.com/kentaroy47/faster-rcnn.pytorch_resnet50
Pytorch Pretrained Resnet18, 34, 50 backbone of faster-rcnn
https://github.com/kentaroy47/faster-rcnn.pytorch_resnet50
Last synced: 8 months ago
JSON representation
Pytorch Pretrained Resnet18, 34, 50 backbone of faster-rcnn
- Host: GitHub
- URL: https://github.com/kentaroy47/faster-rcnn.pytorch_resnet50
- Owner: kentaroy47
- License: mit
- Created: 2018-09-07T06:33:09.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-12-13T17:51:45.000Z (almost 7 years ago)
- Last Synced: 2025-01-20T23:52:40.425Z (9 months ago)
- Language: Python
- Homepage:
- Size: 1.44 MB
- Stars: 20
- Watchers: 1
- Forks: 7
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# A *Faster* Pytorch Implementation of Faster R-CNN
## Forked from https://github.com/jwyang/faster-rcnn.pytorch
changes.. updated script to use pytorch pretrained resnet (res18, res34, res50, res101, res151)The former code accepted only caffe pretrained models, so the normalization of images are changed to use pytorch models.
Try the forked repo first and if you want to train with pytorch models, you can try this.
Take a look here, for the changes of Channel align and normalization.
https://github.com/jwyang/faster-rcnn.pytorch/issues/173## Preparation
First of all, clone the code
```
git clone https://github.com/kentaroy47/faster-rcnn.pytorch_resnet50.git
```Then, create a folder:
```
cd faster-rcnn.pytorch_resnet50 && mkdir data
```### prerequisites
* Python 2.7 or 3.6
* Pytorch 0.4.0 (**now it does not support 0.4.1 or higher**)
* CUDA 8.0 or higher### Data Preparation
* **PASCAL_VOC 07+12**: Please follow the instructions in [py-faster-rcnn](https://github.com/rbgirshick/py-faster-rcnn#beyond-the-demo-installation-for-training-and-testing-models) to prepare VOC datasets. Actually, you can refer to any others. After downloading the data, creat softlinks in the folder data/.
* **COCO**: Please also follow the instructions in [py-faster-rcnn](https://github.com/rbgirshick/py-faster-rcnn#beyond-the-demo-installation-for-training-and-testing-models) to prepare the data.
* **Visual Genome**: Please follow the instructions in [bottom-up-attention](https://github.com/peteanderson80/bottom-up-attention) to prepare Visual Genome dataset. You need to download the images and object annotation files first, and then perform proprecessing to obtain the vocabulary and cleansed annotations based on the scripts provided in this repository.
### Compilation
As pointed out by [ruotianluo/pytorch-faster-rcnn](https://github.com/ruotianluo/pytorch-faster-rcnn), choose the right `-arch` in `make.sh` file, to compile the cuda code:
| 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 |More details about setting the architecture can be found [here](https://developer.nvidia.com/cuda-gpus) or [here](http://arnon.dk/matching-sm-architectures-arch-and-gencode-for-various-nvidia-cards/)
Install all the python dependencies using pip:
```
pip install -r requirements.txt
```Compile the cuda dependencies using following simple commands:
```
cd lib
sh make.sh
```It will compile all the modules you need, including NMS, ROI_Pooing, ROI_Align and ROI_Crop. The default version is compiled with Python 2.7, please compile by yourself if you are using a different python version.
**As pointed out in this [issue](https://github.com/jwyang/faster-rcnn.pytorch/issues/16), if you encounter some error during the compilation, you might miss to export the CUDA paths to your environment.**
## Train
Make a directory for pretrained weights.
```
mkdir data/pretrained_model/
cd data/pretrained_model
```Then, download the pretrained resnet models and place it under pretrained_model.
Only ones you will use are required.```
#res18
wget https://download.pytorch.org/models/resnet18-5c106cde.pth
#res34
wget https://download.pytorch.org/models/resnet34-333f7ec4.pth
#res50
wget https://download.pytorch.org/models/resnet50-19c8e357.pth
#res101
wget https://download.pytorch.org/models/resnet101-5d3b4d8f.pth
#res151
wget https://download.pytorch.org/models/resnet152-b121ed2d.pth
```Before training, set the right directory to save and load the trained models. Change the arguments "save_dir" and "load_dir" in trainval_net.py and test_net.py to adapt to your environment.
To train a faster R-CNN model with resnet18 on pascal_voc, simply run:
```
CUDA_VISIBLE_DEVICES=$GPU_ID python trainval_net.py \
--dataset pascal_voc --net res18 \
--bs $BATCH_SIZE --nw $WORKER_NUMBER \
--lr $LEARNING_RATE --lr_decay_step $DECAY_STEP \
--cuda
```
where 'bs' is the batch size with default 1. Alternatively, to train with resnet101 on pascal_voc, simple run:
```
CUDA_VISIBLE_DEVICES=$GPU_ID python trainval_net.py \
--dataset pascal_voc --net res50 \
--bs $BATCH_SIZE --nw $WORKER_NUMBER \
--lr $LEARNING_RATE --lr_decay_step $DECAY_STEP \
--cuda
```
Above, BATCH_SIZE and WORKER_NUMBER can be set adaptively according to your GPU memory size. **On Titan Xp with 12G memory, it can be up to 4**.If you have multiple (say 8) Titan Xp GPUs, then just use them all! Try:
```
python trainval_net.py --dataset pascal_voc --net res18 \
--bs 24 --nw 8 \
--lr $LEARNING_RATE --lr_decay_step $DECAY_STEP \
--cuda --mGPUs```
Change dataset to "coco" or 'vg' if you want to train on COCO or Visual Genome.
## Test
If you want to evlauate the detection performance of a pre-trained vgg16 model on pascal_voc test set, simply run
```
python test_net.py --dataset pascal_voc --net res18 \
--checksession $SESSION --checkepoch $EPOCH --checkpoint $CHECKPOINT \
--cuda
```
Specify the specific model session, chechepoch and checkpoint, e.g., SESSION=1, EPOCH=6, CHECKPOINT=416.