【可变形注意力(1)】Multi-scale Deformable Attention Transformers 多尺度变形注意力

文章目录

  • 前言
  • 论文 《Deformable DETR: Deformable Transformers for End-to-End Object Detection》的多尺度变形注意力的解读
    • DEFORMABLE TRANSFORMERS FOR END-TO-END OBJECT DETECTION
  • **2.** Deformable Attention Module
      • Deformable Attention Module
  • 3. Multi-Scale Deformable Attention Module
      • Multi-scale Deformable Attention Module
      • Deformable Transformer Encoder
      • Deformable Transformer Decoder.
    • A.2 CONSTRUCTING MULT-SCALE FEATURE MAPS FOR DEFORMABLE DETR
  • 参考

前言

1、大多数现代物体检测框架受益于多尺度特征图 (Liu等人,2020)。

2、Deformable DETR: Deformable Transformers for End-to-End Object Detection 提出的可变形注意力模块可以自然地扩展为多尺度特征图。

论文 《Deformable DETR: Deformable Transformers for End-to-End Object Detection》的多尺度变形注意力的解读

DEFORMABLE TRANSFORMERS FOR END-TO-END OBJECT DETECTION

2. Deformable Attention Module

  • Given an input feature map x with size of CHW, let q index a query element with content feature zq and a 2-d reference point pq, the deformable attention feature is calculated by:

img

  • where m indexes the attention head (M is number of heads), k indexes the sampled keys, and K is the total sampled key number (KHW).

img

Deformable Attention Module

  • Δpmqk and Amqk denote the sampling offset and attention weight of the kth sampling point in the mth attention head, respectively.
  • As pqpmqk is fractional**, bilinear interpolation is applied.
  • Both Δpmqk and Amqk are obtained via linear projection over the query feature zq.
  • The query feature zq is fed to a linear projection operator of 3MK channels, where the first 2MK channels encode the sampling offsets Δpmqk, and the remaining MK channels are fed to a softmax operator to obtain the attention weights Amqk.

To be brief, two sets of channels are used to encode offsets in x and y directions. The remaining one set of channels is to encode attention weight.

These two sets of offsets are learnt, which has the similar concept in DCN.

  • Let Nq be the number of query elements, when MK is relatively small, the complexity of the deformable attention module is of:

img

  • When it is applied in DETR encoder, where Nq=HW, the complexity becomes O(HWC²), which is of linear complexity with the spatial size.
  • When it is applied as the cross-attention modules in DETR decoder, where Nq=N (N is the number of object queries), the complexity becomes O(NKC²), which is irrelevant to the spatial size HW.

Deformable Attention Module

Deformable Attention Module,在图像特征上,应用Transformer注意力的核心问题是:it would look over all possible spatial locations。
为了解决这个问题,我们提出了一个可变形的注意模块(deformable attention module)。
受可变形卷积的启发 (Dai等,2017; Zhu等,2019b),可变形注意模块只关注参考点周围的一小部分关键采样点,而与特征图的空间大小无关,如图2所示,通过为每个查询仅分配少量固定数量的键,可以减轻收敛和特征空间分辨率的问题。

在这里插入图片描述

Given an input feature map x ∈ R C × H × W x ∈ R^{C×H×W} xRC×H×W, let q q q index a query element with content feature z q z_q zq and a 2-d reference point p q p_q pq,让 q q q索引一个具有内容特征 z q z_q zq和二维参考点 p q p_q pq的查询元素
the deformable attention feature is calculated by
在这里插入图片描述
where m m m indexes the attention head,
k k k indexes the sampled keys, and K K K is the total sampled key number (K << HW).
∆ p m q k ∆p_{mqk} pmqk and A m q k A_{mqk} Amqk denote the sampling offset and attention weight of the k t h k_{th} kth sampling point in the m t h m_{th} mth attention head, respectively.
其中,m为注意头索引,k为采样键索引,K为总采样键数 (K << HW)。∆ pmqk和Amqk分别表示第m个注意头中第k个采样点的采样偏移和注意权重。

The scalar attention weight A m q k A_{mqk} Amqk lies in the range [0, 1], normalized by
在这里插入图片描述

∆ p m q k ∈ R 2 ∆p_{mqk} ∈ R^2 pmqkR2是具有无约束范围的二维实数

