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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
| """ SoundMHPE: 声波多人3D姿态估计 论文: arXiv 2609.04902, ECCV 2026 项目: https://oumi03.github.io/sound-mhpe/
核心: 仅用声学信号(非视觉)估计多人3D姿态 依赖: torch>=2.0, numpy, librosa """
import torch import torch.nn as nn import torch.nn.functional as F from typing import Tuple
class AcousticMultiScaleEncoder(nn.Module): """ 声学多尺度编码器 从混合声波信号中提取: 1. 多时间尺度特征(短/中/长窗口) 2. 细粒度频率特征 3. 个体声学签名分离 """ def __init__(self, audio_dim: int = 128, num_persons: int = 4, freq_bins: int = 257): super().__init__() self.num_persons = num_persons self.short_conv = nn.Conv1d(freq_bins, audio_dim, 3, padding=1) self.medium_conv = nn.Conv1d(freq_bins, audio_dim, 7, padding=3) self.long_conv = nn.Conv1d(freq_bins, audio_dim, 15, padding=7) self.freq_encoder = nn.Sequential( nn.Linear(freq_bins, 256), nn.ReLU(), nn.Linear(256, audio_dim) ) self.person_separator = nn.MultiheadAttention( embed_dim=audio_dim, num_heads=8, batch_first=True ) self.person_heads = nn.ModuleList([ nn.Linear(audio_dim * 3, audio_dim) for _ in range(num_persons) ]) def forward(self, audio_spectrum: torch.Tensor) -> torch.Tensor: """ Args: audio_spectrum: (B, freq_bins, T) STFT频谱 Returns: person_features: (B, num_persons, audio_dim, T) """ B, F_bins, T = audio_spectrum.shape short_feat = self.short_conv(audio_spectrum) medium_feat = self.medium_conv(audio_spectrum) long_feat = self.long_conv(audio_spectrum) multi_scale = torch.cat([short_feat, medium_feat, long_feat], dim=1) seq = multi_scale.transpose(1, 2) freq_feat = self.freq_encoder(audio_spectrum.transpose(1, 2)) separated, _ = self.person_separator(seq, seq, seq) person_features = [] for i, head in enumerate(self.person_heads): person_feat = head(separated) person_features.append(person_feat) return torch.stack(person_features, dim=1)
class TemporalPoseDecoder(nn.Module): """ 时间姿态解码器 使用注意力机制: 1. 解多人信息(跨人关联) 2. 跨帧时序依赖 3. 逐帧个体姿态重建 """ def __init__(self, audio_dim: int = 128, num_joints: int = 17, num_persons: int = 4, num_frames: int = 16): super().__init__() self.num_joints = num_joints self.num_persons = num_persons self.temporal_attn = nn.MultiheadAttention( embed_dim=audio_dim, num_heads=8, batch_first=True ) self.cross_person_attn = nn.MultiheadAttention( embed_dim=audio_dim, num_heads=8, batch_first=True ) self.pose_regressor = nn.Sequential( nn.Linear(audio_dim, 256), nn.ReLU(), nn.Linear(256, num_joints * 3) ) def forward(self, person_features: torch.Tensor) -> torch.Tensor: """ Args: person_features: (B, num_persons, T, audio_dim) Returns: poses_3d: (B, num_persons, T, num_joints, 3) """ B, P, T, D = person_features.shape poses_all = [] for p in range(P): person_seq = person_features[:, p, :, :] attn_out, _ = self.temporal_attn(person_seq, person_seq, person_seq) poses = self.pose_regressor(attn_out) poses = poses.view(B, T, self.num_joints, 3) poses_all.append(poses) poses_3d = torch.stack(poses_all, dim=1) flat = poses_3d.view(B, P, -1) return poses_3d
class SoundMHPE(nn.Module): """ SoundMHPE: 完整的声波多人3D姿态估计模型 输入: 声波信号 (STFT频谱) 输出: 多人3D姿态序列 架构: 1. AcousticMultiScaleEncoder → 多人声学特征分离 2. TemporalPoseDecoder → 时序姿态重建 """ def __init__(self, num_persons: int = 4, num_joints: int = 17): super().__init__() self.encoder = AcousticMultiScaleEncoder(num_persons=num_persons) self.decoder = TemporalPoseDecoder(num_joints=num_joints, num_persons=num_persons) def forward(self, audio_spectrum: torch.Tensor) -> torch.Tensor: """ Args: audio_spectrum: (B, freq_bins, T) — STFT频谱 Returns: poses_3d: (B, num_persons, T, num_joints, 3) """ person_features = self.encoder(audio_spectrum) poses_3d = self.decoder(person_features) return poses_3d
if __name__ == "__main__": B, F_bins, T = 2, 257, 64 audio_spectrum = torch.randn(B, F_bins, T) model = SoundMHPE(num_persons=4, num_joints=17) poses_3d = model(audio_spectrum) print(f"输入: STFT频谱 {audio_spectrum.shape}") print(f"输出: 3D姿态 {poses_3d.shape}") print(f" → {poses_3d.shape[1]}人 × {poses_3d.shape[2]}帧 × {poses_3d.shape[3]}关节 × 3D") total_params = sum(p.numel() for p in model.parameters()) print(f"参数量: {total_params:,} ({total_params/1e6:.2f}M)")
|