On the Integration of Self-Attention and Convolution

Xuran Pan, Chunjiang Ge, Rui Lu, Shiji Song, Guanfu Chen +2 more
11/29/2021
529 citations
cs.CV
transformer-attention

Official code: LeapLabTHU/ACmix (411 stars, Python, last commit 2022-04-25).

Abstract

Convolution and self-attention are two powerful techniques for representation learning, and they are usually considered as two peer approaches that are distinct from each other. In this paper, we show that there exists a strong underlying relation between them, in the sense that the bulk of computations of these two paradigms are in fact done with the same operation.

Show full abstract

Specifically, we first show that a traditional convolution with kernel size k x k can be decomposed into k^2 individual 1x1 convolutions, followed by shift and summation operations. Then, we interpret the projections of queries, keys, and values in self-attention module as multiple 1x1 convolutions, followed by the computation of attention weights and aggregation of the values. Therefore, the first stage of both two modules comprises the similar operation. More importantly, the first stage contributes a dominant computation complexity (square of the channel size) comparing to the second stage. This observation naturally leads to an elegant integration of these two seemingly distinct paradigms, i.e., a mixed model that enjoys the benefit of both self-Attention and Convolution (ACmix), while having minimum computational overhead compared to the pure convolution or self-attention counterpart. Extensive experiments show that our model achieves consistently improved results over competitive baselines on image recognition and downstream tasks. Code and pre-trained models will be released at https://github.com/LeapLabTHU/ACmix and https://gitee.com/mindspore/models.

View on arXivView PDF

Code Implementations(1)

LeapLabTHU/ACmixOfficial100%

Official repository of ACmix (CVPR2022)

41144PythonMar 14, 20224 years ago

Similar Papers

Cite this paper

@article{pan2021integration,
  title  = {On the Integration of Self-Attention and Convolution},
  author = {Xuran Pan and Chunjiang Ge and Rui Lu and Shiji Song and Guanfu Chen and Zeyi Huang and Gao Huang},
  year   = {2021},
  eprint = {2111.14556},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2111.14556}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2111.14556.svg)](https://codeofpaper.com/paper/2111.14556)

Discussion