p q + ∆ p m q k p_q+∆p_{mqk} pq+pmqk为分数时,应用双线性插值,如Dai等人 (2017) 在计算 x ( p q + ∆ p m q k ) x(p_q + ∆p_{mqk}) x(pq+pmqk)

∆ p m q k ∆p_{mqk} pmqk A m q k A_{mqk} Amqk都是通过对query feature z q z_q zq 的线性投影获得的

In implementation, the query feature z q z_q zq is fed to a linear projection operator of 3MK channels, where the first 2MK channels encode the sampling offsets ∆ p m q k ∆p_{mqk} pmqk, and the remaining MK channels are fed to a softmax operator to obtain the attention weights A m q k A_{mqk} Amqk.

可变形注意模块设计用于将卷积特征图作为key elements进行处理。
N q N_q Nq为query elements的数量,当mk相对较小时,可变形注意模块的复杂度为 O ( 2 N q C 2 m i n ( H W C 2 , N q K C 2 ) ) O(2N_qC^2 min(HWC^2,N_qKC^2)) O(2NqC2min(HWC2NqKC2)) (详见附录A.1)。
当它应用于DETR编码器时,其中 q = H W q = HW q=HW,复杂度变为 O ( H W C 2 ) O(HWC^2) O(HWC2),它与空间大小呈线性复杂度。
When it is applied as the cross-attention modules in DETR decoder, where Nq = N (N is the number of object queries), the complexity becomes O ( N K C 2 ) O(NKC^2) O(NKC2), which is irrelevant to the spatial size H W HW HW.

3. Multi-Scale Deformable Attention Module

Multi-scale deformable attention modules to replace the Transformer attention modules processing feature maps.

  • Let {xl}, where l from 1 to L, be the input multi-scale feature maps, where xl has the size of C×Hl×Wl. Let ^pq ∈ [0, 1]² be the normalized coordinates of the reference point for each query element q, then the multi-scale deformable attention module is applied as:

img

  • The normalized coordinates (0, 0) and (1, 1) indicate the top-left and the bottom-right image corners, respectively. Φl(^pq) re-scales the normalized coordinates ^pq to the input feature map of the l-th level.
  • The multi-scale deformable attention is very similar to the previous single-scale version, except that it samples LK points from multi-scale feature maps instead of K points from single-scale feature maps.
  • The proposed attention module will degenerate to deformable convolution, as in DCN, when L=1, K=1, and Wm is fixed as an identity matrix.

The proposed (multi-scale) deformable attention module can also be perceived as an efficient variant of Transformer attention, where a pre-filtering mechanism is introduced by the deformable sampling locations.

Multi-scale Deformable Attention Module

Multi-scale Deformable Attention Module.大多数现代物体检测框架受益于多尺度特征图 (Liu等人,2020)。我们提出的可变形注意力模块可以自然地扩展为多尺度特征图。

Let x l l = 1 L {x^l}^L_{l=1} xll=1L be the input multi-scale feature maps, where x l ∈ R C × H l × W l x^l ∈ R^{C×H_l×W_l} xlRC×Hl×Wl.
Let p q ∈ [ 0 , 1 ] 2 p_q∈ [0, 1]^2 pq[0,1]2 be the normalized coordinates of the reference point for each query element q q q,
then the multi-scale deformable attention module is applied as

在这里插入图片描述
where m m m indexes the attention head,
l l l indexes the input feature level,
k k k indexes the sampling point.
∆ p m l q k ∆p_{mlqk} pmlqk and A m l q k A_{mlqk} Amlqk denote the sampling offset and attention weight of the k t h k^{th} kth sampling point in the lth feature level and the m t h m^{th} mth attention head, respectively.
The scalar attention weight A m l q k A_{mlqk} Amlqk is normalized by在这里插入图片描述

Here, we use normalized coordinates p q ∈ [ 0 , 1 ] 2 p_q ∈ [0, 1]^2 pq[0,1]2 for the clarity of scale formulation, in which the normalized coordinates (0, 0) and (1, 1) indicate the top-left and the bottom-right image corners, respectively.

Function φ l ( p q ) φ_l(p_q) φl(pq) in Equation 3 rescales the normalized coordinates p q p_q pq to the input feature map of the l t h l^{th} lth level.
方程3中的函数 φ将归一化坐标 p q p_q pq重新缩放到第 l l l级的输入特征图

