当前位置:网站首页>【Transformer】AdaViT: Adaptive Tokens for Efficient Vision Transformer
【Transformer】AdaViT: Adaptive Tokens for Efficient Vision Transformer
2022-07-29 05:21:00 【呆呆的猫】

一、背景
Transformer 在多个任务上都取得了亮眼的表现,在计算机视觉中,一般是对输入图像切分成多个 patch,然后计算 patch 之间的自注意力实现下游任务。
但由于自注意力机制的计算量是和输入图像大小呈平方关系的,所以,在边端设备上使用 Transformer 成为了一个问题。
作者认为不同的输入图像对网络来说,预测难度是不同的。如一个车和一个人在干净的背景中,那么就很好识别。如果是多个不同的动物在复杂的背景中,那么就较难识别。
基于此,作者实现了一个网络结构,根据输入的难度,来动态的调节 token 的个数来控制 transformer 的计算复杂度。
二、方法
vision transformer 的过程如下:
- ϵ ( . ) \epsilon(.) ϵ(.): encoding network,把输入图像编码成 positioned token
- C ( . ) C(.) C(.):class token 的后处理
- L L L:transformer block
- F ( . ) F(.) F(.):self-attention
为了动态杀掉 tokens,作者为每个 token 引入了一个 input-dependent halting score:
- H ( . ) H(.) H(.) 是 halting module
- k k k 是 token 索引, l l l 是层
- t k , e l t_{k,e}^l tk,el 是 t k l t_k^l tkl 的第 e e e 维
- σ \sigma σ 是 logistic sigmoid 函数
- β \beta β 和 γ \gamma γ 是非线性操作之前使用的平移和缩放系数
为了根据 layer 来追踪 halting probabilities,每个 token 会计算一个补充参数:
halting probabilities 如下:
ponder loss :每个 token 的 ponder loss 会平均。
分类任务的损失为:
halting score distribution 分布为:
所以使用 KL 散度来衡量真实和预测的分布偏差:
则总损失为:
三、效果
从图 3 可以看出, adaptive 选择 token 能够对高度突出和巨变的区域产生强响应,通常和类别相关。
1、Token 颜色深度分布:
在图中绘制 token 的颜色,如图 4 所示,其实是一个以图像中心为中心的 2D 类高斯分布,这也说明 ImageNet 的大多数样本都是在中间的。很多计算量都来自于中间区域,边缘参与计算的很少。
2、Halting score distribution:
如图 5 绘制了每个图像的每个 layer 的 halting score。
随机采样了 5k 验证集,在前几个 layer,halting score 随着 layer 的加深而增大,后面慢慢减小。
3、难样本和简单样本
图 6 展示了难例和简单例和其各自所需的计算量。
简单的例子可以被正确分类,AdaViT 处理的也比难例快。
4、类别敏感性
起初非常确信或非常不确信的样本被 adaptive 影响的很小,adaptive 推理能够提升形状明显的类别,如独立的家具或动物。
边栏推荐
- 有价值的博客、面经收集(持续更新)
- Nailing alarm script
- 与张小姐的春夏秋冬(5)
- 中海油集团,桌面云&网盘存储系统应用案例
- C # judge whether the user accesses by mobile phone or computer
- Huawei 2020 school recruitment written test programming questions read this article is enough (Part 2)
- 并发编程学习笔记 之 工具类Semaphore(信号量)
- Spring, summer, autumn and winter with Miss Zhang (2)
- 『全闪实测』数据库加速解决方案
- Reporting Service 2016 自定义身份验证
猜你喜欢
Research on the implementation principle of reentrantlock in concurrent programming learning notes
Synchronous development with open source projects & codereview & pull request & Fork how to pull the original warehouse
剑指核心-TaoCloud全闪SDS助力构建高性能云服务
Super simple integration HMS ml kit face detection to achieve cute stickers
与张小姐的春夏秋冬(3)
[pycharm] pycharm remote connection server
XDFS&空天院HPC集群典型案例
[DL] introduction and understanding of tensor
Flutter正在被悄悄放弃?浅析Flutter的未来
Breaking through the hardware bottleneck (I): the development of Intel Architecture and bottleneck mining
随机推荐
【Attention】Visual Attention Network
Tear the ORM framework by hand (generic + annotation + reflection)
Spring, summer, autumn and winter with Miss Zhang (2)
30 knowledge points that must be mastered in quantitative development [what is individual data]?
并发编程学习笔记 之 原子操作类AtomicInteger详解
isAccessible()方法:使用反射技巧让你的性能提升数倍
Rsync+inotyfy realize real-time synchronization of single data monitoring
Detailed explanation of atomic operation class atomicinteger in learning notes of concurrent programming
xtrabackup 的使用
[competition website] collect machine learning / deep learning competition website (continuously updated)
"Shandong University mobile Internet development technology teaching website construction" project training log V
与张小姐的春夏秋冬(1)
剑指核心-TaoCloud全闪SDS助力构建高性能云服务
day02作业之进程管理
【图像分类】如何使用 mmclassification 训练自己的分类模型
并发编程学习笔记 之 ReentrantLock实现原理的探究
Spring, summer, autumn and winter with Miss Zhang (3)
在uni-app项目中,如何实现微信小程序openid的获取
Xsan is highly available - xdfs and San are integrated with new vitality
识变!应变!求变!