arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~
arXiv 2105.15075cs.CVcs.AIcs.LG
收藏

并非所有的图像都值得16 x16字:用于高效图像识别的动态Transformers

Not All Images are Worth 16x16 Words: Dynamic Transformers for Efficient Image Recognition

Tsinghua University(清华大学);Huawei Technologies Ltd.(华为技术有限公司);Beijing Academy of Artificial Intelligence(北京智源人工智能研究院)

Yulin Wang, Rui Huang, Shiji Song, Zeyi Huang, Gao Huang

摘要:

视觉Transformer(ViT)在大规模图像识别中取得了显著的成功。他们将每个2D图像分成固定数量的补丁,每个补丁都被视为一个令牌。通常,用更多的标记表示图像将导致更高的预测精度,同时也会导致计算成本急剧增加。为了在准确性和速度之间实现适当的权衡,令牌的数量根据经验设置为16 x16或14 x14。在本文中,我们认为,每一个图像都有自己的特点,理想情况下,令牌数应取决于每个单独的输入。事实上,我们已经观察到,存在相当数量的“简单”图像,可以用仅仅数量的4x 4令牌准确预测,而只有一小部分“困难”图像需要更精细的表示。受此现象的启发,我们提出了一个动态的Transformer自动配置适当数量的令牌为每个输入图像。这是通过级联多个Transformers来实现的,其中令牌的数量不断增加,这些令牌在测试时以自适应方式顺序激活,即,一旦产生了足够可信的预测,则终止推断。我们进一步设计了跨动态Transformer不同组件的有效特征重用和关系重用机制,以减少冗余计算。在ImageNet、CIFAR-10和CIFAR-100上的大量实证结果表明,我们的方法在理论计算效率和实际推理速度方面都明显优于竞争基线。代码和预训练模型(基于PyTorch和MindSpore)可在https://github.com/blackfeather-wang/Dynamic-Vision-Transformer和https://github.com/blackfeather-wang/Dynamic-Vision-Transformer-MindSpore上获得。

英文摘要:

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 or 14x14. 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. Code and pre-trained models (based on PyTorch and MindSpore) are available at https://github.com/blackfeather-wang/Dynamic-Vision-Transformer and https://github.com/blackfeather-wang/Dynamic-Vision-Transformer-MindSpore.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