每日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考虑到跨尺度交互作用以增强特征表示。

相关推荐
XLYcmy21 小时前
ASR 识别任务:两篇论文阅读分析与系统方案技术报告 当前报告不足
论文阅读·论文笔记·token·cuda·asr·论文分享·tokenizer
feasibility.2 天前
LeCun团队世界模型JEPA首登无人机:9K参数模型,零样本Sim-to-Real飞入100Hz闭环
论文阅读·嵌入式·无人机·具身智能·世界模型·杨立昆·jpea
XLYcmy2 天前
ASR识别任务两篇论文阅读分析与系统方案技术报告 上
论文阅读·ai·gpu·asr·论文分享·speechbrain·wespeaker
Zucker n3 天前
文献发现、课题组织与证据可追溯的论文阅读。
论文阅读·windows·ubuntu
西柚小萌新3 天前
【论文阅读】--可信LLM智能体的威胁与对策 综述
论文阅读
Rocky Ding*3 天前
【三年面试五年模拟】2026-11-05_月之暗面大模型算法岗一面、二面面经全解析
论文阅读·人工智能·深度学习·机器学习·aigc·强化学习·ai-native
Rocky Ding*5 天前
REPA-E技术深度解析:解冻 VAE 之后,扩散模型为什么需要选择梯度
论文阅读·人工智能·深度学习·机器学习·aigc·ai-native·repa-e
Rocky Ding*6 天前
【三年面试五年模拟】2026-11-01_字节跳动AI Agent全栈研发一面面经全解析
论文阅读·人工智能·深度学习·机器学习·aigc·ai-native·ai agent
五网6 天前
软件测试用例模板怎么写:从用例设计到执行记录的全套指南
软件测试·论文阅读·全文检索·测试用例·论文笔记·用例设计·用例模板
Rocky Ding*7 天前
深入浅出IDM-VTON论文精读:虚拟试衣怎样同时保住服装语义与局部细节
论文阅读·人工智能·深度学习·机器学习·aigc·ai-native·idm-vton