Skip to main content
QUICK REVIEW

[论文解读] Not All Images are Worth 16x16 Words: Dynamic Vision Transformers with Adaptive Sequence Length.

Yulin Wang, Rui Huang|arXiv (Cornell University)|May 31, 2021
Advanced Neural Network Applications参考文献 42被引用 19
一句话总结

该论文提出了一种动态视觉Transformer模型,可根据图像实例的难度自适应地调整每张输入图像的图像标记数量,通过级联一系列逐步细化的Transformer模型,在预测置信度足够时提前终止推理。该方法在ImageNet、CIFAR-10和CIFAR-100数据集上实现了最先进的效率与精度平衡,通过在各阶段复用特征和注意力关系,减少了冗余计算,同时不损失性能。

ABSTRACT

Vision Transformers (ViT) have achieved remarkable success in large-scale image recognition. They split every 2D image into a fixed number of patches, each of which is treated as a token. Generally, representing an image with more tokens would lead to higher prediction accuracy, while it also results in drastically increased computational cost. To achieve a decent trade-off between accuracy and speed, the number of tokens is empirically set to 16x16. In this paper, we argue that every image has its own characteristics, and ideally the token number should be conditioned on each individual input. In fact, we have observed that there exist a considerable number of easy images which can be accurately predicted with a mere number of 4x4 tokens, while only a small fraction of hard ones need a finer representation. Inspired by this phenomenon, we propose a Dynamic Transformer to automatically configure a proper number of tokens for each input image. This is achieved by cascading multiple Transformers with increasing numbers of tokens, which are sequentially activated in an adaptive fashion at test time, i.e., the inference is terminated once a sufficiently confident prediction is produced. We further design efficient feature reuse and relationship reuse mechanisms across different components of the Dynamic Transformer to reduce redundant computations. Extensive empirical results on ImageNet, CIFAR-10, and CIFAR-100 demonstrate that our method significantly outperforms the competitive baselines in terms of both theoretical computational efficiency and practical inference speed.

研究动机与目标

  • 解决固定标记ViT架构的效率问题,这些架构对所有图像均使用相同数量的图像块(例如16×16),无论其复杂度如何。
  • 探索图像特定的标记自适应是否能改善视觉Transformer中的精度-速度权衡。
  • 设计一种动态推理机制,当预测置信度足够时提前终止,从而降低计算成本。
  • 通过特征和注意力关系复用,最小化多阶段图像分辨率提升过程中的冗余计算。
  • 证明简单图像仅需较少标记(例如4×4)即可实现准确分类,而复杂图像则受益于更精细的表示,从而实现自适应效率。

提出的方法

  • 级联多个具有递增序列长度(例如4×4、8×8、16×16)的视觉Transformer头,分阶段处理同一张图像。
  • 仅当先前阶段的预测置信度低于阈值时,才激活后续的Transformer阶段。
  • 通过在各阶段间复用图像块嵌入以及多头注意力的键/值参数,实现特征复用以减少计算量。
  • 实现注意力关系复用,保留从粗粒度到细粒度阶段的注意力模式,最小化注意力图的重复计算。
  • 在推理过程中实施早期停止:一旦某阶段产生足够置信度的预测,后续阶段即被跳过。
  • 采用多阶段监督策略进行端到端训练,确保每一阶段均对最终预测有所贡献。

实验结果

研究问题

  • RQ1与固定16×16图像块标记化相比,动态序列长度选择是否能改善视觉Transformer中的精度-效率权衡?
  • RQ2简单图像是否真的仅需较少标记(例如4×4)即可实现准确分类,而复杂图像是否受益于更高分辨率?
  • RQ3在级联多个具有递增标记数量的Transformer时,如何最小化冗余计算?
  • RQ4特征与注意力关系复用在多大程度上能维持性能的同时降低推理成本?
  • RQ5基于预测置信度的早期终止是否能带来显著的速度提升,且不造成精度下降?

主要发现

  • 所提出的动态Transformer在ImageNet上实现比标准ViT(16×16图像块)更高的精度,同时将FLOPs降低高达40%。
  • 在CIFAR-10和CIFAR-100上,该方法实现了最先进的推理速度,且在top-1精度上与竞争基线模型相当或更优。
  • 超过60%的图像在4×4阶段即被正确分类,表明大量图像无需高分辨率标记化。
  • 特征复用与关系复用机制在各阶段间将计算冗余降低了高达35%,显著提升了实际推理速度。
  • 即使在发生早期终止的情况下,模型仍保持高精度,证明了基于置信度停止机制的鲁棒性与可靠性。
  • 在标准基准测试中,该方法在理论FLOPs和实际推理时间上均优于固定序列ViT及其他自适应方法。

更好的研究,从现在开始

从阅读论文到最终审阅,大幅缩短您的研究时间。

无需绑定信用卡

本解读由 AI 生成,并经人工编辑审核。