Home

Awesome

High-resolution networks (HRNets) for object detection

News

Introduction

This is the official code of High-Resolution Representations for Object Detection. We extend the high-resolution representation (HRNet) [1] by augmenting the high-resolution representation by aggregating the (upsampled) representations from all the parallel convolutions, leading to stronger representations. We build a multi-level representation from the high resolution and apply it to the Faster R-CNN, Mask R-CNN and Cascade R-CNN framework. This proposed approach achieves superior results to existing single-model networks on COCO object detection. The code is based on mmdetection

<div align=center>

</div>

Performance

ImageNet pretrained models

HRNetV2 ImageNet pretrained models are now available! Codes and pretrained models are in HRNets for Image Classification

All models are trained on COCO train2017 set and evaluated on COCO val2017 set. Detailed settings or configurations are in configs/hrnet.

Note: Models are trained with the newly released code and the results have minor differences with that in the paper. Current results will be updated soon and more models and results are comming.

Note: Pretrained HRNets can be downloaded at HRNets for Image Classification

Note: Models with * are implemented in Official mmdetection.

Faster R-CNN

Backbone#ParamsGFLOPslr schedSyncBNMS trainmAPmodel
HRNetV2-W1826.2M159.11xNN36.1OneDrive,BaiduDrive(y4hs)
HRNetV2-W1826.2M159.11xYN37.2OneDrive,BaiduDrive(ypnu)
HRNetV2-W1826.2M159.11xYY(Default)37.6OneDrive,BaiduDrive(ekkm)
HRNetV2-W1826.2M159.11xYY(ResizeCrop)37.6OneDrive,BaiduDrive(phgo)
HRNetV2-W1826.2M159.12xNN38.1OneDrive,BaiduDrive(mz9y)
HRNetV2-W1826.2M159.12xYY(Default)39.4OneDrive,BaiduDrive(ocuf)
HRNetV2-W1826.2M159.12xYY(ResizeCrop)39.7
HRNetV2-W3245.0M245.31xNN39.5OneDrive,BaiduDrive(ztwa)
HRNetV2-W3245.0M245.31xYY(Default)41.0
HRNetV2-W3245.0M245.32xNN40.8OneDrive,BaiduDrive(hmdo)
HRNetV2-W3245.0M245.32xYY(Default)42.6OneDrive,BaiduDrive(k03x)
HRNetV2-W4060.5M314.91xNN40.4OneDrive,BaiduDrive(0qda)
HRNetV2-W4060.5M314.92xNN41.4OneDrive,BaiduDrive(xny6)
HRNetV2-W48*79.4M399.11xNN40.9model
HRNetV2-W48*79.4M399.11xNN41.5model

Mask R-CNN

Backbonelr schedMask mAPBox mAPmodel
HRNetV2-W181x34.237.3OneDrive,BaiduDrive(vvc1)
HRNetV2-W182x35.739.2OneDrive,BaiduDrive(x2m7)
HRNetV2-W321x36.840.7OneDrive,BaiduDrive(j2ir)
HRNetV2-W322x37.642.1OneDrive,BaiduDrive(tzkz)
HRNetV2-W48*1x42.438.1model
HRNetV2-W48*2x42.938.3model

Cascade R-CNN

Note: we follow the original paper[2] and adopt 280k training iterations which is equal to 20 epochs in mmdetection.

Backbonelr schedmAPmodel
HRNetV2-W18*20e41.2model
HRNetV2-W3220e43.7OneDrive,BaiduDrive(ydd7)
HRNetV2-W48*20e44.6model

Cascade Mask R-CNN

Backbonelr schedMask mAPBox mAPmodel
HRNetV2-W18*20e36.441.9model
HRNetV2-W32*20e38.544.5model
HRNetV2-W48*20e39.546.0model

Hybrid Task Cascade

Backbonelr schedMask mAPBox mAPmodel
HRNetV2-W18*20e37.943.1model
HRNetV2-W32*20e39.645.3model
HRNetV2-W48*20e40.746.8model
HRNetV2-W48*28e41.047.0model

FCOS

BackboneGNMS trainLr schdBox mAPmodel
HRNetV2p-W18*YN1x35.2model
HRNetV2p-W18*YN2x38.2model
HRNetV2p-W32*YN1x37.7model
HRNetV2p-W32*YN2x40.3model
HRNetV2p-W18*YY2x38.1model
HRNetV2p-W32*YY2x41.4model
HRNetV2p-W48*YY2x42.9model

Techniques about multi-scale training

Default

You need to change lines below in config files

