Attention UNet论文解析 - 知乎Attention UNet论文地址: https://arxiv.org/pdf/1804.03999.pdf 代码地址: https://github.com/ozan-oktay/Attention-Gated-NetworksAttention UNet在UNet中引入注意力机制,在对编码器每个分辨率上的特征与解…https://zhuanlan.zhihu.com/p/480384295

图像分割UNet系列------Attention Unet详解_gz7seven的博客-CSDN博客_attention unet图像分割unet系列------Attention Unet详解1、Attention Unet主要目标2、Attention Unet网络结构    Attention Unet发表于2018年中期(比Res-UNet要早一些),它也是UNet非常重要的改进版本之一。当然,Attention Unet同样也是应用在医学图像分割领域,不过文章主要是以胰脏图像分割进行实验与论证的。1、Attention Unet主要目标    作者在摘要与简介中很清楚的表明了要解决的问题以及要达到的目标。具体如下所示:https://gz7seven.blog.csdn.net/article/details/119612308?spm=1001.2101.3001.6650.6&utm_medium=distribute.pc_relevant.none-task-blog-2~default~BlogCommendFromBaidu~Rate-6-119612308-blog-118300513.pc_relevant_multi_platform_whitelistv3&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2~default~BlogCommendFromBaidu~Rate-6-119612308-blog-118300513.pc_relevant_multi_platform_whitelistv3&utm_relevant_index=10

一、Attention Unet主要目标

  1. 抑制输入图像中的不相关区域,同时突出特定局部区域的显著特征
  2. 用soft-attention 代替hard-attention的思路(注意:sorf-attention可微,可以微分的attention就可以通过神经网络算出梯度并且前向传播和后向反馈来学习得到attention的权重);
  3. 集成到标准UNet网络结构中时要简单方便、计算开销小,最重要的是提高模型的灵敏度和预测的精度。

二、Attention Unet网络结构

Attention UNet在UNet中引入注意力机制,在对编码器每个分辨率上的特征与解码器中对应特征进行拼接之前,使用了一个注意力模块,重新调整了编码器的输出特征。该模块生成一个门控信号,用来控制不同空间位置处特征的重要性,如下图中红色圆圈所示

三、Attention Gate

Attention Gate:AG通常用于自然图像分析、知识图和语言处理(NLP),用于图像字幕、机器翻译和分类任务。最初的工作是通过解释输出类分数相对于输入图像的梯度来探索注意图。另一方面,可训练的注意力是由设计强制执行的,并被分为hard-attention and soft-attention。

结合图1与图2可以很清楚的了解到Attention UNet网络结构的主要特点。从图1可以很清楚的看到解码部分feature map与其上一层的编码部分feature map作为AG的输入,经过AG后将结果cat上采样的解码部分feature map。

四、Attention Gate的本质

AG是如何做到提高局部(感兴趣区域ROI)特征抑制某些非感兴趣区域的呢?

五、代码实现

# python3
# @File: AttentionUNet3D.py
# --coding:utf-8--
# @Author:axjing
# 说明: For 3D Data Train
import torch
import torch.nn as nndef maxpool2x2(x):mp = nn.MaxPool3d(kernel_size=2, stride=2)x = mp(x)return x
class EncoderBlock(nn.Module):def __init__(self, in_channels, out_channels):super(EncoderBlock, self).__init__()self.encoder_block = nn.Sequential(nn.Conv3d(in_channels, out_channels, 3, padding=1, bias=False),nn.BatchNorm3d(num_features=out_channels),nn.ReLU(inplace=True),nn.Conv3d(out_channels, out_channels, 3, padding=1, bias=False),nn.BatchNorm3d(num_features=out_channels),nn.ReLU(inplace=True),# 原论文中是每层有两个卷积核进行下采样 https://arxiv.org/abs/1505.04597nn.Conv3d(out_channels, out_channels, 3, padding=1, bias=False),nn.BatchNorm3d(num_features=out_channels),nn.ReLU(inplace=True),)def forward(self, x):x = self.encoder_block(x)return xclass CenterBlock(nn.Module):def __init__(self, in_channels, out_channels):super(CenterBlock, self).__init__()mid_channels = int(in_channels * 2)self.center_block = nn.Sequential(nn.Conv3d(in_channels, mid_channels, 3, padding=1, bias=False),nn.BatchNorm3d(num_features=mid_channels),nn.ReLU(inplace=True),nn.Conv3d(int(in_channels * 2), mid_channels, 3, padding=1, bias=False),nn.BatchNorm3d(num_features=mid_channels),nn.ReLU(inplace=True),nn.ConvTranspose3d(mid_channels, out_channels, 4, stride=2, padding=1),nn.BatchNorm3d(num_features=out_channels),nn.ReLU(inplace=True),)def forward(self, x):x = self.center_block(x)return xclass DecoderBlock(nn.Module):def __init__(self, in_channels, out_channels):super(DecoderBlock, self).__init__()mid_channels = int(in_channels / 2)self.decoder_block = nn.Sequential(nn.Conv3d(in_channels, mid_channels, 3, padding=1, bias=False),nn.BatchNorm3d(num_features=mid_channels),nn.ReLU(inplace=True),nn.Conv3d(mid_channels, mid_channels, 3, padding=1, bias=False),nn.BatchNorm3d(num_features=mid_channels),nn.ReLU(inplace=True),nn.ConvTranspose3d(mid_channels, out_channels, 4, stride=2, padding=1),nn.BatchNorm3d(num_features=out_channels),nn.ReLU(inplace=True),)def forward(self, x):x = self.decoder_block(x)return xclass FinalBlock(nn.Module):def __init__(self, in_channels, out_channels):super(FinalBlock, self).__init__()mid_channels = int(in_channels / 2)self.final_block = nn.Sequential(nn.Conv3d(in_channels, mid_channels, 3, padding=1, bias=False),nn.BatchNorm3d(num_features=mid_channels),nn.ReLU(inplace=True),nn.Conv3d(mid_channels, mid_channels, 3, padding=1, bias=False),nn.BatchNorm3d(num_features=mid_channels),nn.ReLU(inplace=True),nn.Conv3d(mid_channels, out_channels, 1, bias=False),)def forward(self, x):x = self.final_block(x)return xclass AttentionGates3D(nn.Module):def __init__(self, F_g, F_l, F_int):super(AttentionGates3D, self).__init__()self.W_g = nn.Sequential(nn.Conv3d(F_l, F_int, kernel_size=1, stride=1, padding=0, bias=True),nn.BatchNorm3d(F_int))self.W_x = nn.Sequential(nn.Conv3d(F_g, F_int, kernel_size=1, stride=1, padding=0, bias=True),nn.BatchNorm3d(F_int))self.psi = nn.Sequential(nn.Conv3d(F_int, 1, kernel_size=1, stride=1, padding=0, bias=True),nn.BatchNorm3d(1),nn.Sigmoid())self.relu = nn.ReLU(inplace=True)def forward(self, g, x):g1 = self.W_g(g)x1 = self.W_x(x)psi = self.relu(g1 + x1)psi = self.psi(psi)out = x * psireturn outclass AttentionUNet3D(nn.Module):def __init__(self, in_channels, out_channels):super(AttentionUNet3D, self).__init__()# Encoder Partself.encoder1 = EncoderBlock(in_channels=in_channels, out_channels=64)self.encoder2 = EncoderBlock(in_channels=64, out_channels=128)self.encoder3 = EncoderBlock(in_channels=128, out_channels=256)self.encoder4 = EncoderBlock(in_channels=256, out_channels=512)# Center part.self.center = CenterBlock(in_channels=512, out_channels=512)# Decoder part.self.decoder4 = DecoderBlock(in_channels=1024, out_channels=256)self.decoder3 = DecoderBlock(in_channels=512, out_channels=128)self.decoder2 = DecoderBlock(in_channels=256, out_channels=64)# Final part.self.final = FinalBlock(in_channels=128, out_channels=out_channels)# Attention Gateself.att4 = AttentionGates3D(F_g=512, F_l=512, F_int=256)self.att3 = AttentionGates3D(F_g=256, F_l=256, F_int=128)self.att2 = AttentionGates3D(F_g=128, F_l=128, F_int=64)self.att1 = AttentionGates3D(F_g=64, F_l=64, F_int=32)def forward(self, x):# Encoding, compressive pathway.out_encoder1 = self.encoder1(x)out_endocer1_mp = maxpool2x2(out_encoder1)out_encoder2 = self.encoder2(out_endocer1_mp)out_endocer2_mp = maxpool2x2(out_encoder2)out_encoder3 = self.encoder3(out_endocer2_mp)out_endocer3_mp = maxpool2x2(out_encoder3)out_encoder4 = self.encoder4(out_endocer3_mp)# Decoding, expansive pathway.out_endocer4_mp = maxpool2x2(out_encoder4)out_center = self.center(out_endocer4_mp)out_att4 = self.att4(g=out_center, x=out_encoder4)out_decoder4 = self.decoder4(torch.cat((out_center, out_att4), 1))out_att3 = self.att3(g=out_decoder4, x=out_encoder3)out_decoder3 = self.decoder3(torch.cat((out_decoder4, out_att3), 1))out_att2 = self.att2(g=out_decoder3, x=out_encoder2)out_decoder2 = self.decoder2(torch.cat((out_decoder3, out_att2), 1))out_att1 = self.att1(g=out_decoder2, x=out_encoder1)out_final = self.final(torch.cat((out_decoder2, out_att1), 1))return out_finalif __name__ == '__main__':data_=torch.rand(1,1,64,64,64)model=AttentionUNet3D(in_channels=1,out_channels=2)print(model)out_data=model(data_)print(out_data.shape)print("*" * 30 + "\n |\t\tEnd Of Program\t\t|\n" + "*" * 30)

六、Attention Unet注意力机制是空间注意力还是通道注意力?

通道注意力和空间注意力,分别捕捉通道间的依赖关系和空间上的像素级关系,同时使用这两类注意力机制可以达到更好的效果(例如CBAM),但无疑增加了更多的计算量。

CBAM(convolutional block attention modules)是一个卷积块注意力模块,作用于输入图像,按照顺序将注意力机制应用于通道,然后是空间维度。CBAM的结果是一个加权的特征图,考虑了输入图像的通道和空间区域。

Attention UNet相关推荐

  1. 论文笔记:Attention U-Net: Learning Where to Look for the Pancreas

    Abstract 我们提出了一种用于医学成像的新型注意门(AG)模型,该模型自动学习聚焦于不同形状和大小的目标结构.用AG训练的模型隐 含地学习抑制输入图像中的不相关区域,同时突出显示对特定任务有用的 ...

  2. 医学图像分割之Attention U-Net

    目录 一.背景 二.问题 三.解决问题 四.Attention U-Net网络结构 简单总结Attention U-Net的操作:增强目标区域的特征值,抑制背景区域的目标值.抑制也就是设为了0. 一. ...

  3. 【论文翻译-3】Attention U-Net: Learning Where to Look for the Pancreas

    Attention U-Net: Learning Where to Look for the Pancreas 阅读日期:2020年11月25日 Abstract 我们提出新型注意力门控(atten ...

  4. SA-UNet: Spatial Attention U-Net for Retinal Vessel Segmentation

    论文阅读:SA-UNet: Spatial Attention U-Net for Retinal Vessel Segmentation 用于视网膜血管分割的空间注意力U-Net 摘要:视网膜血管的 ...

  5. 【语义分割系列:七】Attention Unet 论文阅读翻译笔记 医学图像 python实现

    Attention U-Net 2018 CVPR Ozan Oktay, Jo Schlemper, Loic Le Folgoc, Matthew Lee Attention U-Net: Lea ...

  6. 基于Attention U-Net的宠物图像分割

    图像分割 基础 Attention U-Net 环境设置 数据处理 提取划分图片 图片和标签展示 数据集类定义 模型组网 基础模块 Attention块 Attention U-Net 模型可视化 训 ...

  7. Attention U-Net: Learning Where to Look for the Pancreas

    Abstract 我们提出了一种用于医学成像的新型注意门(AG)模型,该模型自动学习聚焦于不同形状和大小的目标结构.用AG训练的模型隐含地学习抑制输入图像中的不相关区域,同时突出显示对特定任务有用的显 ...

  8. Attention U-Net网络

    Attention U-Net网络pytorch构建 from torch import nn from torch.nn import functional as F import torch fr ...

  9. Spatial Attention U-Net for Retinal Vessel Segmentation(ICPR 2020)

    总的来讲,改进比较常规,引入dropblock,并在桥接阶段加入空间注意力. keras实现model Dropblock.py import keras import keras.backend a ...

  10. APAUNet: Axis Projection Attention UNet for Small Target Segmentation in 3D Medical Images. In ACCV

    APAUNet Introduction By Yuncheng Jiang*, Zixun Zhang*, Shixi Qin, Yao guo, Zhen Li, Shuguang Cui. Th ...

最新文章

  1. Java反射实践:从反射中理解class
  2. Java6.0中Comparable接口与Comparator接口详解
  3. Jetty实战之 嵌入式Jetty运行web app
  4. 《JavaScript面向对象编程指南》——1.7 训练环境设置
  5. EDA实验课课程笔记(六)——NC-verilog的介绍与使用(二)
  6. 基于 pureXML 技术的数据库表结构扩展
  7. Thinking in Java 13.7扫描输入
  8. Elasticsearch---Analyzer(分析器)
  9. 苹果电脑怎么安装计算机一级,苹果系统安装教程,详细教您苹果电脑怎么重装系统...
  10. 计算机图形图像设计构图的基本形式,构图一学就会!构图基本形式只有四种
  11. linux c 获取usb vid,Linux如何使用libudev获取USB设备VID及PID
  12. Java 发送邮件的几种方式
  13. ipad照片文件删除了怎么恢复
  14. 【实战技能】从《Beautiful Teams》一书看团队
  15. 【数据结构】共享栈详解 判断共享栈满条件栈顶指针变化详解记忆方法例题
  16. 离婚时夫妻共同债务和个人债务如何区分
  17. 计算机名称显示word作者,如何让word文档不显示作者名
  18. 对rtthread系统的理解
  19. java宅急送下载_基于jsp的宅急送物流管理系统-JavaEE实现宅急送物流管理系统 - java项目源码...
  20. 开发Unity3D空战类插件 战机HUD系统

热门文章

  1. 广告策划书的一般模式
  2. MT管理系去弹窗【失败】
  3. 软件测试周刊(第47期):要爱具体的人,不要爱抽象的人;要爱生活,不要爱生活的意义。
  4. 图像补全(image inpainting)
  5. Data Recovery Strategy Determines Backup Strategy【每日一译】--2012-11-11
  6. php fpm在哪配置,php配置php-fpm启动参数及配置详解
  7. HCIP 云计算资料下载 肖哥视频下载
  8. Cocos Creator下JavaScript模拟砸金蛋3d旋转效果,附代码
  9. 判断网卡MAC地址前缀
  10. 2020年408真题_2020年港澳台联考真题——英语!