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

ResLFE 残差局部特征提取模块

计算量砍十倍:位置编码改成阶段级,每个 stage 开头预计算一次、全 stage 复用,FLOPs 直接减半(92.2G→44.6G),最终只用 plain 设计 10% 的计算量(92.2G→9.2G),

三维视觉三维点云点云分割ResLFECVPR2025深度网络

结构图

ResLFE 残差局部特征提取模块结构图
ResLFE 残差局部特征提取模块结构图

计算量砍十倍:位置编码改成阶段级,每个 stage 开头预计算一次、全 stage 复用,FLOPs 直接减半(92.2G→44.6G),最终只用 plain 设计 10% 的计算量(92.2G→9.2G),

论文信息

  • 论文:DeepLA-Net: Very Deep Local Aggregation Networks for Point Cloud Analysis
  • 出处:CVPR 2025

核心痛点

点云稀疏、离散又无序,局部模式本就难学,主流局部聚合网络(LANet)还一味堆更复杂的局部表征设计,但 S3DIS 性能早已饱和在 73% 附近。2D CNN 靠残差连接走通了"以深度换性能"的路,LANet 却被高计算成本和难优化卡住,深不下去。

模块亮点

  • 计算量砍十倍:位置编码改成阶段级,每个 stage 开头预计算一次、全 stage 复用,FLOPs 直接减半(92.2G→44.6G),最终只用 plain 设计 10% 的计算量(92.2G→9.2G),推理快 3.75 倍
  • 向量特征表征:用"中心点减邻居"的特征差替代分组特征,与相对位置嵌入对齐,零额外计算涨 1.2%(67.4%→68.6%)
  • 深度红利:24 块模型以 10% 算力反超 plain 基线 1.1%(69.0%→70.1%);DeepLA-Net 最深 120 块、单张 RTX 3090 就能训,S3DIS Area5 达 75.7% mIoU(首次突破 75%)

适用场景

领域为 3D 点云分析,原文验证了 S3DIS / ScanNet v2 语义分割、ScanObjectNN 物体分类等任务。

插入位置建议

  • 直接替换 PointNet++、PointNeXt 等局部聚合骨干里的局部特征提取层
  • 在 stage 内堆叠 ResLFE 块搭深骨干,按原文 1:1:3:1 的块比例分四个 stage、通道数逐级翻倍(64→512)
  • 把逐层计算的位置编码挪到 stage 开头算一次并缓存复用,其余不动就能省近一半开销

适用任务

  • 3D 点云分析
  • 原文验证了 S3DIS
  • ScanNet v2 语义分割

完整代码

reslfe.py
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.utils.checkpoint import checkpoint as torch_checkpoint
from torch.nn.init import trunc_normal_
import sys
from pathlib import Path
sys.path.append(str(Path(__file__).absolute().parent.parent))


class DropPath(nn.Module):
    def __init__(self, drop_prob=0.0):
        super().__init__()
        self.drop_prob = drop_prob

    def forward(self, x):
        if self.drop_prob == 0. or not self.training:
            return x
        keep_prob = 1 - self.drop_prob
        batch_size = x.size(0)
        random_tensor = keep_prob + torch.rand(batch_size, 1, 1, device=x.device)
        random_tensor = random_tensor.floor()  # binary mask
        output = x / keep_prob * random_tensor
        return output


def vector_feature(x, knn, training=True):
    # Assuming knn is a tensor of shape (B, N, k) where k is the number of nearest neighbors
    # and x is of shape (B, N, C), where B is the batch size, N is the number of points, and C is the feature dimension.
    B, N, C = x.shape
    if not training:
        return x  # For inference, just return the input features

    # Example: simple knn-based feature aggregation
    knn_features = []
    for i in range(B):
        for j in range(N):
            # Assuming knn[i, j, :] are indices of k nearest neighbors for point (i, j)
            neighbors = x[i, knn[i, j, :], :]  # Shape: (k, C)
            aggregated_feature = torch.mean(neighbors, dim=0)  # Aggregate by mean
            knn_features.append(aggregated_feature)

    # Convert list to tensor and reshape
    knn_features = torch.stack(knn_features, dim=0).view(B, N, C)
    return knn_features


