[论文解读] Slide-Transformer: Hierarchical Vision Transformer with Local Self-Attention
本文提出了一种新颖的局部自注意力机制——Slide-Attention,用于视觉Transformer模型。该方法通过使用深度可分离卷积替代低效的Im2Col操作,在不同硬件平台上实现了高效率与广泛兼容性。通过从行(row-based)视角重新诠释局部注意力机制,并引入可重参数化的变形位移模块,Slide-Attention在图像分类、语义分割和目标检测基准上均达到当前最优性能,同时在iPhone 12等移动设备上实现了1.7倍的推理速度提升。
Self-attention mechanism has been a key factor in the recent progress of Vision Transformer (ViT), which enables adaptive feature extraction from global contexts. However, existing self-attention methods either adopt sparse global attention or window attention to reduce the computation complexity, which may compromise the local feature learning or subject to some handcrafted designs. In contrast, local attention, which restricts the receptive field of each query to its own neighboring pixels, enjoys the benefits of both convolution and self-attention, namely local inductive bias and dynamic feature selection. Nevertheless, current local attention modules either use inefficient Im2Col function or rely on specific CUDA kernels that are hard to generalize to devices without CUDA support. In this paper, we propose a novel local attention module, Slide Attention, which leverages common convolution operations to achieve high efficiency, flexibility and generalizability. Specifically, we first re-interpret the column-based Im2Col function from a new row-based perspective and use Depthwise Convolution as an efficient substitution. On this basis, we propose a deformed shifting module based on the re-parameterization technique, which further relaxes the fixed key/value positions to deformed features in the local region. In this way, our module realizes the local attention paradigm in both efficient and flexible manner. Extensive experiments show that our slide attention module is applicable to a variety of advanced Vision Transformer models and compatible with various hardware devices, and achieves consistently improved performances on comprehensive benchmarks. Code is available at https://github.com/LeapLabTHU/Slide-Transformer.
研究动机与目标
- 解决现有局部注意力模块依赖Im2Col或CUDA专用内核所导致的效率低下与硬件兼容性有限的问题。
- 克服稀疏全局注意力与基于窗口的注意力机制在捕捉局部特征及实现跨窗口通信方面的局限性。
- 设计一种结合卷积局部归纳偏置与自注意力动态特征选择能力的局部注意力机制。
- 通过将计算密集型操作替换为标准深度可分离卷积,确保高效率与广泛的硬件兼容性。
- 通过可重参数化的位移模块实现灵活且可变形的局部特征聚合,同时不牺牲推理速度。
提出的方法
- 从行(row-based)视角重新诠释Im2Col操作,其中每一行对应输入特征图的一个位移版本。
- 将基于列的Im2Col替换为深度可分离卷积,以高效计算局部键(key)和值(value)矩阵,降低计算与内存开销。
- 引入一种变形位移模块,利用重参数化技术在局部感受野内实现动态可学习的键/值位置。
- 使用重参数化技术将多个卷积分支合并为单个推理时的核,以保持模型容量的同时维持高效性。
- 将Slide-Attention模块集成到现有的视觉Transformer架构(如Swin、PVT和CSwin)中,实现即插即用的部署。
- 设计模块时确保硬件无关性,支持无CUDA支持的设备,包括Apple的MPS和移动GPU。
实验结果
研究问题
- RQ1能否设计一种局部注意力机制,使其在计算效率与跨多种硬件平台的兼容性方面均表现优异?
- RQ2在局部注意力中用深度可分离卷积替代Im2Col是否能在不损失性能的前提下提升推理速度?
- RQ3可重参数化的变形位移模块是否能在保持推理效率的同时增强局部注意力的特征表示能力?
- RQ4与全局注意力和基于窗口的注意力相比,Slide-Attention在标准视觉基准上的准确率与速度表现如何?
- RQ5Slide-Attention能否在无需专用硬件的移动设备与边缘设备上有效部署?
主要发现
- 当替换先进视觉Transformer模型中的注意力模块时,Slide-Attention在图像分类、语义分割和目标检测任务中均实现了稳定的性能提升。
- 在支持MPS的iPhone 12上,基于Slide-Attention的Swin-small模型不仅性能优于原始的Swin-base模型,且推理速度提升了1.7倍。
- 该方法展现出高度的效率与泛化能力,在无CUDA支持的设备(如Apple的Metal Performance Shader)上表现良好。
- 可重参数化的变形位移模块在不增加推理时间的前提下提升了模型容量与灵活性。
- 当集成到Swin、PVT和CSwin架构中时,Slide-Attention在ImageNet-1K、ADE20K和COCO基准上均取得了当前最优结果。
- 消融实验表明,行视角重诠释与深度可分离卷积替代显著降低了与标准Im2Col实现相比的计算成本。
阅读本论文
在 Nubint 阅读器中打开原文,边读边就任意段落提问。
在 Nubint 中阅读本论文本解读由 AI 根据论文原文生成,引用前请核对原文。