Skip to main content
QUICK REVIEW

[Paper Review] Twins: Revisiting the Design of Spatial Attention in Vision Transformers

Xiangxiang Chu, Zhi Tian|arXiv (Cornell University)|Apr 28, 2021
3D Surveying and Cultural HeritageEarth and Planetary Sciences43 references616 citations
TL;DR

The paper proposes two vision transformer backbones, Twins-PCPVT and Twins-SVT, introducing a simple yet effective spatial attention design that combines conditional positional encoding with global sub-sampled and locally grouped attention, achieving strong results on classification, segmentation, and detection with efficient computation.

ABSTRACT

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 https://github.com/Meituan-AutoML/Twins .

Motivation & Objective

  • Revisit and improve the design of spatial attention in vision transformers for dense prediction tasks.
  • Demonstrate that a simple, efficient attention design can match or exceed state-of-the-art backbones with reduced computation.
  • Provide two architectures (Twins-PCPVT and Twins-SVT) that perform well across image-level and pixel-level vision tasks.
  • Show that positional encoding and attention design choices crucially impact performance and deployment efficiency.

Proposed method

  • Introduce Twins-PCPVT by replacing PVT's absolute positional encoding with conditional positional encodings (CPE) and using a position encoding generator (PEG) after the first encoder block of each stage.
  • Propose Twins-SVT with Spatially Separable Self-Attention (SSSA) combining locally-grouped self-attention (LSA) and global sub-sampled attention (GSA) to balance local and global information.
  • Formulate SSSA as a sequence of LayerNorm, attention/FFN blocks, and residual connections similar to standard transformers.
  • Use PEG/CPE for position encoding to handle variable input sizes and improve translation invariance.
  • Benchmark the models on ImageNet-1K, ADE20K, COCO with RetinaNet and Mask R-CNN to assess classification, segmentation, and detection performance.
  • Highlight deployment advantages over Swin by avoiding window-shift operations and enabling efficient matrix multiplications.

Experimental results

Research questions

  • RQ1Can a simple spatial attention design rival or surpass state-of-the-art backbones (e.g., Swin, PVT) for dense prediction tasks?
  • RQ2Do conditional positional encodings and a global sub-sampled attention strategy improve performance with comparable FLOPs?
  • RQ3Is interleaving local and global attention (SSSA) an effective and deployment-friendly alternative to complex shifted-window mechanisms?
  • RQ4How do the proposed Twins backbones perform across image classification, semantic/instance segmentation, and object detection datasets?

Key findings

  • Twins-PCPVT-S outperforms PVT-small by 1.4% and matches Swin-T with 18% fewer FLOPs.
  • Twins-SVT-S surpasses Swin-T with about 35% fewer FLOPs.
  • Twins-SVT-S achieves 1.7% higher mIoU than Swin-T in Semantic FPN/ADE20K setup; Twins-SVT-L surpasses Swin-B by 0.7% mIoU.
  • Twins-PCPVT-S on ADE20K shows +4.5% mIoU over PVT-Small and exceeds ResNet-50 by 7.6% mIoU; Twins-PCPVT-B/ L similarly outperform their PVT counterparts.
  • Twins-SVT-S and Twins-SVT-B achieve comparable or better performance than Swin variants in COCO object detection and instance segmentation across 1x and 3x schedules.
  • Replacing Swin-T's relative PE with CPVT does not improve detection, suggesting gains stem from the Twins-SVT design rather than positional encoding alone.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.