data = dict(
    imgs_per_gpu=4,
    workers_per_gpu=8,
    pad_size=(1600, 1024),
    train=dict(
        type=dataset_type,
        ann_file=data_root + 'annotations/instances_train2017.json',
        img_prefix=data_root + 'images/train2017.zip',
        img_scale=[(1600, 1000), (1000, 600), (1333, 800)],
        img_norm_cfg=img_norm_cfg,
        size_divisor=32,
        flip_ratio=0.5,
        with_mask=False,
        with_crowd=True,
        with_label=True),

ResizeCrop

Less memory and less time, this implementation is more efficient compared to the former one

You need to change lines below in config files

    imgs_per_gpu=2,
    workers_per_gpu=4,
    pad_size=(1216, 800),
    train=dict(
        type=dataset_type,
        ann_file=data_root + 'annotations/instances_train2017.json',
        img_prefix=data_root + 'train2017.zip',
        img_scale=(1200, 800),
        img_norm_cfg=img_norm_cfg,
        size_divisor=1,
        extra_aug=dict(
            rand_resize_crop=dict(
                scales=[[1400, 600], [1400, 800], [1400, 1000]],
                size=[1200, 800]
            )),
        flip_ratio=0.5,
        with_mask=False,
        with_crowd=True,
        with_label=True),

Quick start

Environment

This code is developed using on Python 3.6 and PyTorch 1.0.0 on Ubuntu 16.04 with NVIDIA GPUs. Training and testing are performed using 4 NVIDIA P100 GPUs with CUDA 9.0 and cuDNN 7.0. Other platforms or GPUs are not fully tested.

Install

  1. Install PyTorch 1.0 following the official instructions
  2. Install mmcv
pip install mmcv
  1. Install pycocotools
git clone https://github.com/cocodataset/cocoapi.git \
 && cd cocoapi/PythonAPI \
 && python setup.py build_ext install \
 && cd ../../
  1. Install NVIDIA/apex to enable SyncBN
git clone https://github.com/NVIDIA/apex
cd apex
python setup install --cuda_ext
  1. Install HRNet-Object-Detection
git clone https://github.com/HRNet/HRNet-Object-Detection.git

cd HRNet-Object-Detection
# compile CUDA extensions.
chmod +x compile.sh
./compile.sh

# run setup
python setup.py install 

# or install locally
python setup.py install --user

For more details, see INSTALL.md

HRNetV2 pretrained models

cd HRNet-Object-Detection
# Download pretrained models into this folder
mkdir hrnetv2_pretrained

Datasets

Please download the COCO dataset from cocodataset. If you use zip format, please specify CocoZipDataset in config files or CocoDataset if you unzip the downloaded dataset.

Train (multi-gpu training)

Please specify the configuration file in configs (learning rate should be adjusted when the number of GPUs is changed).

python -m torch.distributed.launch --nproc_per_node <GPUS NUM> tools/train.py <CONFIG-FILE> --launcher pytorch
# example:
python -m torch.distributed.launch --nproc_per_node 4 tools/train.py configs/hrnet/faster_rcnn_hrnetv2p_w18_1x.py --launcher pytorch

Test

python tools/test.py <CONFIG-FILE> <MODEL WEIGHT> --gpus <GPUS NUM> --eval bbox --out result.pkl
# example:
python tools/test.py configs/hrnet/faster_rcnn_hrnetv2p_w18_1x.py work_dirs/faster_rcnn_hrnetv2p_w18_1x/model_final.pth --gpus 4 --eval bbox --out result.pkl

NOTE: If you meet some problems, you may find a solution in issues of official mmdetection repo or submit a new issue in our repo.

Other applications of HRNets (codes and models):

Citation

If you find this work or code is helpful in your research, please cite:

@inproceedings{SunXLW19,
  title={Deep High-Resolution Representation Learning for Human Pose Estimation},
  author={Ke Sun and Bin Xiao and Dong Liu and Jingdong Wang},
  booktitle={CVPR},
  year={2019}
}

@article{WangSCJDZLMTWLX19,
  title={Deep High-Resolution Representation Learning for Visual Recognition},
  author={Jingdong Wang and Ke Sun and Tianheng Cheng and 
          Borui Jiang and Chaorui Deng and Yang Zhao and Dong Liu and Yadong Mu and 
          Mingkui Tan and Xinggang Wang and Wenyu Liu and Bin Xiao},
  journal   = {TPAMI}
  year={2019}
}

Reference

[1] Deep High-Resolution Representation Learning for Visual Recognition. Jingdong Wang, Ke Sun, Tianheng Cheng, Borui Jiang, Chaorui Deng, Yang Zhao, Dong Liu, Yadong Mu, Mingkui Tan, Xinggang Wang, Wenyu Liu, Bin Xiao. Accepted by TPAMI. download

Acknowledgement

Thanks @open-mmlab for providing the easily-used code and kind help!