FasterViT: Fast Vision Transformers with Hierarchical Attention
本文引入了层次注意力(Hierarchical Attention)的Carrier Token(CT),该令牌以低成本获得比局部窗口更大的注意力足迹。
层次注意力具体步骤为:
- 划分输入特征图为 n × n n\times n n×n局部窗口,得到特征图 x ^ 1 \hat{x}_{1} x^1。
- CT计算。首先通过卷积和池化初始化CT。
x
^
c
=
Conv
3
×
3
(
x
)
x
^
c
t
=
AvgPool
H
2
→
n
2
L
(
x
^
c
)
,
\begin{aligned} \hat{\mathbf{x}}_{\mathbf{c}} & =\operatorname{Conv}_{3 \times 3}(\mathbf{x}) \\ \hat{\mathbf{x}}_{\mathbf{c t}} & =\operatorname{AvgPool}_{H^{2} \rightarrow n^{2} L}\left(\hat{\mathbf{x}}_{\mathbf{c}}\right), \end{aligned}
x^cx^ct=Conv3×3(x)=AvgPoolH2→n2L(x^c),
Conv 3 × 3 \operatorname{Conv}_{3 \times 3} Conv3×3是高效位置编码。这些池化令牌表示对应局部窗口的摘要。CT初始化对于每个分辨率阶段只经历一次。
CT经过如下注意力过程: x ^ c t = x ^ c t + γ 1 ⋅ MHSA ( LN ( x ^ c t ) ) , x ^ c t = x ^ c t + γ 2 ⋅ MLP d → 4 d → d ( LN ( x ^ c t ) ) , \begin{array}{l} \hat{\mathbf{x}}_{\mathbf{c t}}=\hat{\mathbf{x}}_{\mathbf{c t}}+\gamma_{1} \cdot \operatorname{MHSA}\left(\operatorname{LN}\left(\hat{\mathbf{x}}_{\mathbf{c t}}\right)\right), \\ \hat{\mathbf{x}}_{\mathbf{c t}}=\hat{\mathbf{x}}_{\mathbf{c t}}+\gamma_{2} \cdot \operatorname{MLP}_{d \rightarrow 4 d \rightarrow d}\left(\operatorname{LN}\left(\hat{\mathbf{x}}_{\mathbf{c t}}\right)\right), \end{array} x^ct=x^ct+γ1⋅MHSA(LN(x^ct)),x^ct=x^ct+γ2⋅MLPd→4d→d(LN(x^ct)), - 为建模短距离和长距离空间信息,计算局部和Carrier令牌间交互( x ^ 1 , x ^ c t , 1 \hat{x}_{1},\hat{x}_{ct,1} x^1,x^ct,1)。首先合并局部特征和CT。每个局部窗口只能获得对应CT。 x ^ w = Concat ( [ x ^ 1 , x ^ c t , 1 ] ) \hat{x}_{w}=\text{Concat}([\hat{x}_{1},\hat{x}_{ct,1}]) x^w=Concat([x^1,x^ct,1])。这些令牌经过另一个注意力流程: x ^ w = x ^ w + γ 1 ⋅ M H S A ( L N ( x ^ w ) ) , x ^ w = x ^ w + γ 2 ⋅ M L P d → 4 d → d ( L N ( x ^ w ) ) . \begin{aligned}\mathbf{\hat{x}}_{\mathbf{w}}&=\mathbf{\hat{x}}_{\mathbf{w}}+\gamma_{1}\cdot\mathbf{MHSA}(\mathrm{LN}(\mathbf{\hat{x}}_{\mathbf{w}})),\\\mathbf{\hat{x}}_{\mathbf{w}}&=\mathbf{\hat{x}}_{\mathbf{w}}+\gamma_{2}\cdot\mathrm{MLP}_{d\to4d\to d}(\mathrm{LN}(\mathbf{\hat{x}}_{\mathbf{w}})).\end{aligned} x^wx^w=x^w+γ1⋅MHSA(LN(x^w)),=x^w+γ2⋅MLPd→4d→d(LN(x^w)).。
- 令牌被进一步拆分并用于后续的分层注意力层