多尺度可变形注意力与以前的单尺度版本非常相似,不同之处在于它从多尺度特征图中采样LK点,而不是从单尺度特征图中采样K点

The proposed attention module will degenerate to deformable convolution when L=1 K=1 and W ’ m ∈ R C v ∗ C W’_m ∈ R^{C_v*C} WmRCvC is
fixed as an identity matrix单位矩阵

Deformable convolution is designed for single-scale inputs, focusing only on one sampling point for each attention head. How-
ever, our multi-scale deformable attention looks over multiple sampling points from multi-scale in-puts. The proposed (multi-scale) deformable attention module can also be perceived as an efficient variant of Transformer attention, where a pre-filtering mechanism is introduced by the deformable sampling locations
当采样点遍历所有可能的位置时,the (multi-scale) deformable attention module is equivalent to Transformer attention

Deformable Transformer Encoder

我们用提出的多尺度可变形注意模块代替了DETR中处理特征图的Transformer 注意模块。编码器的输入和输出都是具有相同分辨率的多尺度特征图。

在编码器中,我们从ResNet (He等人,2016) 中的阶段C3到C5的输出特征图中提取多尺度特征图(通过1 × 1卷积变换),其中 C l C_l Cl的分辨率比输入图像低 2 l 2_l 2l。最低分辨率特征图 x L x_L xL是通过最终C5阶段的3 × 3步幅2卷积获得的,表示为 C 6 C_6 C6。所有多尺度特征图都是C = 256通道。注意,FPN (Lin等,2017a) 中的自顶向下结构没有使用,因为我们提出的多尺度可变形注意力本身可以在多尺度特征图之间交换信息。附录a2还说明了多尺度特征图的构建。5.2部分的实验表明,添加FPN不会改善性能。
In application of the multi-scale deformable attention module in encoder, the output are of multi-scale feature maps with the same resolutions as the input. Both the key and query elements are of pixels from the multi-scale feature maps.
对于每个查询像素,参考点是其自身。为了确定每个查询像素位于哪个特征级别,除了位置嵌入之外,我们还在特征表示中添加了比例级别嵌入 (表示为el)。 与固定编码的位置嵌入不同,比例级嵌入 {el} 是随机初始化的,并与网络联合训练。

Deformable Transformer Decoder.

There are cross-attention and self-attention modules in the decoder. The query elements for both types of attention modules are of object queries. In the cross-attention modules, object queries extract features from the feature maps, where the key elements are of the output feature maps from the encoder. In the self-attention modules, object queries interact with each other, where the key elements are of the object queries. Since our proposed deformable attention module is designed for processing convolutional feature maps as key elements, we only replace each cross-attention module to be the multi-scale deformable attention module, while leaving the self-attention modules unchanged.
For each object query, the 2-d normalized coordinate of the reference point p q p_q pq is predicted from its object query embedding via a learnable linear projection followed by a sigmoid function.参考点 “p” 是通过可学习的线性投影和sigmoid函数从其object query embedding中预测的。

因为多尺度可变形注意模块提取参考点周围的图像特征,所以我们让检测头预测边界框作为相对偏移w.r.t.参照点,进一步降低优化难度。参考点用作框中心的初始猜测。检测头预测相对偏移w.r.t.参考点。查看附录A.3的详细信息。这样,学习的解码器注意力将与预测的边界框具有很强的相关性,这也加速了训练收敛。

通过用DETR中的可变形注意模块替换Transformer注意模块,我们建立了一个高效且快速的会聚检测系统,称为可变形DETR (参见图1)。
在这里插入图片描述

A.2 CONSTRUCTING MULT-SCALE FEATURE MAPS FOR DEFORMABLE DETR

正如4.1节所讨论并在图4中所示,编码器{xl}L−1 L =1 (L = 4)的输入多尺度特征映射是从ResNet中C3到C5阶段的输出特征映射中提取的(He et al., 2016)(通过1×1卷积进行转换)。最低分辨率的feature map xL是通过在最后的C5 stage上的3×3 stride 2卷积获得的。注意,我们没有使用FPN (Lin et al., 2017a),因为我们提出的多尺度变形注意本身可以在多尺度特征图之间交换信息。

在这里插入图片描述

参考

