Home

Awesome

InceptionNeXt: When Inception Meets ConvNeXt (CVPR 2024)

<p align="left"> <a href="https://arxiv.org/abs/2303.16900" alt="arXiv"> <img src="https://img.shields.io/badge/arXiv-2203.16900-b31b1b.svg?style=flat" /></a> <a href="https://colab.research.google.com/drive/1-CAPm6FNKYRbe_lAPxIBxsIH4xowgfg8?usp=sharing" alt="Colab"> <img src="https://colab.research.google.com/assets/colab-badge.svg" /></a> </p>

This is a PyTorch implementation of InceptionNeXt proposed by our paper "InceptionNeXt: When Inception Meets ConvNeXt". Many thanks to Ross Wightman, InceptionNeXt is integrated into timm.

InceptionNeXt TLDR: To speed up ConvNeXt, we build InceptionNeXt by decomposing the large kernel dpethweise convolution with Inception style. Our InceptionNeXt-T enjoys both ResNet-50’s speed and ConvNeXt-T’s accuracy.

Requirements

Our models are trained and tested in the environment of PyTorch 1.13, NVIDIA CUDA 11.7.1 and timm 0.6.11 (pip install timm==0.6.11). If you use docker, check Dockerfile that we used.

Data preparation: ImageNet with the following folder structure, you can extract ImageNet by this script.

│imagenet/
├──train/
│  ├── n01440764
│  │   ├── n01440764_10026.JPEG
│  │   ├── n01440764_10027.JPEG
│  │   ├── ......
│  ├── ......
├──val/
│  ├── n01440764
│  │   ├── ILSVRC2012_val_00000293.JPEG
│  │   ├── ILSVRC2012_val_00002138.JPEG
│  │   ├── ......
│  ├── ......

Models

InceptionNeXt trained on ImageNet-1K

ModelResolutionParamsMACsTrain throughputInfer. throughputTop1 Acc
mobilenetv2_1402246.1M0.60G1001519074.7
efficientnet_b02245.3M0.40G954550277.1
ghostnet_1302247.3M0.24G946745175.7
convnext_atto2243.7M0.55G835453975.7
inceptionnext_atto2244.2M0.51G2661987675.3
resnet5022426M4.1G969314978.4
convnext_tiny22429M4.5G575241382.1
inceptionnext_tiny22428M4.2G901290082.3
inceptionnext_small22449M8.4G521175083.5
inceptionnext_base22487M14.9G375124484.0
inceptionnext_base_38438487M43.6G13942885.2

ConvNeXt variants trained on ImageNet-1K

ModelResolutionParamsMACsTrain throughputInfer. throughputTop1 Acc
resnet5022426M4.1G969314978.4
convnext_tiny22429M4.5G575241382.1
convnext_tiny_k522429M4.4G675270482.0
convnext_tiny_k322428M4.4G798280281.5
convnext_tiny_k3_par1_222428M4.4G818274081.4
convnext_tiny_k3_par3_822428M4.4G847276281.4
convnext_tiny_k3_par1_422428M4.4G871280881.3
convnext_tiny_k3_par1_822428M4.4G901283380.8
convnext_tiny_k3_par1_1622428M4.4G916284680.1

The throughputs are measured on an A100 with full precisioni and batch size of 128. See Benchmarking throughput.

Usage

We also provide a Colab notebook which run the steps to perform inference with InceptionNeXt: Colab

Validation

To evaluate our CAFormer-S18 models, run:

MODEL=inceptionnext_tiny
python3 validate.py /path/to/imagenet  --model $MODEL -b 128 \
  --pretrained

Benchmarking throughput

On the environment described above, we benchmark throughputs on an A100 with batch size of 128. The beter results of "Channel First" and "Channel Last" memory layouts are reported.

For Channel First:

MODEL=inceptionnext_tiny # convnext_tiny
python3 benchmark.py /path/to/imagenet  --model $MODEL

For Channel Last:

MODEL=inceptionnext_tiny # convnext_tiny
python3 benchmark.py /path/to/imagenet  --model $MODEL --channel-last

Train

We use batch size of 4096 by default and we show how to train models with 8 GPUs. For multi-node training, adjust --grad-accum-steps according to your situations.

DATA_PATH=/path/to/imagenet
CODE_PATH=/path/to/code/inceptionnext # modify code path here


ALL_BATCH_SIZE=4096
NUM_GPU=8
GRAD_ACCUM_STEPS=4 # Adjust according to your GPU numbers and memory size.
let BATCH_SIZE=ALL_BATCH_SIZE/NUM_GPU/GRAD_ACCUM_STEPS


MODEL=inceptionnext_tiny # inceptionnext_small, inceptionnext_base
DROP_PATH=0.1 # 0.3, 0.4


cd $CODE_PATH && sh distributed_train.sh $NUM_GPU $DATA_PATH \
--model $MODEL --opt adamw --lr 4e-3 --warmup-epochs 20 \
-b $BATCH_SIZE --grad-accum-steps $GRAD_ACCUM_STEPS \
--drop-path $DROP_PATH

Training (fine-tuning) scripts of other models are shown in scripts.

Bibtex

@inproceedings{yu2024inceptionnext,
  title={Inceptionnext: When inception meets convnext},
  author={Yu, Weihao and Zhou, Pan and Yan, Shuicheng and Wang, Xinchao},
  booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  pages={5672--5683},
  year={2024}
}

Acknowledgment

Weihao Yu would like to thank TRC program and GCP research credits for the support of partial computational resources. Our implementation is based on pytorch-image-models, poolformer, ConvNeXt and metaformer.