取观测末步主体 0 的当前状态,在每个主体的观测与预测特征之间插入该状态。将三条主体序列并入 batch 经连续往返 Mamba,提取每条末 token 形成交互结果;ego 结果作为 Query 聚合所有主体,归一化后只写回最后时间步的 ego 位置。
[(2,6,3,8)] · D=8,layers=1,d_state=3,d_conv=3,obs_len=4;eval(2,6,3,8) · 仅最后时间步主体 0 的 8 维特征改变1,256 个参数(可训练 1,256;sum(p.numel()),包含非训练 Parameter,不计 buffer) · 轨迹预测中的 ego 交互上下文forward() 数据流顺序拆解 · 点击任意子模块方块可同步查看对应源码切片取观测末步主体 0 的当前状态,在每个主体的观测与预测特征之间插入该状态。将三条主体序列并入 batch 经连续往返 Mamba,提取每条末 token 形成交互结果;ego 结果作为 Query 聚合所有主体,归一化后只写回最后时间步的 ego 位置。
1166 ego_current_state = x[:, obs_len - 1, 0, :].unsqueeze(1).unsqueeze(1) # Shape: (B, 1, 1, D)1169 obs_part = x[:, :obs_len, :, :] # Shape: (B, obs_len, N, D)1170 pred_part = x[:, obs_len:, :, :] # Shape: (B, T - obs_len, N, D)1174 ego_current_state_expanded = ego_current_state.expand(-1, -1, N, -1) # Shape: (B, 1, N, D)1177 interaction_sequences = torch.cat([obs_part, ego_current_state_expanded, pred_part], dim=1) # Shape: (B, T+1, N, D)1180 sequences_reshaped = rearrange(interaction_sequences, 'b t n d -> (b n) t d')1181 processed_sequences = self.pairwise_mamba_encoder(sequences_reshaped)1185 fused_tokens = processed_sequences[:, -1, :]1186 interaction_results = rearrange(fused_tokens, '(b n) d -> b n d', b=B, n=N)1189 ego_result_query = interaction_results[:, 0:1, :]1195 final_ego_context = self.fusion_norm(ego_result_query + fused_context)1200 output[:, -1, 0, :] = final_ego_context.squeeze(1)
输入为 (B,T,N,D),主体 0 是 ego。obs_len 指观测长度,后续位置是宿主已有预测特征,不应传入未来真实监督值。
from SocialMambaEgoInteraction import EgoCentricPairwiseInteractionBlock_UMamba2 model = EgoCentricPairwiseInteractionBlock_UMamba2(8, 1, d_state=3, d_conv=3, dropout=0.0) output = model(agent_features, obs_len=4)
Method 动机参考:用共享 ego 当前状态将成对轨迹联系起来,再以主体级注意力聚合与 ego 相关的交互上下文。
| 消融变体 | 结构配置 | 验证目的 |
|---|---|---|
| 无状态插入 | 直接编码原主体序列 | 比较 ego 当前态影响 |
| 主体均值 | 用均值代替 fusion_attention | 比较主体相关性聚合 |
| 编码层数 | num_layers=1 / 2 | 比较交互建模与开销;待运行对照 |