FasterViT: Fast Vision Transformers with Hierarchical Attention

本文介绍了一种名为FasterViT的方法,它通过引入层次注意力和CarrierToken(CT)来提升视觉Transformer的速度。CT利用低成本实现大范围注意力,通过卷积、池化和多层注意力机制处理局部窗口和全局信息。
摘要由CSDN通过智能技术生成

FasterViT: Fast Vision Transformers with Hierarchical Attention

本文引入了层次注意力(Hierarchical Attention)的Carrier Token(CT),该令牌以低成本获得比局部窗口更大的注意力足迹。
层次注意力具体步骤为:

  1. 划分输入特征图为 n × n n\times n n×n局部窗口,得到特征图 x ^ 1 \hat{x}_{1} x^1
  2. 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)=AvgPoolH2n2L(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+γ1MHSA(LN(x^ct)),x^ct=x^ct+γ2MLPd4dd(LN(x^ct)),
  3. 为建模短距离和长距离空间信息,计算局部和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+γ1MHSA(LN(x^w)),=x^w+γ2MLPd4dd(LN(x^w)).
  4. 令牌被进一步拆分并用于后续的分层注意力层
  • 25
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qgh1223

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值