def checkpoint(function, *args, **kwargs):
    return torch_checkpoint(function, *args, use_reentrant=False, **kwargs)

class VFR(nn.Module):
    def __init__(self, in_dim, out_dim, bn_momentum, init=0.):
        super().__init__()
        self.linear = nn.Linear(in_dim, out_dim, bias=False)
        self.bn = nn.BatchNorm1d(out_dim, momentum=bn_momentum)
        nn.init.constant_(self.bn.weight, init)

    def forward(self, x, knn):
        B, N, C = x.shape
        x = self.linear(x)
        x = vector_feature(x, knn, self.training)
        x = self.bn(x.view(B*N, -1)).view(B, N, -1)
        return x

class FFN(nn.Module):
    def __init__(self, in_dim, mlp_ratio, bn_momentum, act, init=0.):
        super().__init__()
        hid_dim = round(in_dim * mlp_ratio)
        self.ffn = nn.Sequential(
            nn.Linear(in_dim, hid_dim),
            act(),
            nn.Linear(hid_dim, in_dim, bias=False),
            nn.BatchNorm1d(in_dim, momentum=bn_momentum),
        )
        nn.init.constant_(self.ffn[-1].weight, init)

    def forward(self, x):
        B, N, C = x.shape
        x = self.ffn(x.view(B*N, -1)).view(B, N, -1)
        return x

class ResLFE_Block(nn.Module):
    def __init__(self, dim, depth, drop_path, mlp_ratio, bn_momentum, act):
        super().__init__()

        self.depth = depth
        self.VFRs = nn.ModuleList([VFR(dim, dim, bn_momentum) for _ in range(depth)])
        self.mlp = FFN(dim, mlp_ratio, bn_momentum, act, 0.2)
        self.FFNs = nn.ModuleList([FFN(dim, mlp_ratio, bn_momentum, act) for _ in range(depth)])

        if isinstance(drop_path, list):
            drop_rates = drop_path
            self.dp = [dp > 0. for dp in drop_path]
        else:
            drop_rates = torch.linspace(0., drop_path, self.depth).tolist()
            self.dp = [drop_path > 0.] * depth
        self.drop_paths = nn.ModuleList([DropPath(dpr) for dpr in drop_rates])

    def drop_path(self, x, i, pts):
        if not self.dp[i] or not self.training:
            return x
        if pts is None:
            # 如果pts为None,直接对整个张量应用drop path
            return self.drop_paths[i](x)
        else:
            # 如果pts不为None,按照pts分割并分别应用drop path
            return torch.cat([self.drop_paths[i](xx) for xx in torch.split(x, pts, dim=1)], dim=1)

    def forward(self, x, pe, knn, pts=None):
        x = x + self.drop_path(self.mlp(x), 0, pts)
        for i in range(self.depth):
            x = x + pe
            x = x + self.drop_path(self.VFRs[i](x, knn), i, pts)
            x = x + self.drop_path(self.FFNs[i](x), i, pts)
        return x


if __name__ == '__main__':
    # Test parameters
    batch_size = 2
    num_points = 1024
    feature_dim = 64
    k_neighbors = 16

    # Create input tensor
    x = torch.randn(batch_size, num_points, feature_dim).to('cuda')

    # Create positional encoding (dummy)
    pe = torch.randn(batch_size, num_points, feature_dim).to('cuda')

    # Create dummy knn indices (for testing)
    knn = torch.randint(0, num_points, (batch_size, num_points, k_neighbors)).to('cuda')

    # Create block
    block = ResLFE_Block(
        dim=feature_dim,
        depth=2,
        drop_path=0.1,
        mlp_ratio=4.0,
        bn_momentum=0.1,
        act=nn.GELU
    ).to('cuda')

    # Forward pass
    output = block(x, pe, knn)

    print(f"Input size: {x.size()}")
    print(f"Output size: {output.size()}")

环境与依赖

Python 3.9+

继续浏览

下一篇RFAConv 感受野注意力卷积感受野级注意力:把特征图重排成互不重叠的滑动窗口,用 AvgPool + 1×1 分组卷积 + Softmax 为每个感受野单独生成注意力权重,卷积参数不再共享

相关资源