学术
模块更新于 2026-11-20· 浏览 1· 下载 0

ESAM 边缘空间注意力模块

梯度引导注意力:用两组固定权重的 Sobel 卷积分别计算横向、纵向梯度,合成幅值后经 Sigmoid 生成边缘空间注意力图,对原特征加权增强,把边缘信息融进特征图(记作 ESAB)

医学影像医学图像分割脑肿瘤分割ESAM边缘注意力多模态MRI

结构图

ESAM 边缘空间注意力模块结构图
ESAM 边缘空间注意力模块结构图

梯度引导注意力:用两组固定权重的 Sobel 卷积分别计算横向、纵向梯度,合成幅值后经 Sigmoid 生成边缘空间注意力图,对原特征加权增强,把边缘信息融进特征图(记作 ESAB)

论文信息

  • 论文:Brain Tumor Segmentation Based on the Fusion of Deep Semantics and Edge Information in Multimodal MRI
  • 出处:Information Fusion 2022

核心痛点

多模态脑肿瘤分割方法大多只顾提取深层语义特征,把 FLAIR、T1、T1ce、T2 各模态简单堆叠成多通道输入,忽略了对分割有特定意义的边缘信息;且边缘是浅层特征,用深层网络最后一个卷积块提取效果大打折扣。

模块亮点

  • 梯度引导注意力:用两组固定权重的 Sobel 卷积分别计算横向、纵向梯度,合成幅值后经 Sigmoid 生成边缘空间注意力图,对原特征加权增强,把边缘信息融进特征图(记作 ESAB)
  • 逐级精炼边缘:边缘分支只喂对边缘敏感的 FLAIR 和 T1ce 模态,经 4 个卷积块逐级提取特征,每级输出都过一次该模块精炼,充分利用中间层的边缘特征
  • 轻量即插即用:Sobel 核固定不训练,主体就是 3×3 卷积、1×1 卷积加 BN、ReLU 与残差连接,不改变通道数与特征图尺寸,任意 CNN 骨干都能直接插入;整体模型在 BraTS 2018、2019、2020 上优于多个 SOTA 方法

适用场景

领域为多模态脑肿瘤 MRI 分割,原文在 BraTS 2018、2019、2020 上验证了水肿(ED)、坏死与非增强肿瘤(NCR/NET)、增强肿瘤(ET)区域的分割;也适合器官与病灶分割、病理图像分割等看重边界质量的任务。

插入位置建议

  • 接在 CNN 骨干每个卷积块输出之后,逐级精炼特征
  • 放在 U-Net 编码器各层特征之后、跳跃连接之前,让特征自带边缘信息
  • 插在边缘分支与语义分支融合之前,先增强边缘特征再做融合

适用任务

  • 多模态脑肿瘤 MRI 分割
  • 原文在 BraTS 2018
  • 2019

完整代码

esam.py
import torch
import torch.nn as nn
import numpy as np
import torch.nn.functional as F

"""
ESAM被用作一个独立的网络模块,其主要功能是通过卷积层和梯度增强来处理输入特征图,目的是增强图像的边缘信息,从而更好地捕捉边缘细节。
通过这种方式,ESAM旨在将边缘信息集成到特征图中,帮助提高分割的精确度。
"""


def get_sobel(in_chan, out_chan):
    filter_x = np.array([
        [1, 0, -1],
        [2, 0, -2],
        [1, 0, -1],
    ]).astype(np.float32)
    filter_y = np.array([
        [1, 2, 1],
        [0, 0, 0],
        [-1, -2, -1],
    ]).astype(np.float32)

    filter_x = filter_x.reshape((1, 1, 3, 3))
    filter_x = np.repeat(filter_x, in_chan, axis=1)
    filter_x = np.repeat(filter_x, out_chan, axis=0)

    filter_y = filter_y.reshape((1, 1, 3, 3))
    filter_y = np.repeat(filter_y, in_chan, axis=1)
    filter_y = np.repeat(filter_y, out_chan, axis=0)

    filter_x = torch.from_numpy(filter_x)
    filter_y = torch.from_numpy(filter_y)
    filter_x = nn.Parameter(filter_x, requires_grad=False)
    filter_y = nn.Parameter(filter_y, requires_grad=False)
    conv_x = nn.Conv2d(in_chan, out_chan, kernel_size=3, stride=1, padding=1, bias=False)
    conv_x.weight = filter_x
    conv_y = nn.Conv2d(in_chan, out_chan, kernel_size=3, stride=1, padding=1, bias=False)
    conv_y.weight = filter_y
    sobel_x = nn.Sequential(conv_x, nn.BatchNorm2d(out_chan))
    sobel_y = nn.Sequential(conv_y, nn.BatchNorm2d(out_chan))

    return sobel_x, sobel_y


def run_sobel(conv_x, conv_y, input):
    g_x = conv_x(input)
    g_y = conv_y(input)
    g = torch.sqrt(torch.pow(g_x, 2) + torch.pow(g_y, 2))
    return torch.sigmoid(g) * input


class ESAM(nn.Module):
    def __init__(self, in_channels):
        super(ESAM, self).__init__()
        self.conv1 = nn.Conv2d(in_channels, in_channels, kernel_size=3, padding=1)
        self.conv2 = nn.Conv2d(in_channels, in_channels, kernel_size=1)  # 保持通道数不变
        self.bn = nn.BatchNorm2d(in_channels)  # 用于conv1和conv2的输出
        self.sobel_x1, self.sobel_y1 = get_sobel(in_channels, in_channels)  # 注意此处

    def forward(self, x):
        y = run_sobel(self.sobel_x1, self.sobel_y1, x)
        y = F.relu(self.bn(y))
        y = self.conv1(y)
        y = x + y
        y = self.conv2(y)
        y = F.relu(self.bn(y))  # 使用self.bn而不是self.ban

        return y



if __name__ == '__main__':
    block = ESAM(in_channels=3)
    input = torch.rand(32, 3, 224, 224)
    output = block(input)
    print(input.size())
    print(output.size())

环境与依赖

Python 3.9+

继续浏览

下一篇EVM 高效视觉Mamba模块重活搬进隐藏状态:HSM-SSD 先把 L 个 token 压成 N 个共享隐藏状态(N≪L),通道混合直接在 N×D 隐藏状态上完成,全局交互复杂度降到 O(ND²+LND)

相关资源