[论文解读] Vision Transformers with Hierarchical Attention
本文提出了一种新型机制——分层多头自注意力(H-MHSA),该机制以两级分层方式计算自注意力:首先在小图像块内建模局部关系,然后在合并后更大的块之间建模全局依赖关系。通过在每一层限制注意力计算的标记数量,H-MHSA 显著降低了计算和内存开销,同时保留了细粒度细节,使 HAT-Net 系列模型在图像分类、语义分割、目标检测和实例分割任务中均实现了最先进性能。
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.
研究动机与目标
- 为解决原始视觉变换器中因图像块导致的长序列长度所引发的多头自注意力(MHSA)高计算和内存复杂度问题。
- 在不损失细粒度空间细节的前提下,实现视觉变换器中局部与全局依赖关系的高效建模。
- 设计一种灵活、高效且可扩展的变换器架构,使其在多种视觉基准测试中优于现有方法。
- 通过在图像分类、语义分割、目标检测和实例分割任务上的全面实验,证明分层注意力的有效性。
提出的方法
- 将输入图像划分为图像块,每个图像块被视为一个标记,形成注意力计算的初始序列。
- 在小块网格内计算局部自注意力(由参数 G1 控制),捕捉细粒度的局部关系。
- 通过下采样将较小的块合并为更大的块(由参数 G2 控制),减少用于全局注意力计算的标记数量。
- 对合并后的粗粒度标记应用全局自注意力,以建模图像中长距离依赖关系。
- 将局部和全局注意力特征拼接并聚合,形成具有丰富多尺度表示的最终特征。
- 将 H-MHSA 模块集成到名为 HAT-Net 的网络系列中,该系列采用逐通道可分离卷积和 SiLU 激活函数以提升效率与性能。
实验结果
研究问题
- RQ1分层注意力机制是否能有效降低视觉变换器的计算成本,同时保持或提升性能?
- RQ2以分层方式结合局部与全局注意力,对视觉变换器的特征表示有何影响?
- RQ3H-MHSA 在下游视觉任务中,相较于基于窗口或下采样方法的现有注意力机制,能多大程度上实现性能超越?
- RQ4在局部网格大小(G1)和下采样率(G2)方面,何种配置能在准确率与效率之间实现最佳平衡?
主要发现
- 在相同训练条件下(300个训练周期),采用 H-MHSA 的 HAT-Net 在 ImageNet-1K 上达到 82.6% 的 top-1 准确率,优于 PVT 模型。
- HAT-Net-Small 在 ADE20K 上的语义分割任务中达到 45.7% 的 mIoU,展现出优异的跨任务泛化能力。
- 在 MS-COCO 的目标检测任务中,HAT-Net-Small 达到 45.7% APb、67.8% APb50 和 44.7% APb75,性能强劲且 FLOPs 显著降低。
- 与基线变换器相比,H-MHSA 在所有评估任务(图像分类、语义分割、目标检测和实例分割)中均提升了性能。
- 使用 SiLU 激活函数替代 GELU 可将 GPU 显存消耗从 23.8GB 降低至 20.2GB,同时保持或略微提升性能。
- 默认配置 G1 = 8,8,8 和 G2 = 16,8,4 在多种设置下均实现了准确率与计算效率之间的良好权衡。
阅读本论文
在 Nubint 阅读器中打开原文,边读边就任意段落提问。
在 Nubint 中阅读本论文本解读由 AI 根据论文原文生成,引用前请核对原文。