【语义分割专题】语义分割相关工作--Attemtion U-Net
·
Attention U-Net: Learning Where to Look for the Pancreas
Attention注意力机制,把注意力集中到对特定任务有用的显著特征,抑制输入图像中的不相关区域。在级联神经网络中,需要明确的外观组织/器官定位模块,而使用Attention就不需要了。
- 提出了grid-base gating,使attention coefficients更具体到局部区域;
- 在一个feed-forward CNN模型中使用soft-attention技术。提出的attention gate可以替代图像分类中使用的注意防范和图像分割框架中使用的外部器官定位模型。
- 提高模型对foreground像素的敏感度。

Attention-UNet模型是以UNet模型为基础的,可以从上图看出,Attention U-Net和U-Net的区别在于decoder处,从encoder提取的部分进行了Attention Gate再进行decoder操作。
在对encoder每个分辨率上的特征与decoder中对应特征进行拼接之前,使用了一个AGs,重新调整了encoder的输出特征。该模块生成了一个门控信号,用来控制不同空间位置处特征的重要性。
Attention GATE解析

该方法的注意力模型内如上图所示:
- 该模块通过 1 x 1的卷积分别于ReLu和Sigmoid结合,生成一个权重图
- 之后权重图与元素相乘
Attention代码
# 通道attention
class ChannelAttention(nn.Module):
def __init__(self, in_planes, out_planes):
super(ChannelAttention, self).__init__()
self.avg_pool = nn.AdaptiveAvgPool2d(1)
self.max_pool = nn.AdaptiveMaxPool2d(1)
self.fc1 = nn.Conv2d(in_planes, out_planes, 1, bias=False)
self.relu1 = nn.ReLU()
self.fc2 = nn.Conv2d( out_planes, in_planes, 1, bias=False)
self.sigmoid = nn.Sigmoid()
def forward(self, x):
avg_out = self.fc2(self.relu1(self.fc1(self.avg_pool(x))))
max_out = self.fc2(self.relu1(self.fc1(self.max_pool(x))))
out = avg_out + max_out
return self.sigmoid(out) * x
# 特征attention
class SpatialAttention(nn.Module):
def __init__(self, kernel_size=7):
super(SpatialAttention, self).__init__()
self.conv1 = nn.Conv2d(2, 1, kernel_size, padding=3, bias=False)
self.sigmoid = nn.Sigmoid()
def forward(self, x):
avg_out = torch.mean(x, dim=1, keepdim=True)
max_out, _ = torch.max(x, dim=1, keepdim=True)
out = torch.cat([avg_out, max_out], dim=1)
out = self.conv1(out)
return self.sigmoid(out) * x
# 混合attention
class CNNAttetion(nn.Module):
def __init__(self, in_planes, out_planes):
super(CNNAttetion, self).__init__()
self.channel_att = ChannelAttention(in_planes, out_planes)
self.spatial_att = SpatialAttention()
def forward(self, x):
out = self.channel_att(x)
out = self.spatial_att(out)
return out
更多推荐
所有评论(0)