Skip to main content
QUICK REVIEW

[Paper Review] Vision Transformers with Hierarchical Attention

Yun Liu, Yuhuan Wu|arXiv (Cornell University)|Jun 6, 2021
Visual Attention and Saliency DetectionComputer Science18 citations
TL;DR

This paper proposes Hierarchical Multi-Head Self-Attention (H-MHSA), a novel mechanism that computes self-attention in a two-stage hierarchical fashion—first modeling local relationships within small image patches, then modeling global dependencies across merged, larger patches. By restricting attention computation to a limited number of tokens at each level, H-MHSA significantly reduces computational and memory costs while preserving fine-grained details, enabling the HAT-Net family to achieve state-of-the-art performance across image classification, semantic segmentation, object detection, and instance segmentation tasks.

ABSTRACT

This paper tackles the high computational/space complexity associated with Multi-Head Self-Attention (MHSA) in vanilla vision transformers. To this end, we propose Hierarchical MHSA (H-MHSA), a novel approach that computes self-attention in a hierarchical fashion. Specifically, we first divide the input image into patches as commonly done, and each patch is viewed as a token. Then, the proposed H-MHSA learns token relationships within local patches, serving as local relationship modeling. Then, the small patches are merged into larger ones, and H-MHSA models the global dependencies for the small number of the merged tokens. At last, the local and global attentive features are aggregated to obtain features with powerful representation capacity. Since we only calculate attention for a limited number of tokens at each step, the computational load is reduced dramatically. Hence, H-MHSA can efficiently model global relationships among tokens without sacrificing fine-grained information. With the H-MHSA module incorporated, we build a family of Hierarchical-Attention-based Transformer Networks, namely HAT-Net. To demonstrate the superiority of HAT-Net in scene understanding, we conduct extensive experiments on fundamental vision tasks, including image classification, semantic segmentation, object detection, and instance segmentation. Therefore, HAT-Net provides a new perspective for vision transformers. Code and pretrained models are available at https://github.com/yun-liu/HAT-Net.

Motivation & Objective

  • To address the high computational and memory complexity of Multi-Head Self-Attention (MHSA) in vanilla vision transformers due to long sequence lengths from image patches.
  • To enable efficient modeling of both local and global dependencies in vision transformers without sacrificing fine-grained spatial details.
  • To design a flexible, efficient, and scalable transformer architecture that outperforms existing methods on diverse vision benchmarks.
  • To demonstrate the effectiveness of hierarchical attention through comprehensive experiments on image classification, semantic segmentation, object detection, and instance segmentation.

Proposed method

  • The input image is divided into patches, each treated as a token, forming the initial sequence for attention computation.
  • Local self-attention is computed within small grids of patches (controlled by parameter G1), capturing fine-grained local relationships.
  • Smaller patches are merged into larger ones through downsampling (controlled by parameter G2), reducing the number of tokens for global attention computation.
  • Global self-attention is applied to the merged, coarser tokens to model long-range dependencies across the image.
  • Local and global attentive features are concatenated and aggregated to form final features with rich, multi-scale representations.
  • The H-MHSA module is integrated into a family of networks called HAT-Net, which uses depthwise separable convolutions and SiLU activation for efficiency and performance.

Experimental results

Research questions

  • RQ1Can a hierarchical attention mechanism effectively reduce the computational cost of vision transformers while maintaining or improving performance?
  • RQ2How does combining local and global attention in a hierarchical manner affect feature representation in vision transformers?
  • RQ3To what extent can H-MHSA outperform existing attention mechanisms like window-based or downsampling-based approaches in downstream vision tasks?
  • RQ4What is the optimal configuration of local grid size (G1) and downsampling rate (G2) for balancing accuracy and efficiency?

Key findings

  • HAT-Net with H-MHSA achieves 82.6% top-1 accuracy on ImageNet-1K with 300 training epochs, outperforming PVT under the same training conditions.
  • The HAT-Net-Small variant achieves 45.7% mIoU on ADE20K for semantic segmentation, demonstrating strong generalization across tasks.
  • In object detection on MS-COCO, HAT-Net-Small achieves 45.7% APb, 67.8% APb50, and 44.7% APb75, showing strong performance with reduced FLOPs.
  • H-MHSA improves performance across all evaluated tasks—image classification, semantic segmentation, object detection, and instance segmentation—compared to baseline transformers.
  • Using SiLU activation instead of GELU reduces GPU memory consumption from 23.8GB to 20.2GB while maintaining or slightly improving performance.
  • The default configuration of G1 = 8,8,8 and G2 = 16,8,4 offers a favorable trade-off between accuracy and computational efficiency across diverse settings.

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.