https://sh-tsang.medium.com/review-deformable-transformers-for-end-to-end-object-detection-e29786ef2b4c

(正文完)

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/107328.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

【开源】基于SpringBoot的森林火灾预警系统的设计和实现

目录 一、摘要1.1 项目介绍1.2 项目录屏 二、功能模块2.1 数据中心模块2.2 系统基础模块2.3 烟雾传感器模块2.4 温度传感器模块2.5 历史记录模块2.6 园区数据模块 三、系统设计3.1 用例设计3.1.1 森林园区基础系统用例设计3.1.2 森林预警数据用例设计 3.2 数据库设计3.2.1 烟雾…

C# | Chaikin算法 —— 计算折线对应的平滑曲线坐标点

Chaikin算法——计算折线对应的平滑曲线坐标点 本文将介绍一种计算折线对应的平滑曲线坐标点的算法。该算法使用Chaikin曲线平滑处理的方法&#xff0c;通过控制张力因子和迭代次数来调整曲线的平滑程度和精度。通过对原始点集合进行切割和插值操作&#xff0c;得到平滑的曲线坐…

【原创】解决Kotlin无法使用@Slf4j注解的问题

前言 主要还是辟谣之前的网上的用法&#xff0c;当然也会给出最终的使用方法。这可是Kotlin&#xff0c;关Slf4j何事&#xff01;&#xff1f; 辟谣内容&#xff1a;创建注解来解决这个问题 例如&#xff1a; Target(AnnotationTarget.CLASS) Retention(AnnotationRetentio…

开源Linux社区Armbian开发指南

1. 什么是armbian Armbian是一个基于Debian或Ubuntu的开源操作系统&#xff0c;专门针对嵌入式ARM平台进行优化和定制。Armbian可以运行在多种不同的嵌入式设备上&#xff0c;例如树莓派、ArmSoM、香蕉派等等。Armbian针对不同的嵌入式平台&#xff0c;提供了相应的硬件支持&a…

利用HTTP2,新型DDoS攻击峰值破纪录

亚马逊、Cloudflare 和谷歌周二联合发布消息称&#xff0c;一种依赖于 HTTP/2 快速重置技术的攻击行为对它们造成了破纪录的分布式拒绝服务 (DDoS) 攻击。 根据披露的信息&#xff0c;该攻击自8月下旬以来便一直存在&#xff0c;所利用的漏洞被跟踪为CVE-2023-44487&#xff0c…

基于SpringBoot+Vue的服装销售系统

基于SpringBootVue的服装销售平台的设计与实现~ 开发语言&#xff1a;Java数据库&#xff1a;MySQL技术&#xff1a;SpringBootMyBatisVue工具&#xff1a;IDEA/Ecilpse、Navicat、Maven 系统展示 主页 我的订单 登录界面 管理员界面 摘要 基于SpringBoot和Vue的服装销售系统…

管理类联考——数学——汇总篇——知识点突破——数据分析——记忆

文章目录 考点记忆/考点汇总——按大纲 整体目录大纲法记忆宫殿法绘图记忆法 局部数字编码法对号不对号 归类记忆法重点记忆法歌决记忆法口诀&#xff1a;加法分类&#xff0c;类类相加&#xff1b;乘法分步&#xff0c;步步相乘。 谐音记忆法涂色 理解记忆法比较记忆法转图像记…

Qwt开发环境搭建(保姆级教程)

1.简介 QWT&#xff0c;即Qt Widgets for Technical Applications&#xff0c;其目标是以基于2D方式的窗体部件来显示数据&#xff0c; 数据源以数值&#xff0c;数组或一组浮点数等方式提供&#xff0c; 输出方式可以是Curves&#xff08;曲线&#xff09;&#xff0c;Slider…

计算机毕设 opencv 图像识别 指纹识别 - python

文章目录 0 前言1 课题背景2 效果展示3 具体实现3.1 图像对比过滤3.2 图像二值化3.3 图像侵蚀细化3.4 图像增强3.5 特征点检测 4 OpenCV5 最后 0 前言 &#x1f525; 这两年开始毕业设计和毕业答辩的要求和难度不断提升&#xff0c;传统的毕设题目缺少创新和亮点&#xff0c;往…

liunx Centos-7.5上 rabbitmq安装

