Home

Awesome

EMO


Official PyTorch implementation of "Rethinking Mobile Block for Efficient Attention-based Models, ICCV'23".

Abstract: This paper focuses on developing modern, efficient, lightweight models for dense predictions while trading off parameters, FLOPs, and performance. Inverted Residual Block (IRB) serves as the infrastructure for lightweight CNNs, but no counterpart has been recognized by attention-based studies. This work rethinks lightweight infrastructure from efficient IRB and effective components of Transformer from a unified perspective, extending CNN-based IRB to attention-based models and abstracting a one-residual Meta Mobile Block (MMB) for lightweight model design. Following simple but effective design criterion, we deduce a modern Inverted Residual Mobile Block (iRMB) and build a ResNet-like Efficient MOdel (EMO) with only iRMB for down-stream tasks. Extensive experiments on ImageNet-1K, COCO2017, and ADE20K benchmarks demonstrate the superiority of our EMO over state-of-the-art methods, e.g., EMO-1M/2M/5M achieve 71.5, 75.1, and 78.4 Top-1 that surpass equal-order CNN-/Attention-based models, while trading-off the parameter, efficiency, and accuracy well: running 2.8-4.0×↑ faster than EdgeNeXt on iPhone14. Code is available.

<div align="center"> <img src="resources/emo.png" width="800px" /> </div> <div align="center"> <img src="resources/sota.png" width="480px" /> </div>

Top: Abstracted unified Meta-Mobile Block from Multi-Head Self-Attention and Feed-Forward Network in Transformer as well as efficient Inverted Residual Block in MobileNet-v2. Absorbing the experience of light-weight CNN and Transformer, an efficient but effective EMO is designed based on deduced iRMB.<br> Bottom: Performance vs. FLOPs comparisons with SoTA Transformer-based methods.


Main results

Image Classification for ImageNet-1K:

Model#ParamsFLOPsResolutionTop-1Log
EMO-1M1.3M261M224 x 22471.5log
EMO-2M2.3M439M224 x 22475.1log
EMO-5M5.1M903M224 x 22478.4log
EMO-6M6.1M961M224 x 22479.0log

Object Detection Performance Based on SSDLite for COCO2017:

BackboneAPAP<sub>50</sub>AP<sub>75</sub>AP<sub>S</sub>AP<sub>M</sub>AP<sub>L</sub>#ParamsFLOPsLog
EMO-1M22.037.322.02.120.643.22.3M0.6Glog
EMO-2M25.242.025.33.325.947.63.3M0.9Glog
EMO-5M27.945.228.15.230.250.66.0M1.8Glog

Object Detection Performance Based on RetinaNet for COCO2017:

BackboneAPAP<sub>50</sub>AP<sub>75</sub>AP<sub>S</sub>AP<sub>M</sub>AP<sub>L</sub>#ParamsFLOPsLog
EMO-1M34.454.236.220.237.146.010.4M163Glog
EMO-2M36.256.638.121.738.848.111.5M167Glog
EMO-5M38.959.841.023.842.251.714.4M178Glog

Semantic Segmentation Based on DeepLabv3 for ADE20k:

BackboneaAccmIoUmAcc#ParamsFLOPsLog
EMO-1M75.033.544.25.6M2.4Glog
EMO-2M75.635.346.06.9M3.5Glog
EMO-5M77.637.848.210.3M5.8Glog

Semantic Segmentation Based on PSPNet for ADE20k:

BackboneaAccmIoUmAcc#ParamsFLOPsLog
EMO-1M74.833.243.44.3M2.1Glog
EMO-2M75.534.544.95.5M3.1Glog
EMO-5M77.638.249.08.5M5.3Glog

Classification

Environments

conda install -y pytorch==1.10.1 torchvision==0.11.2 torchaudio==0.10.1 cudatoolkit=11.3 -c pytorch -c conda-forge
pip3 install timm==0.6.5 tensorboardX einops torchprofile fvcore
git clone https://github.com/NVIDIA/apex && cd apex && pip3 install -v --disable-pip-version-check --no-cache-dir --global-option="--cpp_ext" --global-option="--cuda_ext" ./ (optional)

Prepare ImageNet-1K Dataset

Download and extract ImageNet-1K dataset in the following directory structure:

├── imagenet
    ├── train
        ├── n01440764
            ├── n01440764_10026.JPEG
            ├── ...
        ├── ...
    ├── train.txt (optional)
    ├── val
        ├── n01440764
            ├── ILSVRC2012_val_00000293.JPEG
            ├── ...
        ├── ...
    └── val.txt (optional)

Test

Test with 8 GPUs in one node:

python3 -m torch.distributed.launch --nproc_per_node=8 --nnodes=1 --use_env run.py -c configs/mobile/cls_emo -m test model.name=EMO_1M trainer.data.batch_size=2048 model.model_kwargs.checkpoint_path=resources/EMO-1M/net.pth

This should give Top-1: 71.498 (Top-5: 90.368)

<details> <summary> EMO-2M </summary>
python3 -m torch.distributed.launch --nproc_per_node=8 --nnodes=1 --use_env run.py -c configs/mobile/cls_emo -m test model.name=EMO_2M trainer.data.batch_size=2048 model.model_kwargs.checkpoint_path=resources/EMO-2M/net.pth

This should give Top-1 75.134 (Top-5: 92.184)

</details> <details> <summary> EMO-5M </summary>
python3 -m torch.distributed.launch --nproc_per_node=8 --nnodes=1 --use_env run.py -c configs/mobile/cls_emo -m test model.name=EMO_5M trainer.data.batch_size=2048 model.model_kwargs.checkpoint_path=resources/EMO-5M/net.pth

This should give Top-1 78.422 (Top-5: 93.970)

</details> <details> <summary> EMO-6M </summary>
python3 -m torch.distributed.launch --nproc_per_node=8 --nnodes=1 --use_env run.py -c configs/mobile/cls_emo -m test model.name=EMO_6M trainer.data.batch_size=2048 model.model_kwargs.checkpoint_path=resources/EMO-6M/net.pth

This should give Top-1 78.988 (Top-5: 94.162)

</details>

Train

Train with 8 GPUs in one node:

python3 -m torch.distributed.launch --nproc_per_node=8 --nnodes=1 --use_env run.py -c configs/mobile/cls_emo -m train model.name=EMO_1M trainer.data.batch_size=2048


Down-Stream Tasks

Object Detection

Semantic Segmentation

Mobile Evaluation

Citation

If our work is helpful for your research, please consider citing:

@inproceedings{emo,
  title={Rethinking Mobile Block for Efficient Attention-based Models},
  author={Zhang, Jiangning and Li, Xiangtai and Li, Jian and Liu, Liang and Xue, Zhucun and Zhang, Boshen and Jiang, Zhengkai and Huang, Tianxin and Wang, Yabiao and Wang, Chengjie},
  booktitle={Proceedings of the IEEE/CVF International Conference on Computer Vision},
  pages={1389--1400},
  year={2023}
}

Acknowledgements

We thank but not limited to following repositories for providing assistance for our research: