ConTNet: Why not use convolution and transformer at the same time?

Haotian Yan, Zhe Li, Weijian Li, Changhu Wang, Ming Wu, Chuang ZhangarXiv 2021

Abstract

ConTNet is a hybrid neural network architecture that interweaves Standard Transformer Encoders (STE) with convolutional layers. By combining the global context of Transformers with the local efficiency of Convolutional Neural Networks (ConvNets), ConTNet matches the performance of state-of-the-art models like DeiT-B while requiring 60% less computational complexity. Furthermore, it retains the training ease of standard ResNet architectures, making it a robust choice for various vision tasks.

Introduction

Convolutional Neural Networks (ConvNets) have long dominated computer vision due to their efficiency and translation equivariance. However, their local receptive fields limit their ability to capture long-range dependencies without excessive depth. Vision Transformers (ViTs) address this via self-attention but are often data-hungry and difficult to optimize, requiring massive datasets or complex training recipes. ConTNet proposes a middle ground: a hybrid architecture that leverages both convolutions and transformers to achieve global awareness with local efficiency.

Methodology

The core of the architecture is the ConT block, designed as a drop-in replacement for standard convolutional stages.

The ConT Block Architecture

Each ConT block integrates two Standard Transformer Encoders (STE) followed by a 3x3 spatial convolution. This arrangement allows the network to alternate between capturing global contextual features and local fine-grained details.

The ConTNet architecture integrates spatial convolutions with Transformer encoders in a residual structure.

Patch-wise STE and Hierarchical Design

To maintain computational efficiency, the STE operates on a grid of patches rather than the entire image at once. This "super-kernel" approach provides a massive receptive field while preserving patch-wise translation equivariance. Following the ResNet blueprint, ConTNet is organized into four hierarchical stages with decreasing spatial resolution and increasing channel depth, ensuring compatibility with downstream tasks like object detection.

Experiments and Results

ConTNet was evaluated on ImageNet-1k for classification, COCO 2017 for detection/segmentation, and Cityscapes for semantic segmentation.

ImageNet Classification

ConTNet variants consistently outperform their ResNet counterparts in both accuracy and efficiency. For instance, ConT-B achieves a top-1 accuracy of 81.8% with only 6.4G FLOPs, significantly more efficient than pure Transformer models like DeiT-B.

Comparison of ConTNet variants against ResNet baselines in terms of FLOPs, parameters, and Top-1 accuracy.

Downstream Tasks

In object detection on COCO, ConT-M as a backbone for Faster R-CNN outperformed ResNet-50 by 2.6% AP. In instance segmentation (Mask R-CNN), it improved the baseline by 3.2% AP. These results highlight the value of global context for complex spatial tasks.

Conclusion

ConTNet demonstrates that the strengths of convolutions and transformers are complementary. By strategically placing transformers within a convolutional framework, the model achieves high performance with reduced computational costs and enhanced training stability. Future work may explore more advanced transformer variants or depth-wise separable convolutions to further optimize the efficiency-accuracy trade-off.

Summary updated

BibTeX
@misc{yan2021contnet,
  author = {Haotian Yan and Zhe Li and Weijian Li and Changhu Wang and Ming Wu and Chuang Zhang},
  title = {{ConTNet: Why not use convolution and transformer at the same time?}},
  year = {2021},
  eprint = {2104.13497},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2104.13497},
}
Figure