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

SCConv 空间与通道重建卷积

空间通道一起压:SRU 借组归一化中可训练的缩放因子 γ 评估特征图信息量,门控分出信息量大 / 小两部分再交叉重构,抑制空间冗余;

计算机视觉计算机视觉模型压缩SCConvCVPR2023轻量化网络

结构图

SCConv 空间与通道重建卷积结构图
SCConv 空间与通道重建卷积结构图

空间通道一起压:SRU 借组归一化中可训练的缩放因子 γ 评估特征图信息量,门控分出信息量大 / 小两部分再交叉重构,抑制空间冗余;

论文信息

  • 论文:SCConv: Spatial and Channel Reconstruction Convolution for Feature Redundancy
  • 出处:CVPR 2023

核心痛点

CNN 卷积层特征存在大量冗余,参数和计算开销居高不下;GhostNet、SPConv、OctConv 等高效卷积只压单一维度的冗余,空间与通道冗余始终没被同时解决。

模块亮点

  • 空间通道一起压:SRU 借组归一化中可训练的缩放因子 γ 评估特征图信息量,门控分出信息量大 / 小两部分再交叉重构,抑制空间冗余;CRU 用 GWC+PWC 提取代表特征,廉价 1×1 卷积加特征复用处理次要特征,削减通道冗余
  • 消融涨点实打实:CIFAR-100 上 ResNet50 基线 78.60%,只嵌 SRU 升到 79.59%,只嵌 CRU 升到 79.21% 且参数、FLOPs 省 38%,完整 SCConv 达到 79.89%,为三种组合中的最优
  • 又轻又准:参数量约为标准 3×3 卷积的 1/5;ImageNet-1K 上 SCConv-R50 计算量降 34.4%、Top-1 精度反升 0.26%

适用场景

领域为轻量化网络设计与模型压缩;原文实验覆盖 CIFAR-100、ImageNet-1K 图像分类和 MS COCO 目标检测;同样适合语义分割等以 CNN 为骨干的任务,尤其适合资源受限设备的部署。

插入位置建议

  • 替换 ResNet 瓶颈残差块里的 3×3 标准卷积,论文消融和 ImageNet 实验都在这个位置
  • 替换 ResNeXt、WideResNet、DenseNet 等骨干中的 3×3 卷积,论文均验证有效
  • 替换 RetinaNet 等检测框架骨干里的 3×3 卷积,降参数降 FLOPs 还涨点

适用任务

  • 轻量化网络设计与模型压缩

完整代码

scconv.py
import torch
import torch.nn.functional as F
import torch.nn as nn


class GroupBatchnorm2d(nn.Module):
    def __init__(self, c_num: int,
                 group_num: int = 16,
                 eps: float = 1e-10
                 ):
        super(GroupBatchnorm2d, self).__init__()
        assert c_num >= group_num
        self.group_num = group_num
        self.weight = nn.Parameter(torch.randn(c_num, 1, 1))
        self.bias = nn.Parameter(torch.zeros(c_num, 1, 1))
        self.eps = eps

    def forward(self, x):
        N, C, H, W = x.size()
        x = x.view(N, self.group_num, -1)
        mean = x.mean(dim=2, keepdim=True)
        std = x.std(dim=2, keepdim=True)
        x = (x - mean) / (std + self.eps)
        x = x.view(N, C, H, W)
        return x * self.weight + self.bias


