Home

Awesome

High-resolution networks (HRNets) for Semantic Segmentation

Branches

News

Introduction

This is the official code of high-resolution representations for Semantic Segmentation. We augment the HRNet with a very simple segmentation head shown in the figure below. We aggregate the output representations at four different resolutions, and then use a 1x1 convolutions to fuse these representations. The output representations is fed into the classifier. We evaluate our methods on three datasets, Cityscapes, PASCAL-Context and LIP.

Segmentation models

HRNetV2 Segmentation models are now available. All the results are reproduced by using this repo!!!

The models are initialized by the weights pretrained on the ImageNet. You can download the pretrained models from https://github.com/HRNet/HRNet-Image-Classification.

Big models

  1. Performance on the Cityscapes dataset. The models are trained and tested with the input size of 512x1024 and 1024x2048 respectively. If multi-scale testing is used, we adopt scales: 0.5,0.75,1.0,1.25,1.5,1.75.
modelTrain SetTest Set#ParamsGFLOPsOHEMMulti-scaleFlipmIoULink
HRNetV2-W48TrainVal65.8M696.2NoNoNo80.9OneDrive/BaiduYun(Access Code:tj7a)
HRNetV2-W48TrainVal65.8M696.2YesNoNo81.2OneDrive/BaiduYun(Access Code:794r)
HRNetV2-W48TrainTest65.8M696.2NoYesYes80.5OneDrive/BaiduYun(Access Code:tj7a)
HRNetV2-W48TrainTest65.8M696.2YesYesYes81.1OneDrive/BaiduYun(Access Code:794r)
HRNetV2-W48TrainValTest65.8M696.2NoYesYes81.5OneDrive/BaiduYun(Access Code:pbai)
HRNetV2-W48TrainValTest65.8M696.2YesYesYes81.9OneDrive/BaiduYun(Access Code:qett)
  1. Performance on the LIP dataset. The models are trained and tested with the input size of 473x473.
model#ParamsGFLOPsOHEMMulti-scaleFlipmIoULink
HRNetV2-W4865.8M74.3NoNoYes56.04OneDrive/BaiduYun(Access Code:mjw3)
  1. Performance on the PASCAL-Context dataset. The models are trained and tested with the input size of 480x480. If multi-scale testing is used, we adopt scales: 0.5,0.75,1.0,1.25,1.5,1.75,2.0 (the same as EncNet, DANet etc.).
modelnum classes#ParamsGFLOPsOHEMMulti-scaleFlipmIoULink
HRNetV2-W4859 classes65.8M76.5NoYesYes54.1OneDrive/BaiduYun(Access Code:53fj)
HRNetV2-W4860 classes65.8M76.5NoYesYes48.3OneDrive/BaiduYun(Access Code:9uf8)

Small models

The models are initialized by the weights pretrained on the ImageNet. You can download the pretrained models from https://github.com/HRNet/HRNet-Image-Classification.

