每日Attention学习6——Context Aggregation Module

模块出处

link code IJCAI 22 Boundary-Guided Camouflaged Object Detection


模块名称

Context Aggregation Module (CAM)


模块作用

增大感受野,全局特征提取


模块结构

模块代码
python 复制代码
import torch
import torch.nn as nn
import torch.nn.functional as F


class ConvBNR(nn.Module):
    def __init__(self, inplanes, planes, kernel_size=3, stride=1, dilation=1, bias=False):
        super(ConvBNR, self).__init__()

        self.block = nn.Sequential(
            nn.Conv2d(inplanes, planes, kernel_size, stride=stride, padding=dilation, dilation=dilation, bias=bias),
            nn.BatchNorm2d(planes),
            nn.ReLU(inplace=True)
        )

    def forward(self, x):
        return self.block(x)


class Conv1x1(nn.Module):
    def __init__(self, inplanes, planes):
        super(Conv1x1, self).__init__()
        self.conv = nn.Conv2d(inplanes, planes, 1)
        self.bn = nn.BatchNorm2d(planes)
        self.relu = nn.ReLU(inplace=True)

    def forward(self, x):
        x = self.conv(x)
        x = self.bn(x)
        x = self.relu(x)

        return x
    

class CAM(nn.Module):
    def __init__(self, hchannel, channel):
        super(CAM, self).__init__()
        self.conv1_1 = Conv1x1(hchannel + channel, channel)
        self.conv3_1 = ConvBNR(channel // 4, channel // 4, 3)
        self.dconv5_1 = ConvBNR(channel // 4, channel // 4, 3, dilation=2)
        self.dconv7_1 = ConvBNR(channel // 4, channel // 4, 3, dilation=3)
        self.dconv9_1 = ConvBNR(channel // 4, channel // 4, 3, dilation=4)
        self.conv1_2 = Conv1x1(channel, channel)
        self.conv3_3 = ConvBNR(channel, channel, 3)

    def forward(self, lf, hf):
        if lf.size()[2:] != hf.size()[2:]:
            hf = F.interpolate(hf, size=lf.size()[2:], mode='bilinear', align_corners=False)
        x = torch.cat((lf, hf), dim=1)
        x = self.conv1_1(x)
        xc = torch.chunk(x, 4, dim=1)
        x0 = self.conv3_1(xc[0] + xc[1])
        x1 = self.dconv5_1(xc[1] + x0 + xc[2])
        x2 = self.dconv7_1(xc[2] + x1 + xc[3])
        x3 = self.dconv9_1(xc[3] + x2)
        xx = self.conv1_2(torch.cat((x0, x1, x2, x3), dim=1))
        x = self.conv3_3(x + xx)

        return x

    
if __name__ == '__main__':
    x1 = torch.randn([3, 256, 16, 16])
    x2 = torch.randn([3, 512, 8, 8])
    cam = CAM(hchannel=512, channel=256)
    out = cam(x1, x2)
    print(out.shape)  # 3, 256, 16, 16

原文表述

为了将多层次的融合特征整合到伪装物体预测中,我们设计了一个上下文聚合模块(CAM)来挖掘上下文语义,以增强物体检测,如图5所示。不同于BBSNet中的全局上下文模块不考虑各分支之间的语义关联,CAM考虑到跨尺度交互作用以增强特征表示。

相关推荐
大模型最新论文速读9 小时前
SkillOpt:把 skill 文档当成模型权重来训练
论文阅读·人工智能·深度学习·机器学习·自然语言处理
Cloud_Shy61810 小时前
解读《Effective Python 3rd Edition》:从练气到老魔(第一章 Item 4 - 6)
android·数据库·论文阅读·python
Rocky Ding*1 天前
一文读懂HiDream-I1稀疏 DiT 图像生成基础模型
论文阅读·人工智能·深度学习·机器学习·ai作画·aigc·ai-native
锅挤1 天前
来一篇儿:《anish into Thin Air: Cross-prompt Universal Adversarial Attacks for SAM2》
论文阅读
大模型最新论文速读1 天前
05-29 · LLM 最新论文速览
论文阅读·人工智能·深度学习·机器学习·自然语言处理
森诺Alyson2 天前
前沿技术借鉴研讨-2026.5.28(眼动数据预测抑郁&自杀倾向)
论文阅读·人工智能·深度学习·分类·论文笔记
凌晨一点的秃头猪3 天前
GR2(Generative Reasoning Reranker,生成式推理重排器)论文阅读
论文阅读
Biomamba生信基地3 天前
《Advanced Science》前沿工具发布:STAID,空间反卷积自优化深度学习框架
论文阅读·深度学习·生物信息学·模型训练
仙女修炼史4 天前
CNN更看重Texture还是shape:imagenet-trained cnns are biased
论文阅读·人工智能·cnn
大模型最新论文速读5 天前
GRPO 丢失的组内排序信息,LamPO 补回来了
论文阅读·人工智能·深度学习·机器学习·自然语言处理