This repo is a Python3 implementation of Faster-RCNN_TF by smallcorgi which implements Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks by Shaoqing Ren, Kaiming He, Ross Girshick, Jian Sun.
The full repository has been made compaitable for python3, and if you want to train a network you can follow the following instructions. In case, if you want to do the same using python2, then you can fork or download the following repo.
https://github.com/dxyang/Faster-RCNN-COCO_TF
-
Requirements for Tensorflow (see: Tensorflow)
-
Python packages you might not have:
pillow
scipy
cython
,opencv3
,easydict
This repo has been tested using python3.5, tensorflow1.4, cudNN-6.
-
Clone the PY3-Faster-RCNN-TF repository
# Make sure to clone with --recursive git clone --recursive https://github.com/surajitsaikia27/PY3-Faster-RCNN-TF
-
Build the Cython modules
cd $PY3-Faster-RCNN-TF/lib make
-
To run the demo:
Download the COCO trained pretrained model from https://drive.google.com/file/d/0Bw0qMqgwZcafZlRqRDYxSnBkNFE/view
rename VGGnet_fast_rcnn_iter_490000.ckpt.data-00000-of-00001 as VGGnet_fast_rcnn_iter_490000.ckpt
Run the following command.
python ./tools/demo.py --model "path to the VGGnet_fast_rcnn_iter_490000.ckpt" --net VGGnet_test --img-path path to image folder
The results will be saved in a directory called detections_test
Follow the instructions to train your own model.
-
Build pycocotools modules
cd $PY3-Faster-RCNN-TF/lib git clone https://github.com/cocodataset/cocoapi.git cd cocoapi/PythonAPI make cd ../.. mv cocoapi/PythonAPI/pycocotools pycocotools rm -rf cocoapi
-
Build the Cython modules
cd $PY3-Faster-RCNN-TF/lib make
-
Install gsutil if you haven't already
curl https://sdk.cloud.google.com | bash
-
Download the training, validation, test data for MS COCO
cd $PY3-Faster-RCNN-TF/data mkdir coco; cd coco mkdir images; cd images mkdir train2014 mkdir test2014 mkdir val2014 gsutil -m rsync gs://images.cocodataset.org/train2014 train2014 gsutil -m rsync gs://images.cocodataset.org/test2014 test2014 gsutil -m rsync gs://images.cocodataset.org/val2014 val2014
-
Download the annotations for MS COCO and unzip
cd $PY3-Faster-RCNN-TF/data gsutil -m rsync gs://images.cocodataset.org/annotations coco cd coco unzip annotations_trainval2014.zip unzip image_info_test2014.zip rm *.zip
-
Download the annotations for the 5000 image minival subset of COCO val2014 as mentioned here
cd $PY3-Faster-RCNN-TF/data/coco/annotations wget https://dl.dropboxusercontent.com/s/o43o90bna78omob/instances_minival2014.json.zip wget https://dl.dropboxusercontent.com/s/s3tw5zcg7395368/instances_valminusminival2014.json.zip unzip instances_minival2014.json.zip; rm instances_minival2014.json.zip unzip instances_valminusminival2014.json.zip; rm instances_valminusminival2014.json.zip
-
Download the pre-trained ImageNet model [Google Drive] [Dropbox]
cd $PY3-Faster-RCNN-TF wget https://www.dropbox.com/s/po2kzdhdgl4ix55/VGG_imagenet.npy mkdir data/pretrain_model mv VGG_imagenet.npy data/pretrain_model/VGG_imagenet.npy
-
Create an output directory for log files
cd $PY3-Faster-RCNN-TF mkdir experiments/logs
-
Run script to train and test model
cd $PY3-Faster-RCNN-TF ./experiments/scripts/faster_rcnn_end2end.sh $DEVICE $DEVICE_ID VGG16 coco
- DEVICE is either cpu/gpu
Run the following command.
python ./tools/test_net.py \
--device gpu \
--device_id 0 \
--weights output/faster_rcnn_end2end/coco_2014_train/VGGnet_fast_rcnn_iter_490000.ckpt \
--cfg experiments/cfgs/faster_rcnn_end2end.yml \
--imdb coco_2014_minival \
--network VGGnet_test \
--vis False
- Changing
vis
toTrue
will save images with all detections above 0.8 for every image in the testing set. - The checkpoint files folder contains the following:
cd output/faster_rcnn_end2end/coco_2014_train ls # VGGnet_fast_rcnn_iter_490000.ckpt.data-00000-of-00001 # VGGnet_fast_rcnn_iter_490000.ckpt.index # VGGnet_fast_rcnn_iter_490000.ckpt.meta