Home

Awesome

Generalized Intersection over Union - PyTorch Faster/Mask R-CNN

Faster/Mask R-CNN with GIoU loss implemented in PyTorch

If you use this work, please consider citing:

@article{Rezatofighi_2018_CVPR,
  author    = {Rezatofighi, Hamid and Tsoi, Nathan and Gwak, JunYoung and Sadeghian, Amir and Reid, Ian and Savarese, Silvio},
  title     = {Generalized Intersection over Union},
  booktitle = {The IEEE Conference on Computer Vision and Pattern Recognition (CVPR)},
  month     = {June},
  year      = {2019},
}

Modifications in this repository

This repository is a fork of roytseng-tw/Detectron.pytorch, with an implementation of GIoU and IoU loss while keeping the code as close to the original as possible. It is also possible to train the network with SmoothL1 loss as in the original code. See the options below.

Losses

The type of bounding box loss can be configured in the configuration file as following. MODEL.LOSS_TYPE configures the final bounding box refinement loss. MODEL.RPN_LOSS_TYPE determines the type of the RPN bounding box loss. The valid options are currently: [iou|giou|sl1].

MODEL:
  LOSS_TYPE: 'iou'
  RPN_LOSS_TYPE: 'iou'

Please take a look at compute_iou function of lib/utils/net.py for our GIoU and IoU loss implementation in PyTorch.

Normalizers

We also implement a normalizer of bounding box refinement losses. This can be specified with the MODEL.LOSS_BBOX_WEIGHT and MODEL.RPN_LOSS_BBOX_WEIGHT parameters in the configuration file. The default value is 1.0. We use MODEL.LOSS_BBOX_WEIGHT of 10. for IoU and GIoU experiments in the paper.

MODEL:
  LOSS_BBOX_WEIGHT: 10.
  RPN_LOSS_BBOX_WEIGHT: 1.

Network Configurations

We add sample configuration files used for our experiment in config/baselines. Our experiments in the paper are based on e2e_faster_rcnn_R-50-FPN_1x.yaml and e2e_mask_rcnn_R-50-FPN_1x.yaml as following:

e2e_faster_rcnn_R-50-FPN_giou_1x.yaml  # Faster R-CNN + GIoU loss
e2e_faster_rcnn_R-50-FPN_iou_1x.yaml   # Faster R-CNN + IoU loss
e2e_mask_rcnn_R-50-FPN_giou_1x.yaml    # Mask R-CNN + GIoU loss
e2e_mask_rcnn_R-50-FPN_iou_1x.yaml     # Mask R-CNN + IoU loss

Train and evaluation commands

For detailed installation instruction and network training options, please take a look at the README file or issue of roytseng-tw/Detectron.pytorch. Following is a sample command we used for training and testing Faster R-CNN with GIoU.

python tools/train_net_step.py --dataset coco2017 --cfg configs/baselines/e2e_faster_rcnn_R-50-FPN_giou_1x.yaml --use_tfboard
python tools/test_net.py --dataset coco2017 --cfg configs/baselines/e2e_faster_rcnn_R-50-FPN_giou_1x.yaml --load_ckpt {full_path_of_the_trained_weight}

Pretrained weights

Here are the trained models using the configurations in this repository.