最近阅读了CVPR2018的这篇论文 Harmonious Attention Network for Peson Re-Identification,论文还是比较容易理解的,下面就简单的解读一下,纯属个人观点,有不同意见的欢迎评论与我探讨~
总的来说,这篇论文解决的是ReID传统问题。
Existing works:
Our works:
问题一:现存的方法大多采用传统的CNN,这样带来的影响是:参数过多,计算的代价过大
所以作者提出了HA-CNN网络,该网络是一个lightweight (参数少) 同时又保证了deep(足够深)的特性。
所以作者提出的HA-CNN网络采用了联合学习hard and soft attention 的scheme,充分考虑hard and soft attention。
我个人觉得这三点归结起来就是提出了一个较为novel 的 architecture — HA-CNN.下面就详细讲述这个网络。
我个人总结了该网络的四个特点:
1. LightWeight (less parameters);
2. Joint learning of global and local features;
3. Joint learning of soft and hard attention;
4. Cross-attention interaction learning scheme between attention selection and feature representation.
该网络是一个多分支网络,包括获取global features 的 global branch 与 获取local features 的 local branches。每个branch的基本单位都是Inception-A/B(某种结构,还有其它结构如ResNet,VGG,AlexNet,你可以看成一个工具箱,能用就行了)。
Global branch 由3个Inception A(深色)与3个Inceprtion B(浅色)构成,还包含3个Harmonious Attention(红色),1个Global average pooing(绿色),1个Fully-Connected Layer(灰色), 最后获得一个512-dim global features。
Local branches 有多条(T branches),每条由3个Inception B(浅色) 和 1个 Global average pooling构成,最后每条分支的输出汇总到一起,通过一个 Fully-Connected Layer以获得512-dim local features.
补充: Global branch 只有一条,Local branches有T条,每条Local branch处理一个region。每一个bounding box可以有T个regions。
然后Global feature 与 Local feature 连接起来获得1024-dim feature,即是HA-CNN的输出。
图中的虚线与红色箭头,将在后面结合HA解释。这里先铺垫一下:Global features 是从 whole image 提取的, Local features 是从 来自于bounding box 的 regions,而这些regions是由HA提供的。即虚线是HA将Regions 发送到前面的结点,然后红线是将这些regions分配到各个Local branches。
讲清楚了这个网络的结构,便能解释它的第一个特点— LightWeight。
1. 采用分支网络,参数量的计算由乘法降为加法;
2. Global branch 与 Local branches 共享第一层Conv的参数;
3. Local branches 共享d1, d2, d3的参数。
该网络同时学习Global and Local Features,所以体现了它的第二个特点 — Joint learning of global and local features
补充一下图上参数的注解:
1. di d i 表示filter的数目,也就是channel的数目;
2. 第一层卷积 {32,3∗3,2} { 32 , 3 ∗ 3 , 2 } 表示32个filters,3*3 卷积核, 2 步长。
在深入了解HA结构之前,我们需要了解一下Attention机制。
什么是Attention?我觉得就是一个衡量信息价值的权重,以确定搜索范围。比如我现在要在一张图片上搜索某个人的脸部,那么这张图像上价值权重最高的部分便是包含脸部的regions,这些regions就是我们的attention,也就是我们的搜索范围。再举个例子,我现在有个包含10个单词的句子,我每个单词赋予一个权重,作为每个单词在这个句子中的价值衡量,权重越大,价值越高。自然,我的Attention就是一个10-dim vector,这也是它的本质。
Attention主要包含两类:Hard attention 与 Soft attention。简单的来说,Hard attention 关注的是 region级别的,Soft attention 关注的是 pixel 级别的。 举个例子:现在有一张聚会的合影,合影背景有各种吃剩的食物,瓶子等。但是你依然能很快的从中发现你认识的人(假如有你认识的人)。这就是一个Hard attention。即你能在非常混乱的背景下找到你认识的人,而没有受到太大干扰。这种确实很适合解决misaligned image。然后再举个阅读理解的例子:先阅读问题,提取出关键字(token),然后回文中查找。你寻找的这些token便是soft attention的体现。
Stack overflow上一段比较形象的解释 Attention
HA结构包含四个框:red、yellow、green、black。red 框 代表 soft attention learning, black 框代表 hard attention learning, red框内的green 框代表soft spatial attention, red 框内的yellow 框代表soft channel attention。
下面解释各个框,结合公式可能会好理解一点。
首先来看red 框。(1) green 框的输出 与 yellow 框的输出 进行 multiply op,得到的结果(2) 通过一层卷积层,再 (3) 经过一个Sigmoid获得red框的输出(we use the sigmoid operation to normalise the full soft attention into the range between 0.5 and 1)。公式(1) 描述的是步骤(1).
补充: 将 yellow 框与 green 框 的输出 作multiply op 以获得 soft attention,然后经过一层卷积,这层卷积有利于这两种soft attention 的 combination。最后经过sigmoid层,让输出每一分量保持在0.5~1范围。
接着看green 框。(1) HA的输入传入Reduce层(Global cross-channel averaging pooling layer), (2)得到的结果经过一层卷积层,(3)再经过一层Resize层(双线性插值), 最后(4)再经过一层卷积得到 soft spatial attention。公式(2) 描述的是步骤(1)的Reduce层,其实本质上就是一个channels的平均。
补充: Reduce Layer是对通道作avg操作,即将3d tensor转化为spatial tensor。紧接着的一层卷积用于提取spatial attention的特征。然后通过resize层,恢复h、w大小,该层采用的是双线性插值。最后一层Layer应该是为了增大其非线性表达。
然后看yellow 框。(1) HA的输入传入Global averaging pooling layer,对输入进行squeeze运算,(2)得到的结果通过两个卷积层得到结果。公式(3)描述的是步骤 (1) 的squeeze函数,公式(4) 描述的是步骤 (2)。
补充: 第一层squeeze操作,是将3d tensor 转化为 channel tensor。然后经过两层卷积提取特征。
red框的输出与HA的输入作multiply op后传入下一层。red框体现了HA-CNN的第三个特点: Joint learning of soft and hard attention
最后来看黑色框。作者 model the hard region attention as a transform matrix, 即公式(5), which allows for image cropping, translation and isotropic scaling operations by varying two scale factors (sh,sw) ( s h , s w ) and 2-D spatial position (tx,ty) ( t x , t y )
作者通过使用固定的 sh s h 与 sw s w 来限制模型复杂度,所以hard attention model 只需要考虑两个参数。目前输入是一个c-D vector
, 并且我们提取T个regions,所以蓝色部分的全连接层的参数便是2T*c 个参数。然后经过Tanh,最后获得2T输出 θ θ 。
补充: 作者将hard attention 给 model 成 一个变换矩阵,该矩阵主要有4个参数: sh s h 、 sw s w 、 tx t x 、 ty t y 。 其中, sh s h 、 sw s w 用于固定region的大小,以限制模型的复杂度,所以hard attention learning 学的便是这两个t变量。所以,全连接层的输出是2T,再经过Tanh,将position转化为百分比,以方便定位region的位置,即输出的 θ θ 是T个region的位置信息
θ θ 按照虚线传输回之前的结点,然后分成T个parts根据红线输入到各个Local branches做add op。
更正:现在解释一下HA-CNN的虚线与红线。虚线部分,引用原文如下:
The hard region attention is enforced on that of the corresponding network block to generate T different parts which are subsequently fed into the corresponding streams of the local branch.
这个“enforce” and then “generate T parts” 很迷,应该是没讲清楚。作者的意思应该是从HA模块传回的 θ θ 是regions的position info,然后从所到达的network block的当前feature map中获得region,将他们分别resize 成24x28x32、12x14x d1 d 1 、6x7x d2 d 2 ,传入local分支中与local feature做 add op。这一过程可以用公式(6) 描述
补充: 为什么做这个加法?作者的意思将global branch 学习到的东西分享给local branch,相当于分享了global branch 的学习能力,所以这样可以减少local branch的层数,继而减少参数量。
公式(6) 与 公式 (7) 体现了HA-CNN的第四个特点:Cross-attention interaction learning scheme between attention selection and feature representation
实现细节:
1. All person images are resized to 160×64;
2. we set the width of Inception units at the 1st/2nd/3rd levels as: d1 =128, d2 = 256 and d3 = 384;
3. we use T = 4 regions for hard attention;
4. In each stream, we fix the size of three levels of hard attention
as 24×28, 12×14 and 6×7;
5. For model optimisation, we use the ADAM algorithm at the initial learning rate 5×10−4 with the two moment terms β1 = 0:9 and β2 = 0:999;
6. We set the batch size to 32, epoch to 150, momentum to 0.9;
7. , we do not adopt any data argumentation methods (e.g. scaling, rotation, flipping, and colour distortion), neither model pre-training.
实验结果: