Home

Awesome

ConTNet

Introduction

<!-- **ConTNet** (**Con**vlution-**T**ranformer Network) is proposed mainly in response to the following two issues: (1) ConvNets lack a large receptive field, limiting the performance of ConvNets on downstream tasks. (2) Transformer-based model is not robust enough and requires special training settings or hundreds of millions of images as the pretrain dataset, thereby limiting their adoption. **ConTNet** combines convolution and transformer alternately, which is very robust and can be optimized like ResNet unlike the recently-proposed transformer-based models (e.g., ViT, DeiT) that are sensitive to hyper-parameters and need many tricks when trained from scratch on a midsize dataset (e.g., ImageNet). -->

ConTNet (Convlution-Tranformer Network) is a neural network built by stacking convolutional layers and transformers alternately. This architecture is proposed in response to the following two issues: (1) The receptive field of convolution is limited by a local window (3x3), which potentially impairs the performance of ConvNets on downstream tasks. (2) Transformer-based models suffers from insufficient robustness, as a result, the training course requires multiple training tricks and tons of regularization strategies. In our ConTNet, these drawbacks are alleviated through the combination of convolution and transformer. Two perspectives are offered to understand the motivation. From the view of ConvNet, the transformer sub-layer is inserted between any two conv layers to enhance the non-local interactions of ConvNet. From the view of Transformer, the presence of convolution layers reintroduces the inductive bias as a cause of under-fitting. Through numerical experiments, we find that ConTNet achieves competitive performance on image recognition and downstream tasks. More notably, ConTNet can be optimized easily even in the same way as ResNet.

<!-- ![image](https://user-images.githubusercontent.com/81896692/119272384-2b904e00-bc38-11eb-87a5-193275cc8be2.png) -->

image image image

Training & Validation with this Repo

We give an example of one machine multi-gpus training.

CUDA_VISIBLE_DEVICES=0,1,2,3 python3 -m torch.distributed.launch --nproc_per_node=4 --master_port 29501 main.py --arch ConT-M --batch_size 256 --save_path debug_trial_cont_m --save_best True 

To validate a model, please add the arg --eval .

CUDA_VISIBLE_DEVICES=0 python3 -m torch.distributed.launch --nproc_per_node=1 --master_port 29501 main.py --arch ConT-M --batch_size 256 --save_path debug_trial --eval ./debug_trial_cont_m/checkpoint_bestTop1.pth

To implement resume training, please add the arg --resume.

CUDA_VISIBLE_DEVICES=0,1,2,3 python3 -m torch.distributed.launch --nproc_per_node=4 --master_port 29501 main.py --arch ConT-M --batch_size 256 --save_path debug_trial --save_best True --resume ./debug_trial_cont_m/checkpoint_bestTop1.pth

Pretrained Weights on ImageNet

ImageNet-pretrained weights are available from Google Drive or Baidu Cloud(the code is 3k3s).

Main Results on ImageNet

nameresolutionacc@1#params(M)FLOPs(G)model
Res-18224x22471.511.71.8
ConT-S224x22474.910.11.5
Res-50224x22477.125.64.0
ConT-M224x22477.619.23.1
Res-101224x22478.244.57.6
ConT-B224x22477.939.66.4
DeiT-Ti<sup>*</sup>224x22472.25.71.3
ConT-Ti<sup>*</sup>224x22474.95.80.8
Res-18<sup>*</sup>224x22473.211.71.8
ConT-S<sup>*</sup>224x22476.510.11.5
Res-50<sup>*</sup>224x22478.625.64.0
DeiT-S<sup>*</sup>224x22479.822.14.6
ConT-M<sup>*</sup>224x22480.219.23.1
Res-101<sup>*</sup>224x22480.044.57.6
DeiT-B<sup>*</sup>224x22481.886.617.6
ConT-B<sup>*</sup>224x22481.839.66.4

Note: <sup>*</sup> indicates training with strong augmentations(auto-augmentation and mixup).

Main Results on Downstream Tasks

Object detection results on COCO.

methodbackbone#params(M)FLOPs(G)APAP</sup>s<sup>AP</sup>m<sup>AP</sup>l<sup>
RetinaNetRes-50 <br> ConTNet-M32.0 <br> 27.0235.6 <br> 217.236.5 <br> 37.920.4 <br> 23.040.3 <br> 40.648.1 <br> 50.4
FCOSRes-50 <br> ConTNet-M32.2 <br> 27.2242.9 <br> 228.438.7 <br> 40.822.9 <br> 25.142.5 <br> 44.650.1 <br> 53.0
faster rcnnRes-50 <br> ConTNet-M41.5 <br> 36.6241.0 <br> 225.637.4 <br> 40.021.2 <br> 25.441.0 <br> 43.048.1 <br> 52.0

Instance segmentation results on Cityscapes based on Mask-RCNN.

backboneAP<sup>bb</sup>AP<sub>s</sub><sup>bb</sup>AP<sub>m</sub><sup>bb</sup>AP<sub>l</sub><sup>bb</sup>AP<sup>mk</sup>AP<sub>s</sub><sup>mk</sup>AP<sub>m</sub><sup>mk</sup>AP<sub>l</sub><sup>mk</sup>
Res-50 <br> ConT-M38.2 <br> 40.521.9 <br> 25.140.9 <br> 44.449.5 <br> 52.734.7 <br> 38.118.3 <br> 20.937.4 <br> 41.047.2 <br> 50.3

Semantic segmentation results on cityscapes.

modelmIOU
PSP-Res5077.12
PSP-ConTM78.28

Bib Citing

@article{yan2021contnet,
    title={ConTNet: Why not use convolution and transformer at the same time?},
    author={Haotian Yan and Zhe Li and Weijian Li and Changhu Wang and Ming Wu and Chuang Zhang},
    year={2021},
    journal={arXiv preprint arXiv:2104.13497}
}