Transformer在目标检测的几篇论文
blog记录最近看的两篇文章
- End-to-End Object Detection with Transformers
- Deformable Convolutional Networks
- DEFORMABLE DETR: Deformable Transformers for End-to-End Object Detection
如果你了解第二篇文章,那么第三篇文章就相对容易。
前置废话
最近看了几篇文章,姑且记录下来。最近Transformer在视觉上的paper不断增多,各种idea层出不穷,如swin transformer等。但一切都有迹可循。本blog记录关于目标检测两篇比较有代表性的paper。
前置知识
- 了解最原始的Transformer,
- 优化分配问题(匈牙利法)。
这里简述关于这两点知识。
Transformer
SelfAttetion
对于给定的Feature Map x ∈ R c × h × w x \in R^{c\times h \times w} x∈Rc×h×w, 不妨设置得到的 Q Q Q, K K K和 V V V都是相同维度,即 Q , K , V ∈ R c × h × w Q,K,V \in R^{c\times h \times w} Q,K,V∈Rc×h×w.将 Q , K , V Q,K,V Q,K,V分别 r e s h a p e reshape reshape到 R h w × c R^{hw\times c} Rhw×c,那么 S A = Q K T SA = QK^{T} SA=QKT,进一步做归一化,可以得到
S A = s o f t m a x ( Q K T d k ) SA = softmax(\frac{QK^{T}}{\sqrt{d_{k}}}) SA=softmax(dkQKT) 最终得到的输出
A t t e n t i o n ( Q , K , V ) = s o f t m a x ( Q K T d k ) V ( 1 ) Attention(Q,K,V) = softmax(\frac{QK^{T}}{\sqrt{d_{k}}})V \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (1) Attention(Q,K,V)=softmax(dkQKT)V (1)
可以看到 S A ∈ R h w × h w SA \in R^{hw\times hw} SA∈Rhw×hw, A t t e n t i o n ( Q , K , V ) ∈ R h w × c Attention(Q,K,V) \in R^{hw \times c} Attention(Q,K,V)∈Rhw×c,这就是想要的结果.
Multi-head机制只是把通道数拆成多份,如 m m m份,那么上述的shape就变成了 Q , K , V ∈ R h × w × c m Q,K,V\in R^{h\times w\times \frac{c}{m}} Q,K,V∈Rh×w×mc,最后将m个head进行 c o n c a t concat concat,得到 A t t e n t i o n ∈ R h w × c Attention\in R^{hw\times c} Attention∈Rhw×c . c r o s s − a t t e t i o n cross-attetion cross−attetion和这个类似,只不过 K K K和 V V V的来源不同而已,这里不再过多的赘述。
Position Embedding
由于在self-attention的过程中,只考虑了两两之间的attention,这其实还不够,因为现实生活中位置对于特征也非常重要,原论文采用了两种方式进行position位置的编码。
- hard coding(sin,cos函数编码)
- position learning
对于hard coding的方式主要参考
P E ( p o s , 2 i ) = s i n ( p o s 1000 0 2 i / d m o d e l ) ( 2 ) PE(pos,2i)=sin(\frac{pos}{10000^{2i/d_{model}}}) \ \ \ \ \ \ \ \ \ \ \ \ (2) PE(pos,2i)=sin(100002i/d

最低0.47元/天 解锁文章
1454