Performance on the Cityscapes dataset. The models are trained and tested with the input size of 512x1024 and 1024x2048 respectively. The results of other small models are obtained from Structured Knowledge Distillation for Semantic Segmentation(https://arxiv.org/abs/1903.04197). The small model are built based on the code of Pytorch-v1.1 branch.

modelTrain SetTest Set#ParamsGFLOPsOHEMMulti-scaleFlipDistillationmIoULink
SQTrainVal--NoNoNoNo59.8
CRF-RNNTrainVal--NoNoNoNo62.5
Dilation10TrainVal140.8-NoNoNoNo67.1
ICNetTrainVal--NoNoNoNo70.6
ResNet18(1.0)TrainVal15.2477.6NoNoNoNo69.1
ResNet18(1.0)TrainVal15.2477.6NoNoNoYes72.7
MD(Enhanced)TrainVal14.4240.2NoNoNoNo67.3
MD(Enhanced)TrainVal14.4240.2NoNoNoYes71.9
MobileNetV2PlusTrainVal8.3320.9NoNoNoNo70.1
MobileNetV2PlusTrainVal8.3320.9NoNoNoYes74.5
HRNetV2-W18-Small-v1TrainVal1.5M31.1NoNoNoNo70.3OneDrive/BaiduYun(Access Code:63be)
HRNetV2-W18-Small-v2TrainVal3.9M71.6NoNoNoNo76.2OneDrive/BaiduYun(Access Code:p1qf)

Quick start

Install

  1. Install PyTorch=0.4.1 following the official instructions
  2. git clone https://github.com/HRNet/HRNet-Semantic-Segmentation $SEG_ROOT
  3. Install dependencies: pip install -r requirements.txt

If you want to train and evaluate our models on PASCAL-Context, you need to install details.

# PASCAL_CTX=/path/to/PASCAL-Context/
git clone https://github.com/zhanghang1989/detail-api.git $PASCAL_CTX
cd $PASCAL_CTX/PythonAPI
python setup.py install

Data preparation

You need to download the Cityscapes, LIP and PASCAL-Context datasets.

Your directory tree should be look like this:

$SEG_ROOT/data
├── cityscapes
│   ├── gtFine
│   │   ├── test
│   │   ├── train
│   │   └── val
│   └── leftImg8bit
│       ├── test
│       ├── train
│       └── val
├── lip
│   ├── TrainVal_images
│   │   ├── train_images
│   │   └── val_images
│   └── TrainVal_parsing_annotations
│       ├── train_segmentations
│       ├── train_segmentations_reversed
│       └── val_segmentations
├── pascal_ctx
│   ├── common
│   ├── PythonAPI
│   ├── res
│   └── VOCdevkit
│       └── VOC2010
├── list
│   ├── cityscapes
│   │   ├── test.lst
│   │   ├── trainval.lst
│   │   └── val.lst
│   ├── lip
│   │   ├── testvalList.txt
│   │   ├── trainList.txt
│   │   └── valList.txt

Train and test

Please specify the configuration file.

For example, train the HRNet-W48 on Cityscapes with a batch size of 12 on 4 GPUs:

python tools/train.py --cfg experiments/cityscapes/seg_hrnet_w48_train_512x1024_sgd_lr1e-2_wd5e-4_bs_12_epoch484.yaml

For example, evaluating our model on the Cityscapes validation set with multi-scale and flip testing:

python tools/test.py --cfg experiments/cityscapes/seg_hrnet_w48_train_512x1024_sgd_lr1e-2_wd5e-4_bs_12_epoch484.yaml \
                     TEST.MODEL_FILE hrnet_w48_cityscapes_cls19_1024x2048_trainset.pth \
                     TEST.SCALE_LIST 0.5,0.75,1.0,1.25,1.5,1.75 \
                     TEST.FLIP_TEST True

Evaluating our model on the Cityscapes test set with multi-scale and flip testing:

python tools/test.py --cfg experiments/cityscapes/seg_hrnet_w48_train_512x1024_sgd_lr1e-2_wd5e-4_bs_12_epoch484.yaml \
                     DATASET.TEST_SET list/cityscapes/test.lst \
                     TEST.MODEL_FILE hrnet_w48_cityscapes_cls19_1024x2048_trainset.pth \
                     TEST.SCALE_LIST 0.5,0.75,1.0,1.25,1.5,1.75 \
                     TEST.FLIP_TEST True

Evaluating our model on the PASCAL-Context validation set with multi-scale and flip testing:

python tools/test.py --cfg experiments/pascal_ctx/seg_hrnet_w48_cls59_480x480_sgd_lr4e-3_wd1e-4_bs_16_epoch200.yaml \
                     DATASET.TEST_SET testval \
                     TEST.MODEL_FILE hrnet_w48_pascal_context_cls59_480x480.pth \
                     TEST.SCALE_LIST 0.5,0.75,1.0,1.25,1.5,1.75,2.0 \
                     TEST.FLIP_TEST True

Evaluating our model on the LIP validation set with flip testing:

python tools/test.py --cfg experiments/lip/seg_hrnet_w48_473x473_sgd_lr7e-3_wd5e-4_bs_40_epoch150.yaml \
                     DATASET.TEST_SET list/lip/testvalList.txt \
                     TEST.MODEL_FILE hrnet_w48_lip_cls20_473x473.pth \
                     TEST.FLIP_TEST True \
                     TEST.NUM_SAMPLES 0

Other applications of HRNet

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

We adopt sync-bn implemented by InplaceABN.

We adopt data precosessing on the PASCAL-Context dataset, implemented by PASCAL API.