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
| """ mmWave雷达手势识别:双流LSTM + Attention-BiGRU 论文: Electronics (MDPI), 2026, 15(17), 3973
核心: 双流架构 - Stream 1: 距离-多普勒图序列 → LSTM (时序特征) - Stream 2: 角度-速度序列 → Attention BiGRU (空间特征) - 融合: 双流特征拼接 → 分类
硬件: 60GHz mmWave雷达 (如TI IWR6843) 依赖: torch>=2.0, numpy """
import torch import torch.nn as nn import torch.nn.functional as F from typing import Tuple
class DualStreamLSTMBiGRU(nn.Module): """ 双流手势识别网络 Stream 1: Range-Doppler → LSTM (时序特征) Stream 2: Angle-Velocity → Attention BiGRU (空间特征) 输入: - range_doppler: (B, T, num_range_bins, num_doppler_bins) - angle_velocity: (B, T, num_angle_bins, num_velocity_bins) 输出: 手势类别概率 """ def __init__(self, num_gestures: int = 8, rd_shape: tuple = (64, 16), av_shape: tuple = (32, 8), hidden_dim: int = 128, num_layers: int = 2): super().__init__() self.rd_encoder = nn.Sequential( nn.Linear(rd_shape[0] * rd_shape[1], 64), nn.ReLU(), nn.Dropout(0.3) ) self.rd_lstm = nn.LSTM( input_size=64, hidden_size=hidden_dim, num_layers=num_layers, batch_first=True, bidirectional=True, dropout=0.3 ) self.av_encoder = nn.Sequential( nn.Linear(av_shape[0] * av_shape[1], 64), nn.ReLU(), nn.Dropout(0.3) ) self.av_gru = nn.GRU( input_size=64, hidden_size=hidden_dim, num_layers=num_layers, batch_first=True, bidirectional=True, dropout=0.3 ) self.attention = nn.Sequential( nn.Linear(hidden_dim * 2, hidden_dim), nn.Tanh(), nn.Linear(hidden_dim, 1), nn.Softmax(dim=1) ) self.classifier = nn.Sequential( nn.Linear(hidden_dim * 4, 128), nn.ReLU(), nn.Dropout(0.4), nn.Linear(128, 64), nn.ReLU(), nn.Linear(64, num_gestures) ) def forward(self, rd_seq: torch.Tensor, av_seq: torch.Tensor) -> torch.Tensor: """ Args: rd_seq: (B, T, R, D) Range-Doppler序列 av_seq: (B, T, A, V) Angle-Velocity序列 Returns: logits: (B, num_gestures) """ B, T, R, D = rd_seq.shape A, V = av_seq.shape[2], av_seq.shape[3] rd_flat = rd_seq.view(B, T, R * D) rd_feat = self.rd_encoder(rd_flat) rd_out, _ = self.rd_lstm(rd_feat) rd_summary = rd_out[:, -1, :] av_flat = av_seq.view(B, T, A * V) av_feat = self.av_encoder(av_flat) av_out, _ = self.av_gru(av_feat) attn_weights = self.attention(av_out) av_summary = torch.sum(av_out * attn_weights, dim=1) fused = torch.cat([rd_summary, av_summary], dim=1) return self.classifier(fused)
CABIN_GESTURES = { 0: "左挥手 (Vol Down)", 1: "右挥手 (Vol Up)", 2: "上挥手 (Sunroof Open)", 3: "下挥手 (Sunroof Close)", 4: "顺时针旋转 (Temp Up)", 5: "逆时针旋转 (Temp Down)", 6: "前推 (Accept Call)", 7: "后拉 (Reject Call)", }
class RadarGesturePipeline: """ mmWave雷达手势识别完整流程 硬件: TI IWR6843 (60GHz, 4Tx4Rx) 采样: 30fps, 64 range bins, 16 doppler bins """ def __init__(self): self.model = DualStreamLSTMBiGRU(num_gestures=8) self.gesture_buffer = [] self.confirmation_frames = 3 def process_radar_frame(self, raw_data: np.ndarray) -> dict: """ 处理单帧雷达数据 Args: raw_data: 原始ADC数据 Returns: 手势识别结果 """ range_doppler = self._compute_rd_map(raw_data) angle_velocity = self._compute_av_map(raw_data) self.gesture_buffer.append((range_doppler, angle_velocity)) if len(self.gesture_buffer) > 30: self.gesture_buffer.pop(0) if len(self.gesture_buffer) < 15: return {'gesture': None, 'confidence': 0} rd_seq = torch.FloatTensor( np.stack([f[0] for f in self.gesture_buffer[-15:]]) ).unsqueeze(0) av_seq = torch.FloatTensor( np.stack([f[1] for f in self.gesture_buffer[-15:]]) ).unsqueeze(0) with torch.no_grad(): logits = self.model(rd_seq, av_seq) probs = F.softmax(logits, dim=1) pred = probs.argmax(1).item() conf = probs[0, pred].item() if conf > 0.7: return { 'gesture': CABIN_GESTURES[pred], 'gesture_id': pred, 'confidence': conf } return {'gesture': None, 'confidence': conf}
|