在安装rabbitmq中需要注意&#xff1a; 1、rabbitmq依赖于erlang&#xff0c;需要先安装erlang 2、erlang和rabbitmq版本有对应关系 可参考网页&#xff1a;https://www.rabbitmq.com/which-erlang.html 第一步&#xff0c;安装编译工具及库文件,如果服务器上已经有了&…

如何在vscode中添加less插件

Less &#xff08;Leaner Style Sheets 的缩写&#xff09; 是一门向后兼容的 CSS 扩展语言。它对CSS 语言增加了少许方便的扩展&#xff0c;通过less可以编写更少的代码实现更强大的样式。但less不是css&#xff0c;浏览器不能直接识别&#xff0c;即浏览器无法执行less代码&a…

【mediasoup-sfu-cpp】3: SfuDemo:加入会议首次成功运行

【mediasoup-sfu-cpp】2:SfuCppDemo 和MediaSoup实例 可以发现闫华大神的demo是开箱即用的。虽然客户端的demo 未开源,但是是可以测试的。正确加入后应该就是发布了视频的 加入会议后默认开启camera,ID 是自己填写的,代表UID demo自己随机生成就可以。 配置本地服务地址 ws…

场效应管器件

在面试硬件方面的工作时&#xff0c;我们通常会被提问模电方面的知识。 场效应管简称FET,有三级&#xff1a;源极(S)、漏极(D)、栅极&#xff08;G&#xff09;&#xff1b;可以实现电压控制电流源&#xff1b;“源极和漏极之间的漏极电流Id&#xff0c;由栅极的负电压进行控制…

轻量级仿 Spring Boot=嵌入式 Tomcat+Spring MVC

啥&#xff1f;Spring Boot 不用&#xff1f;——对。就只是使用 Spring MVC Embedded Tomcat&#xff0c;而不用 Boot。为啥&#xff1f;——因为 Boot 太重了&#xff1a;&#xff09; 那是反智吗&#xff1f;Spring Boot 好好的就只是因为太重就不用&#xff1f;——稍安勿…

刀片式服务器介绍

大家都知道服务器分为机架式服务器、刀片式服务器、塔式服务器三类&#xff0c;今天小编就分别讲一讲这三种服务器&#xff0c;第二篇先来讲一讲刀片式服务器的介绍。 刀片式服务器定义&#xff1a;是一种高密度的服务器架构&#xff0c;通过多个独立服务器单元组成&#xff0c…

windows qemu安装飞腾Aarch64 操作系统 亲测

在win7&#xff08;X86架构CPU&#xff09;下使用QEMU虚拟机运行银河麒麟操作系统&#xff08;ARM架构CPU&#xff09; 1、下载并安装QEMU虚拟机软件 https://qemu.weilnetz.de/w64/2020/ 2、准备好ARM银河麒麟操作系统.iso文件 这里是 Kylin-Desktop-V10-Release-2107-ar…

力扣:141. 环形链表(Python3)

题目&#xff1a; 给你一个链表的头节点 head &#xff0c;判断链表中是否有环。 如果链表中有某个节点&#xff0c;可以通过连续跟踪 next 指针再次到达&#xff0c;则链表中存在环。 为了表示给定链表中的环&#xff0c;评测系统内部使用整数 pos 来表示链表尾连接到链表中的…

CentOS 编译安装 nginx

CentOS 编译安装 nginx 修改 yum 源地址为 阿里云 curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repoyum makecache升级内核和软件 yum -y update安装常用软件和依赖 yum -y install gcc gcc-c make cmake zlib zlib-devel openss…

CRM客户管理系统源码 带移动端APP+H5+小程序

CRM客户管理系统源码 带移动端APPH5小程序 开发环境: thinkphp mysql 功能介绍&#xff1a; 1、 办公管理&#xff1a;审批管理、工作报告、日程管理、办公审批、公告管理 2、 客户管理&#xff1a;我的客户、客户列表、成交客户、行业类别、预查、地区列表、客户状态、客…

ubuntu 安装 gnome 安装 xrdp

先安装xrdp 更新 apt-get sudo apt-get update && apt-get upgrade安装图形包 apt-get install xubuntu-desktop安装 xrdp apt-get install xrdp安装 xfce4 apt-get install xfce4配置 xfce4 Add xfce to the xfce desktop window manager autorun by fixing the …