potterhsu / easy-faster-rcnn.pytorch

An easy implementation of Faster R-CNN (https://arxiv.org/pdf/1506.01497.pdf) in PyTorch.
MIT License
165 stars 57 forks source link
deep-learning faster-rcnn mscoco-dataset object-detection pytorch resnet-101 resnet-18 resnet-50 vgg16 voc-dataset

easy-faster-rcnn.pytorch

An easy implementation of Faster R-CNN in PyTorch.

Demo

  1. Download checkpoint from here
  2. Follow the instructions in Setup 2 & 3
  3. Run inference script
    $ python infer.py -s=coco2017 -b=resnet101 -c=/path/to/checkpoint.pth --image_min_side=800 --image_max_side=1333 --anchor_sizes="[64, 128, 256, 512]" --rpn_post_nms_top_n=1000 /path/to/input/image.jpg /path/to/output/image.jpg

Features

Benchmarking

Requirements

Setup

  1. Prepare data

    1. For PASCAL VOC 2007

      1. Download dataset

      2. Extract to data folder, now your folder structure should be like:

        easy-faster-rcnn.pytorch
            - data
                - VOCdevkit
                    - VOC2007
                        - Annotations
                            - 000001.xml
                            - 000002.xml
                            ...
                        - ImageSets
                            - Main
                                ...
                                test.txt
                                ...
                                trainval.txt
                                ...
                        - JPEGImages
                            - 000001.jpg
                            - 000002.jpg
                            ...
                - ...
    2. For MS COCO 2017

      1. Download dataset

      2. Extract to data folder, now your folder structure should be like:

        easy-faster-rcnn.pytorch
            - data
                - COCO
                    - annotations
                        - instances_train2017.json
                        - instances_val2017.json
                        ...
                    - train2017
                        - 000000000009.jpg
                        - 000000000025.jpg
                        ...
                    - val2017
                        - 000000000139.jpg
                        - 000000000285.jpg
                        ...
                - ...
  2. Build Non Maximum Suppression and ROI Align modules (modified from facebookresearch/maskrcnn-benchmark)

    1. Install

      $ python support/setup.py develop
    2. Uninstall

      $ python support/setup.py develop --uninstall
    3. Test

      $ python test/nms/test_nms.py
      • Result

  3. Install pycocotools for MS COCO 2017 dataset

    1. Clone and build COCO API

      $ git clone https://github.com/cocodataset/cocoapi
      $ cd cocoapi/PythonAPI
      $ make

      It's not necessary to be under project directory

    2. If an error with message pycocotools/_mask.c: No such file or directory has occurred, please install cython and try again

      $ pip install cython
    3. Copy pycocotools into project

      $ cp -R pycocotools /path/to/project

Usage

  1. Train

    • To apply default configuration (see also config/)

      $ python train.py -s=voc2007 -b=resnet101
    • To apply custom configuration (see also train.py)

      $ python train.py -s=voc2007 -b=resnet101 --weight_decay=0.0001
    • To apply recommended configuration (see also scripts/)

      $ bash ./scripts/voc2007/train-bs2.sh resnet101 /path/to/outputs/dir
  2. Evaluate

    • To apply default configuration (see also config/)

      $ python eval.py -s=voc2007 -b=resnet101 /path/to/checkpoint.pth
    • To apply custom configuration (see also eval.py)

      $ python eval.py -s=voc2007 -b=resnet101 --rpn_post_nms_top_n=1000 /path/to/checkpoint.pth
    • To apply recommended configuration (see also scripts/)

      $ bash ./scripts/voc2007/eval.sh resnet101 /path/to/checkpoint.pth
  3. Infer

    • To apply default configuration (see also config/)

      $ python infer.py -s=voc2007 -b=resnet101 -c=/path/to/checkpoint.pth /path/to/input/image.jpg /path/to/output/image.jpg
    • To apply custom configuration (see also infer.py)

      $ python infer.py -s=voc2007 -b=resnet101 -c=/path/to/checkpoint.pth -p=0.9 /path/to/input/image.jpg /path/to/output/image.jpg
    • To apply recommended configuration (see also scripts/)

      $ bash ./scripts/voc2007/infer.sh resnet101 /path/to/checkpoint.pth /path/to/input/image.jpg /path/to/output/image.jpg
  4. Infer other sources

    • Source from stream (see also infer_stream.py)

      # Camera
      $ python infer_stream.py -s=voc2007 -b=resnet101 -c=/path/to/checkpoint.pth -p=0.9 0 5
      
      # Video
      $ python infer_stream.py -s=voc2007 -b=resnet101 -c=/path/to/checkpoint.pth -p=0.9 /path/to/file.mp4 5
      
      # Remote
      $ python infer_stream.py -s=voc2007 -b=resnet101 -c=/path/to/checkpoint.pth -p=0.9 rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov 5
    • Source from websocket (see also infer_websocket.py)

      1. Start web server

        $ cd webapp
        $ python -m http.server 8000
      2. Launch service

        $ python infer_websocket.py -s=voc2007 -b=resnet101 -c=/path/to/checkpoint.pth -p=0.9
      3. Navigate website: http://127.0.0.1:8000/

        Sample video from Pexels

Notes