Attention Augmented Convolutional Networks

Posted by JY on June 25, 2020

可与Stand-Alone Self-Attention in Vision Models 对比阅读

1、Introduction

  • 卷积操作具有显著的弱点,因为它仅在本地邻域上操作,缺少全局信息(only operates on a local neighborhood,thus missing global information)
  • Self-attention能够capture long range interactions
  • 本文考虑将Self-attention用于discriminative visual tasks,代替卷积的作用。

2、Methods

(1)引入two-dimensional relative self-attention mechanism,并通过实验证明了可行性

(2)模型细节

H: height

W: weight

Fin: number of input filters of an activation map

Nh: number of heads, Nh divides dv and dk

dv: depth of the values

dk: depth of the queries/keys

  • single-head attention

    • 3×3为例,经过6个filter得到3×3×6的input

    • 以单个head attention为例(蓝色部分),attention map中包括query map、key map和value map

      img

    • 如input中的位置6为self-attention target,对应的attention map中q6,k6,v6

      img

    • 通过QKT可以得到9×9的矩阵。

      img

    • 得到的a single head attention可以用以下公式表示:

    Oh=Softmax((XWq)(XWk)Tdhk)(XWv)

    where Wq,WkRFin×dhkWvRFin×dhv

img


  • multi-head 融合公式:
MHA(X)= Concat [O1,,ONh]WO

where WORdv×dv,最终得到(H,W,dv)的tensor


  • 增加了位置信息

    li,j=qTidhk(kj+rWjxix+rHjyiy)
    Oh=Softmax(QKT+SrelH+SrelWdhk)V

    where SrelH,SrelWRHW×HW,其中SrelH[i,j]=qTirHjyiyandSrelW[i,j]=qTirWjxix

    img

  • 但是直接使用self-attention会导致破坏了平移性,因此可以将self-attention与CNN结合使用

AAConv(X)= Concat [Conv(X),MHA(X)]