URL
https://arxiv.org/pdf/2006.15102.pdf
TL;DR
-
ULSAM
是一个超轻量级的子空间注意力网络,适合用在轻量级的网络中,例如 MobileNet
、ShuffleNet
等
-
适合用在图像细粒度分类任务中,能减少大约 13%
的 Flops
和大约 25%
的 params
,在 ImageNet - 1K
和 其他三个细粒度分类数据集上 Top1 error
分别降低 0.27%
和 1%
-
与 SENet 有点类似,SENet
在 C
维度上添加注意力,ULSAM
在HW
维度上添加注意力
Algorithm
网络结构
公式表示
dwn=DW1∗1(Fn)
maxpooln=maxpool3∗3,1(dwn)
pwn=PW1(maxpooln)
An=softmax(pwn)
F^n=(An⊗Fn)⊕Fn
F^=concat([F^1,F^2,...,F^g])
源码表示
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| import torch import torch.nn as nn
torch.set_default_tensor_type(torch.cuda.FloatTensor)
class SubSpace(nn.Module): """ Subspace class.
...
Attributes ---------- nin : int number of input feature volume.
Methods ------- __init__(nin) initialize method. forward(x) forward pass.
"""
def __init__(self, nin): super(SubSpace, self).__init__() self.conv_dws = nn.Conv2d( nin, nin, kernel_size=1, stride=1, padding=0, groups=nin ) self.bn_dws = nn.BatchNorm2d(nin, momentum=0.9) self.relu_dws = nn.ReLU(inplace=False)
self.maxpool = nn.MaxPool2d(kernel_size=3, stride=1, padding=1)
self.conv_point = nn.Conv2d( nin, 1, kernel_size=1, stride=1, padding=0, groups=1 ) self.bn_point = nn.BatchNorm2d(1, momentum=0.9) self.relu_point = nn.ReLU(inplace=False)
self.softmax = nn.Softmax(dim=2)
def forward(self, x): out = self.conv_dws(x) out = self.bn_dws(out) out = self.relu_dws(out)
out = self.maxpool(x)
out = self.conv_point(out) out = self.bn_point(out) out = self.relu_point(out)
m, n, p, q = out.shape out = self.softmax(out.view(m, n, -1)) out = out.view(m, n, p, q)
out = out.expand(x.shape[0], x.shape[1], x.shape[2], x.shape[3])
out = torch.mul(out, x)
out = out + x
return out
|
Grad-CAM++ 热力图
ULSAM
加入到 MobileNet v1
和 v2
之后,模型的 focus
能力更好
Thoughts
网络表现
- 通过控制变量实验,验证子空间数量
g
和替换位置 pos
对模型表现的影响
对比实验