Skip to content

Latest commit

 

History

History

ResT: An Efficient Transformer for Visual Recognition. NeurIPS 2021 arxiv

ResT V2: Simpler, Faster and Stronger. arXiv 2022. arxiv

PaddlePaddle training/validation code and pretrained models for the model released: ResT and ResTV2.

The official PyTorch implementation is here.

This implementation is developed by PaddleViT.

drawing

ResTv2 and v2 Model Overview

Update

  • Update (2022-05-26): Code is released and ported weights are uploaded.

Models Zoo

Model Acc@1 Acc@5 #Params FLOPs Image Size Crop_pct Interpolation Link
ResT_lite 77.18 93.70 10.5M 1.5G 224 0.9 bicubic google/baidu
ResT_small 79.55 94.92 13.7M 2.0G 224 0.9 bicubic google/baidu
ResT_base 81.60 95.65 30.3M 4.6G 224 0.9 bicubic google/baidu
ResT_large 83.57 96.26 51.7M 8.2G 224 0.9 bicubic google/baidu
ResTV2_lite 82.32 95.48 30.4M 4.0G 224 0.9 bicubic google/baidu
ResTV2_small 83.18 96.06 41.2M 5.9G 224 0.9 bicubic google/baidu
ResTV2_base 83.70 96.25 56.0M 7.8G 224 0.9 bicubic google/baidu
ResTV2_large 84.24 96.51 86.5M 13.7G 224 0.9 bicubic google/baidu

*The results are evaluated on ImageNet2012 validation set.

Data Preparation

ImageNet2012 dataset is used in the following file structure:

│imagenet/
├──train_list.txt
├──val_list.txt
├──train/
│  ├── n01440764
│  │   ├── n01440764_10026.JPEG
│  │   ├── n01440764_10027.JPEG
│  │   ├── ......
│  ├── ......
├──val/
│  ├── n01440764
│  │   ├── ILSVRC2012_val_00000293.JPEG
│  │   ├── ILSVRC2012_val_00002138.JPEG
│  │   ├── ......
│  ├── ......
  • train_list.txt: list of relative paths and labels of training images. You can download it from: google/baidu
  • val_list.txt: list of relative paths and labels of validation images. You can download it from: google/baidu

Usage

To use the model with pretrained weights, download the .pdparam weight file and change related file paths in the following python scripts. The model config files are located in ./configs/.

For example, assume weight file is downloaded in ./restv2_tiny.pdparams, to use the restv2_tiny model in python:

from config import get_config
from rest_v2 import build_restv2 as build_model
# config files in ./configs/
config = get_config('./configs/restv2_tiny.yaml')
# build model
model = build_model(config)
# load pretrained weights
model_state_dict = paddle.load('./restv2_tiny.pdparams')
model.set_state_dict(model_state_dict)

Evaluation

To evaluate model performance on ImageNet2012, run the following script using command line:

sh run_eval_multi.sh

or

CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 \
python main_multi_gpu.py \
-cfg='./configs/restv2_tiny.yaml' \
-dataset='imagenet2012' \
-batch_size=256 \
-data_path='/dataset/imagenet' \
-eval \
-pretrained='./restv2_tiny.pdparams' \
-amp

Note: if you have only 1 GPU, change device number to CUDA_VISIBLE_DEVICES=0 would run the evaluation on single GPU.

Training

To train the model on ImageNet2012, run the following script using command line:

sh run_train_multi.sh

or

CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 \
python main_multi_gpu.py \
-cfg='./configs/restv2_tiny.yaml' \
-dataset='imagenet2012' \
-batch_size=256 \
-data_path='/dataset/imagenet' \
-amp

Note: it is highly recommanded to run the training using multiple GPUs / multi-node GPUs.

Reference

@inproceedings{zhang2021rest,
  title={ResT: An Efficient Transformer for Visual Recognition},
  author={Qinglong Zhang and Yu-bin Yang},
  booktitle={Advances in Neural Information Processing Systems},
  year={2021},
  url={https://openreview.net/forum?id=6Ab68Ip4Mu}
}

@article{zhang2022rest,
  title={ResT V2: Simpler, Faster and Stronger},
  author={Zhang, Qing-Long and Yang, Yu-Bin},
  journal={arXiv preprint arXiv:2204.07366},
  year={2022}
}