1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
| import torch import torch.nn as nn import torch.nn.functional as F
class mmDEAR(nn.Module): """ mmDEAR: mmWave Point Cloud Density Enhancement 论文: arXiv 2503.02375 核心思路: 1. 将稀疏点云上采样到密集点云 2. 使用深度学习预测中间点 3. 保持物理一致性(不产生虚假点) """ def __init__( self, input_dim: int = 3, upsample_factor: int = 16, hidden_dim: int = 256 ): super().__init__() self.upsample_factor = upsample_factor self.feature_extractor = nn.Sequential( nn.Linear(input_dim, 64), nn.BatchNorm1d(64), nn.ReLU(), nn.Linear(64, 128), nn.BatchNorm1d(128), nn.ReLU(), nn.Linear(128, hidden_dim), nn.BatchNorm1d(hidden_dim), nn.ReLU() ) self.density_head = nn.Sequential( nn.Linear(hidden_dim, hidden_dim), nn.ReLU(), nn.Linear(hidden_dim, upsample_factor * 3) ) self.confidence_head = nn.Sequential( nn.Linear(hidden_dim, hidden_dim // 2), nn.ReLU(), nn.Linear(hidden_dim // 2, upsample_factor), nn.Sigmoid() ) def forward(self, points: torch.Tensor) -> dict: """ Args: points: 稀疏点云, shape=(B, N, 3) Returns: result: { dense_points: 密集点云, shape=(B, N*r, 3) confidence: 每点置信度, shape=(B, N*r) } """ B, N, _ = points.shape features = self.feature_extractor(points.reshape(B * N, -1)) features = features.reshape(B, N, -1) global_feat = features.max(dim=1)[0] per_point_feat = features + global_feat.unsqueeze(1) offsets = self.density_head(per_point_feat) offsets = offsets.reshape(B, N, self.upsample_factor, 3) confidence = self.confidence_head(per_point_feat) original_expanded = points.unsqueeze(2).expand(-1, -1, self.upsample_factor, -1) dense_points = original_expanded + offsets dense_points = dense_points.reshape(B, N * self.upsample_factor, 3) confidence = confidence.reshape(B, N * self.upsample_factor) threshold = 0.5 mask = confidence > threshold filtered_points = dense_points[mask.unsqueeze(-1).expand_as(dense_points)].reshape(B, -1, 3) return { 'dense_points': dense_points, 'filtered_points': filtered_points, 'confidence': confidence }
if __name__ == "__main__": model = mmDEAR(upsample_factor=16) sparse_points = torch.randn(4, 150, 3) * 0.5 result = model(sparse_points) print(f"原始点数: {sparse_points.shape[1]}") print(f"密集点数: {result['dense_points'].shape[1]}") print(f"高置信度点数: {result['filtered_points'].shape[1]}") print(f"参数量: {sum(p.numel() for p in model.parameters()):,}")
|