class SRU(nn.Module):
    def __init__(self,
                 oup_channels: int,
                 group_num: int = 16,
                 gate_treshold: float = 0.5,
                 torch_gn: bool = False
                 ):
        super().__init__()

        self.gn = nn.GroupNorm(num_channels=oup_channels, num_groups=group_num) if torch_gn else GroupBatchnorm2d(
            c_num=oup_channels, group_num=group_num)
        self.gate_treshold = gate_treshold
        self.sigomid = nn.Sigmoid()

    def forward(self, x):
        gn_x = self.gn(x)
        w_gamma = self.gn.weight / torch.sum(self.gn.weight)
        w_gamma = w_gamma.view(1, -1, 1, 1)
        reweigts = self.sigomid(gn_x * w_gamma)
        # Gate
        info_mask = reweigts >= self.gate_treshold
        noninfo_mask = reweigts < self.gate_treshold
        x_1 = info_mask * gn_x
        x_2 = noninfo_mask * gn_x
        x = self.reconstruct(x_1, x_2)
        return x

    def reconstruct(self, x_1, x_2):
        x_11, x_12 = torch.split(x_1, x_1.size(1) // 2, dim=1)
        x_21, x_22 = torch.split(x_2, x_2.size(1) // 2, dim=1)
        return torch.cat([x_11 + x_22, x_12 + x_21], dim=1)


class CRU(nn.Module):
    '''
    alpha: 0<alpha<1
    '''

    def __init__(self,
                 op_channel: int,
                 alpha: float = 1 / 2,
                 squeeze_radio: int = 2,
                 group_size: int = 2,
                 group_kernel_size: int = 3,
                 ):
        super().__init__()
        self.up_channel = up_channel = int(alpha * op_channel)
        self.low_channel = low_channel = op_channel - up_channel
        self.squeeze1 = nn.Conv2d(up_channel, up_channel // squeeze_radio, kernel_size=1, bias=False)
        self.squeeze2 = nn.Conv2d(low_channel, low_channel // squeeze_radio, kernel_size=1, bias=False)
        # up
        self.GWC = nn.Conv2d(up_channel // squeeze_radio, op_channel, kernel_size=group_kernel_size, stride=1,
                             padding=group_kernel_size // 2, groups=group_size)
        self.PWC1 = nn.Conv2d(up_channel // squeeze_radio, op_channel, kernel_size=1, bias=False)
        # low
        self.PWC2 = nn.Conv2d(low_channel // squeeze_radio, op_channel - low_channel // squeeze_radio, kernel_size=1,
                              bias=False)
        self.advavg = nn.AdaptiveAvgPool2d(1)

    def forward(self, x):
        # Split
        up, low = torch.split(x, [self.up_channel, self.low_channel], dim=1)
        up, low = self.squeeze1(up), self.squeeze2(low)
        # Transform
        Y1 = self.GWC(up) + self.PWC1(up)
        Y2 = torch.cat([self.PWC2(low), low], dim=1)
        # Fuse
        out = torch.cat([Y1, Y2], dim=1)
        out = F.softmax(self.advavg(out), dim=1) * out
        out1, out2 = torch.split(out, out.size(1) // 2, dim=1)
        return out1 + out2


class ScConv(nn.Module):
    def __init__(self,
                 op_channel: int,
                 group_num: int = 4,
                 gate_treshold: float = 0.5,
                 alpha: float = 1 / 2,
                 squeeze_radio: int = 2,
                 group_size: int = 2,
                 group_kernel_size: int = 3,
                 ):
        super().__init__()
        self.SRU = SRU(op_channel,
                       group_num=group_num,
                       gate_treshold=gate_treshold)
        self.CRU = CRU(op_channel,
                       alpha=alpha,
                       squeeze_radio=squeeze_radio,
                       group_size=group_size,
                       group_kernel_size=group_kernel_size)

    def forward(self, x):
        x = self.SRU(x)
        x = self.CRU(x)
        return x


# 输入 N C H W,  输出 N C H W
if __name__ == '__main__':
    x = torch.randn(1, 128, 256, 256)
    model = ScConv(128)
    x = model(x)
    print(x.shape)

环境与依赖

Python 3.9+

继续浏览

下一篇ScoreNet 分数估计网络分数引导梯度上升:把有噪点云分布建模为干净分布 p 与噪声 n 的卷积,峰值即干净表面;只估计对数概率的梯度(分数),沿分数迭代更新每点位置,论文未观察到收缩伪影,无需充气后处理

相关资源