Paper
之前没有见过这玩意,首先介绍一下通道注意力吧:
不同的通道捕捉的是不同的特征(也就是每个特征图都是有偏重特征的),通道注意力就是用来衡量这些通道重要性的。下面是SENet的一个块:
可能这幅图更清楚:
其对应的公式:
SEblock 代码:
class SELayer(nn.Module):
def __init__(self, channel, reduction=16):
super(SELayer, self).__init__()
self.avg_pool = nn.AdaptiveAvgPool2d(1)
self.fc = nn.Sequential(
nn.Linear(channel, channel // reduction, bias=False),
nn.ReLU(inplace=True),
nn.Linear(channel // reduction, channel, bias=False),
nn.Sigmoid()
)
def forward(self, x):
b, c, _, _ = x.size()
y = self.avg_pool(x).view(b, c) #对应Squeeze操作
y = self.fc(y).view(b, c, 1, 1) #对应Excitation操作
return x * y.expand_as(x)
参考博客: