首页 > 其他分享 >EMCAD: Efficient Multi-scale Convolutional Attention Decoding for Medical Image Segmentation-LAGA

EMCAD: Efficient Multi-scale Convolutional Attention Decoding for Medical Image Segmentation-LAGA

时间:2024-11-09 15:59:10浏览次数:1  
标签:Convolutional Multi scale nn self module init bias size

论文
代码
`
import torch
import torch.nn as nn
from functools import partial
from torch.nn.init import trunc_normal_
import math
from timm.models.helpers import named_apply

def act_layer(act, inplace=False, neg_slope=0.2, n_prelu=1):
# activation layer
act = act.lower()
if act == 'relu':
layer = nn.ReLU(inplace)
elif act == 'relu6':
layer = nn.ReLU6(inplace)
elif act == 'leakyrelu':
layer = nn.LeakyReLU(neg_slope, inplace)
elif act == 'prelu':
layer = nn.PReLU(num_parameters=n_prelu, init=neg_slope)
elif act == 'gelu':
layer = nn.GELU()
elif act == 'hswish':
layer = nn.Hardswish(inplace)
else:
raise NotImplementedError('activation layer [%s] is not found' % act)
return layer

def init_weights(module, name, scheme=''):
if isinstance(module, nn.Conv2d) or isinstance(module, nn.Conv3d):
if scheme == 'normal':
nn.init.normal
(module.weight, std=.02)
if module.bias is not None:
nn.init.zeros_(module.bias)
elif scheme == 'trunc_normal':
trunc_normal_(module.weight, std=.02)
if module.bias is not None:
nn.init.zeros_(module.bias)
elif scheme == 'xavier_normal':
nn.init.xavier_normal_(module.weight)
if module.bias is not None:
nn.init.zeros_(module.bias)
elif scheme == 'kaiming_normal':
nn.init.kaiming_normal_(module.weight, mode='fan_out', nonlinearity='relu')
if module.bias is not None:
nn.init.zeros_(module.bias)
else:
# efficientnet like
fan_out = module.kernel_size[0] * module.kernel_size[1] * module.out_channels
fan_out //= module.groups
nn.init.normal_(module.weight, 0, math.sqrt(2.0 / fan_out))
if module.bias is not None:
nn.init.zeros_(module.bias)
elif isinstance(module, nn.BatchNorm2d) or isinstance(module, nn.BatchNorm3d):
nn.init.constant_(module.weight, 1)
nn.init.constant_(module.bias, 0)
elif isinstance(module, nn.LayerNorm):
nn.init.constant_(module.weight, 1)
nn.init.constant_(module.bias, 0)

Large-kernel grouped attention gate (LGAG)

class LGAG(nn.Module):
'''
结合特征图与注意力系数,激活高相关性特征,高层特征的门控信号来控制网络不通阶段间的信息流动
在LAGA机制中,能够有效地融合来自skip链接的信息,以更少的计算在更大的局部上下文中捕获显著的特征。
用在需要将两个shape相同的tensor融合的地方。
'''
def init(self, F_g, F_l, F_int, kernel_size=3, groups=1, activation='relu'):
super(LGAG, self).init()

    if kernel_size == 1:
        groups = 1
    self.W_g = nn.Sequential(
        nn.Conv2d(F_g, F_int, kernel_size=kernel_size, stride=1, padding=kernel_size // 2, groups=groups,
                  bias=True),
        nn.BatchNorm2d(F_int)
    )
    self.W_x = nn.Sequential(
        nn.Conv2d(F_l, F_int, kernel_size=kernel_size, stride=1, padding=kernel_size // 2, groups=groups,
                  bias=True),
        nn.BatchNorm2d(F_int)
    )
    self.psi = nn.Sequential(
        nn.Conv2d(F_int, 1, kernel_size=1, stride=1, padding=0, bias=True),
        nn.BatchNorm2d(1),
        nn.Sigmoid()
    )
    self.activation = act_layer(activation, inplace=True)

    self.init_weights('normal')

def init_weights(self, scheme=''):
    named_apply(partial(_init_weights, scheme=scheme), self)

def forward(self, g, x):
    g1 = self.W_g(g)
    x1 = self.W_x(x)
    psi = self.activation(g1 + x1)
    psi = self.psi(psi)

    return x * psi

if name == 'main':
in_dim=128
width=4
hidden_dim=in_dim//width

block = LGAG(in_dim,in_dim,hidden_dim).cuda()
g = torch.randn(3,128,64,64).cuda() #输入 B C H W
x = torch.randn(3,128,64,64).cuda() #输入 B C H W
output = block(g,x)

print(input.size())
print(output.size())

`

标签:Convolutional,Multi,scale,nn,self,module,init,bias,size
From: https://www.cnblogs.com/plumIce/p/18536883

相关文章

  • Multi-Scale and Detail-Enhanced Segment Anything-1-MEEM-差分边缘增强模块
    `importtorch.nnasnnimporttorchclassMEEM(nn.Module):definit(self,in_dim,hidden_dim,width=4,norm=nn.BatchNorm2d,act=nn.GELU):super().init()self.in_dim=in_dimself.hidden_dim=hidden_dimself.width=widthself.in_conv=nn.Sequential(nn......
  • 106_api_intro_ai_multilingual-translation
    多语言AI翻译API数据接口ai/翻译基于AI多语言模型支持多语言/基于模型。1.产品功能基于自有专业模型进行AI多语言翻译高效的文本翻译性能全接口支持HTTPS(TLSv1.0/v1.1/v1.2/v1.3);全面兼容AppleATS;全国多节点CDN部署;接口极速响应,多台服务器构......
  • Multi-Scale and Detail-Enhanced Segment Anything-1-LMSA-轻量级多尺度适配器
    `importtorch.nnasnnimporttorchimporttorch.nn.functionalasFclassModifyPPM(nn.Module):definit(self,in_dim,reduction_dim,bins):super(ModifyPPM,self).init()self.features=[]forbininbins:self.features.append(nn.Sequential(nn.Adaptive......
  • CrewAI-Multimodal-Agent
    CrewAI-Multimodal-Agenthttps://github.com/mdwoicke/CrewAI-Multimodal-Agent #AICrewforReviewingMarkdownSyntax##IntroductionThisprojectisanexampleusingtheCrewAIframeworktoautomatetheprocessreviewingamarkdownfileforsyntaxiss......
  • 【YOLOv11改进 - 注意力机制】EMA(Efficient Multi-Scale Attention):基于跨空间学习的高
    介绍摘要通道或空间注意力机制在许多计算机视觉任务中表现出显著的效果,可以生成更清晰的特征表示。然而,通过通道维度缩减来建模跨通道关系可能会对提取深度视觉表示带来副作用。本文提出了一种新颖高效的多尺度注意力(EMA)模块。该模块着重于保留每个通道的信息并减少计算开销,我......
  • 【漏洞复现】灵当CRM multipleUpload.php 任意文件上传漏洞
    免责声明:        本文旨在提供有关特定漏洞的信息,以帮助用户了解潜在风险。发布此信息旨在促进网络安全意识和技术进步,并非出于恶意。读者应理解,利用本文提到的漏洞或进行相关测试可能违反法律或服务协议。未经授权访问系统、网络或应用程序可能导致法律责任或严......
  • CDDFuse: Correlation-Driven Dual-Branch Feature Decomposition for Multi-Modality
    文章信息标题CDDFuse:Correlation-DrivenDual-BranchFeatureDecompositionforMulti-ModalityImageFusion会议及时间CVPR2023主要内容为了解决建模跨模态特征和分解期望模态特有和模态共有特征的挑战,本文提出了一种用于多模态图像融合的双分支Transformer-CNN架构CDD......
  • 基于Multisim篮球比赛24S倒计时电路(含仿真和报告)
    【全套资料.zip】篮球比赛24S倒计时电路设计Multisim仿真设计数字电子技术文章目录功能一、Multisim仿真源文件二、原理文档报告资料下载【Multisim仿真+报告+讲解视频.zip】功能篮球比赛24S倒计时功能:1.具有数码管显示24S计时功能。2.设置外部开关,可以直接启动......
  • 基于Multisim光控夜灯LED电路(含仿真和报告)
    【全套资料.zip】光控夜灯LED电路设计Multisim仿真设计数字电子技术文章目录功能一、Multisim仿真源文件二、原理文档报告资料下载【Multisim仿真+报告+讲解视频.zip】功能光控夜灯LED电路1.采用纯数字电路,非单片机。2.通过检测周围光线,光线暗自动开灯,光线亮自......
  • 吴恩达深度学习笔记:卷积神经网络(Foundations of Convolutional Neural Networks)4.7-4.
    目录第四门课卷积神经网络(ConvolutionalNeuralNetworks)第四周特殊应用:人脸识别和神经风格转换(Specialapplications:Facerecognition&Neuralstyletransfer)4.7深度卷积网络学习什么?(WhataredeepConvNetslearning?)4.8代价函数(Costfunction)第四门课卷......