The official pytorch implementation of the paper RepGhost: A Hardware-Efficient Ghost Module via Re-parameterization
Feature reuse has been a key technique in light-weight convolutional neural networks (CNNs) design. Current methods usually utilize a concatenation operator to keep large channel numbers cheaply (thus large network capacity) by reusing feature maps from other layers. Although concatenation is parameters- and FLOPs-free, its computational cost on hardware devices is non-negligible. To address this, this paper provides a new perspective to realize feature reuse via structural re-parameterization technique. A novel hardware-efficient RepGhost module is proposed for implicit feature reuse via re-parameterization, instead of using concatenation operator. Based on the RepGhost module, we develop our efficient RepGhost bottleneck and RepGhostNet. Experiments on ImageNet and COCO benchmarks demonstrate that the proposed RepGhostNet is much more effective and efficient than GhostNet and MobileNetV3 on mobile devices. Specially, our RepGhostNet surpasses GhostNet 0.5x by 2.5% Top-1 accuracy on ImageNet dataset with less parameters and comparable latency on an ARM-based mobile phone.
python 3.9.12
pytorch 1.11.0
cuda 11.3
timm 0.6.7
git clone https://github.com/ChengpengChen/RepGhost
cd RepGhost
pip install -r requirements.txt
bash distributed_train.sh 8 --model repghost.repghostnet_0_5x -b 128 --lr 0.6 --sched cosine --epochs 300 --opt sgd -j 7 --warmup-epochs 5 --warmup-lr 1e-4 --weight-decay 1e-5 --drop 0.2 --amp --model-ema --model-ema-decay 0.9999 --remode pixel --reprob 0.2 --output work_dirs/train/ --data_dir {path_to_imagenet_dir}
python3 -m torch.distributed.launch --nproc_per_node=8 --master_port=2340 validate.py -b 32 --model-ema --model {model} --resume {checkpoint_path} --data_dir {path_to_imagenet_dir}
To check the conversion example at convert.py
. You can also convert RepGhostNet model for fast inference via:
model.convert_to_deploy()
RepGhostNet | Params(M) | FLOPs(M) | Latency(ms) | Top-1 Acc.(%) | Top-5 Acc.(%) | checkpoints | logs |
---|---|---|---|---|---|---|---|
0.5x | 2.3 | 43 | 25.1 | 66.9 | 86.9 | gdrive \ 百度网盘 | log |
0.58x | 2.5 | 60 | 31.9 | 68.9 | 88.4 | gdrive \ 百度网盘 | log |
0.8x | 3.3 | 96 | 44.5 | 72.2 | 90.5 | gdrive \ 百度网盘 | log |
1.0x | 4.1 | 142 | 62.2 | 74.2 | 91.5 | gdrive \ 百度网盘 | log |
1.11x | 4.5 | 170 | 71.5 | 75.1 | 92.2 | gdrive \ 百度网盘 | log |
1.3x | 5.5 | 231 | 92.9 | 76.4 | 92.9 | gdrive \ 百度网盘 | log |
1.5x | 6.6 | 301 | 116.9 | 77.5 | 93.5 | gdrive \ 百度网盘 | log |
2.0x | 9.8 | 516 | 190.0 | 78.8 | 94.3 | gdrive \ 百度网盘 | log |
We calculate parameters and FLOPs using a modified thop in tools.py
. It only counts infos of convolutional and full-connected layers, without BN. To use it in your code:
from tools import cal_flops_params
flops, params = cal_flops_params(model, input_size=(1, 3, 224, 224))
We first export our pytorch model to a ONNX one, and then use MNN to convert it to MNN format, at last evaluate its latency on an ARM-based mobile phone.
We compare RepGhostNet to MobileOne on iPhone12 CPU based on ModelBench. The result is shown below.
The MobileOne series models are
If RepGhostNet helps your research or work, please consider citing:
@article{chen2022repghost,
title={RepGhost: A Hardware-Efficient Ghost Module via Re-parameterization},
author={Chen, Chengpeng, and Guo, Zichao, and Zeng, Haien, and Xiong, Pengfei and Dong, Jian},
journal={arXiv preprint arXiv:2211.06088},
year={2022}
}
If you have any questions, please contact [email protected].