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

MSGDC 多尺度分组空洞卷积

三路空洞并行:三条 3×3 分组空洞卷积(膨胀率 1、3、5)并行提特征,过 RPReLU 后相加归一化,聚合多尺度感受野上下文

计算机视觉计算机视觉模型轻量化MSGDC二值化网络CVPR2025

结构图

MSGDC 多尺度分组空洞卷积结构图
MSGDC 多尺度分组空洞卷积结构图

三路空洞并行:三条 3×3 分组空洞卷积(膨胀率 1、3、5)并行提特征,过 RPReLU 后相加归一化,聚合多尺度感受野上下文

论文信息

  • 论文:BHViT: Binarized Hybrid Vision Transformer
  • 出处:CVPR 2025

核心痛点

ViT 效果好但体量和计算量巨大,难部署到边缘设备;二值化虽省算力,但二值 CNN 策略直接搬到 ViT 会性能大跌。分层 ViT 前两个 stage 分辨率大、token 数量爆炸,二值化后近 99% 的注意力值趋近 0,大量相似度计算纯属冗余。

模块亮点

  • 三路空洞并行:三条 3×3 分组空洞卷积(膨胀率 1、3、5)并行提特征,过 RPReLU 后相加归一化,聚合多尺度感受野上下文
  • 分组卷积省算力:分组加空洞让参数量和复杂度显著低于普通卷积与自注意力,前两个 stage 当 token mixer,绕开注意力的平方复杂度;输入输出形状不变
  • 涨点有实证:ImageNet-1K 对比中,前两 stage 用 MSGDC、后两用 MSMHA 的混合架构 Top-1 达 70.1%,比纯 ViT 版高 1.3%、比纯 CNN 版(67.2%)高 2.9 个点;BHViT-Small 在 CIFAR-10 上 95.0% Top-1,超过 SOTA 二值方法 ReCU(92.8%)

适用场景

领域为模型压缩 / 二值化视觉 Transformer;原文验证了 ImageNet-1K、CIFAR-10 分类,ADE20K 语义分割和遥感道路分割(RS-LVF);也适合轻量检测 / 分割骨干的浅层特征提取。

插入位置建议

  • 替换分层骨干前两个 stage 的自注意力或其他 token mixer
  • 以残差 X + MSGDC(X) 堆进 block,接在 patch embedding 后、下采样前
  • 插进 CNN 卷积层之间当多尺度增强块,二值化网络里可替换标准卷积

适用任务

  • 模型压缩
  • 二值化视觉 Transformer

完整代码

msgdc.py
import torch
from torch import nn


class RPReLU(nn.Module):
    def __init__(self, hidden_size):
        super().__init__()
        self.move1 = nn.Parameter(torch.zeros(hidden_size))
        self.prelu = nn.PReLU(hidden_size)
        self.move2 = nn.Parameter(torch.zeros(hidden_size))

    def forward(self, x):
        out = self.prelu((x - self.move1).transpose(-1, -2)).transpose(-1, -2) + self.move2
        return out



class LearnableBiasnn(nn.Module):
    def __init__(self, out_chn):
        super(LearnableBiasnn, self).__init__()
        self.bias = nn.Parameter(torch.zeros([1, out_chn, 1, 1]), requires_grad=True)

    def forward(self, x):
        out = x + self.bias.expand_as(x)
        return out



class MSGDC(nn.Module):
    def __init__(self, in_chn, dilation1=1, dilation2=3, dilation3=5, kernel_size=3, stride=1, padding='same'):
        super(MSGDC, self).__init__()
        self.move = LearnableBiasnn(in_chn)
        self.cov1 = nn.Conv2d(in_chn, in_chn, kernel_size, stride, padding, dilation1, bias=True)
        self.cov2 = nn.Conv2d(in_chn, in_chn, kernel_size, stride, padding, dilation2, bias=True)
        self.cov3 = nn.Conv2d(in_chn, in_chn, kernel_size, stride, padding, dilation3, bias=True)
        self.norm = nn.LayerNorm(in_chn,eps=1e-6)
        self.act1 = RPReLU(in_chn)
        self.act2 = RPReLU(in_chn)
        self.act3 = RPReLU(in_chn)

    def forward(self, x):
        B, C, H, W = x.shape
        x = self.move(x)
        x1 = self.cov1(x).permute(0, 2, 3, 1).flatten(1, 2)
        x1 = self.act1(x1)
        x2 = self.cov2(x).permute(0, 2, 3, 1).flatten(1, 2)
        x2 = self.act2(x2)
        x3 = self.cov3(x).permute(0, 2, 3, 1).flatten(1, 2)
        x3 = self.act3(x3)
        x = self.norm(x1 + x2 + x3)
        return x.permute(0, 2, 1).view(-1, C, H, W).contiguous()


if __name__ == '__main__':
    block = MSGDC(in_chn=3).to('cuda')

    input_tensor = torch.rand(1, 3, 64, 64).to('cuda')

    output_tensor = block(input_tensor)

    print(f"Input size: {input_tensor.size()}")
    print(f"Output size: {output_tensor.size()}")

环境与依赖

Python 3.9+

继续浏览

下一篇MVCA 多变量相干注意力谱相干代替点积:对每个注意力头的 Q、K 沿变量维做 FFT,用互谱密度与功率谱密度算出归一化谱相干性,再 Softmax 成注意力权重

相关资源