Twins: Revisiting the Design of Spatial Attention in Vision Transformers


Very recently, a variety of vision transformer architectures for dense prediction tasks have been proposed and they show that the design of spatial attention is critical to their success in these tasks. In this work, we revisit the design of the spatial attention and demonstrate that a carefully-devised yet simple spatial attention mechanism performs favourably against the state-of-the-art schemes. As a result, we propose two vision transformer architectures, namely, Twins-PCPVT and Twins-SVT. Our proposed architectures are highly-efficient and easy to implement, only involving matrix multiplications that are highly optimized in modern deep learning frameworks. More importantly, the proposed architectures achieve excellent performance on a wide range of visual tasks, including image level classification as well as dense detection and segmentation. The simplicity and strong performance suggest that our proposed architectures may serve as stronger backbones for many vision tasks. Our code is released at this https URL.

Results and models


Model Params(M) Flops(G) Top-1 (%) Top-5 (%) Config Download
PCPVT-small* 24.11 3.67 81.14 95.69 config model
PCPVT-base* 43.83 6.45 82.66 96.26 config model
PCPVT-large* 60.99 9.51 83.09 96.59 config model
SVT-small* 24.06 2.82 81.77 95.57 config model
SVT-base* 56.07 8.35 83.13 96.29 config model
SVT-large* 99.27 14.82 83.60 96.50 config model

Models with * are converted from the official repo. The config files of these models are only for validation. We don’t ensure these config files’ training accuracy and welcome you to contribute your reproduction results. The validation accuracy is a little different from the official paper because of the PyTorch version. This result is get in PyTorch=1.9 while the official result is get in PyTorch=1.7


  title={Twins: Revisiting spatial attention design in vision transformers},
  author={Chu, Xiangxiang and Tian, Zhi and Wang, Yuqing and Zhang, Bo and Ren, Haibing and Wei, Xiaolin and Xia, Huaxia and Shen, Chunhua},
  journal={arXiv preprint arXiv:2104.13840},
Read the Docs v: latest
On Read the Docs
Project Home

Free document hosting provided by Read the Docs.