arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2107.14222cs.CV
收藏

视觉Transformer相对位置编码的反思与改进

Rethinking and Improving Relative Position Encoding for Vision Transformer

Sun Yat-sen University(中山大学);Microsoft Research Asia(微软亚洲研究院)

Kan Wu, Houwen Peng, Minghao Chen, Jianlong Fu, Hongyang Chao

摘要:

相对位置编码(RPE)对于Transformer捕获输入令牌的序列排序是重要的。在自然语言处理中已经证明了一般功效。然而,在计算机视觉中,其功效并没有得到很好的研究,甚至仍然存在争议,例如,相对位置编码是否能像绝对位置编码一样好用?为了澄清这一点,我们首先回顾现有的相对位置编码方法,并分析其优点和缺点时,应用于视觉Transformer。然后,我们提出了新的相对位置编码方法专用于2D图像,称为图像RPE(iRPE)。我们的方法考虑了方向相对距离建模以及查询和自我注意力机制中相对位置嵌入之间的相互作用。所提出的iRPE方法是简单和轻量级的。它们可以很容易地插入到Transformer块中。实验表明,仅仅由于所提出的编码方法,DeiT和DETR在ImageNet和COCO上分别获得了1.5%(top-1 Acc)和1.3%(mAP)的稳定改进,而无需调整任何额外的超参数,如学习率和权重衰减。我们的消融和分析也产生了有趣的发现,其中一些与以前的理解背道而驰。代码和模型在https://github.com/microsoft/Cream/tree/main/iRPE上开源。

英文摘要:

Relative position encoding (RPE) is important for transformer to capture sequence ordering of input tokens. General efficacy has been proven in natural language processing. However, in computer vision, its efficacy is not well studied and even remains controversial, e.g., whether relative position encoding can work equally well as absolute position? In order to clarify this, we first review existing relative position encoding methods and analyze their pros and cons when applied in vision transformers. We then propose new relative position encoding methods dedicated to 2D images, called image RPE (iRPE). Our methods consider directional relative distance modeling as well as the interactions between queries and relative position embeddings in self-attention mechanism. The proposed iRPE methods are simple and lightweight. They can be easily plugged into transformer blocks. Experiments demonstrate that solely due to the proposed encoding methods, DeiT and DETR obtain up to 1.5% (top-1 Acc) and 1.3% (mAP) stable improvements over their original versions on ImageNet and COCO respectively, without tuning any extra hyperparameters such as learning rate and weight decay. Our ablation and analysis also yield interesting findings, some of which run counter to previous understanding. Code and models are open-sourced at https://github.com/microsoft/Cream/tree/main/iRPE.

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

↑