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
| """ Driver-Intention Prediction CNN 论文: arXiv 2601.05084 (2026年1月)
核心方法: 1. 64通道原始EEG(512Hz采样) 2. 无传统预处理(无滤波/无ICA/无特征提取) 3. CNN直接从时域EEG学习 4. 3类分类:左转/右转/直行
关键发现: - 83.7%准确率(3类) - 右转分类最准确(空间偏侧效应) - CNN能从噪声EEG中提取有效特征 - 深度学习优于传统频谱特征方法 """
import torch import torch.nn as nn import numpy as np from typing import Tuple
class EEGDriverIntentionCNN(nn.Module): """ 驾驶员意图预测 CNN 论文架构复现: - 输入:64通道 × T时间步原始EEG - 网络结构:Conv1D → Conv1D → Pool → FC → Softmax - 输出:3类(左转/右转/直行) 关键设计决策(来自论文): 1. 不使用传统EEG预处理(滤波/ICA) 2. CNN直接学习时域模式 3. 原始信号→深度学习端到端 4. 64通道全保留(不选通道) """ def __init__(self, num_channels: int = 64, num_classes: int = 3, sampling_rate: int = 512, segment_sec: float = 2.0): super().__init__() self.num_channels = num_channels self.segment_samples = int(sampling_rate * segment_sec) self.conv1 = nn.Conv1d( in_channels=num_channels, out_channels=32, kernel_size=64, stride=4, padding=30 ) self.bn1 = nn.BatchNorm1d(32) self.relu1 = nn.ReLU() self.pool1 = nn.MaxPool1d(kernel_size=4, stride=4) self.conv2 = nn.Conv1d(32, 64, kernel_size=16, stride=2, padding=7) self.bn2 = nn.BatchNorm1d(64) self.relu2 = nn.ReLU() self.pool2 = nn.MaxPool1d(kernel_size=4, stride=4) self.conv3 = nn.Conv1d(64, 128, kernel_size=8, stride=1, padding=3) self.bn3 = nn.BatchNorm1d(128) self.relu3 = nn.ReLU() self.pool3 = nn.AdaptiveAvgPool1d(1) self.fc1 = nn.Linear(128, 64) self.relu4 = nn.ReLU() self.dropout = nn.Dropout(0.5) self.fc2 = nn.Linear(64, num_classes) def forward(self, x): """ Args: x: (B, 64, T) 原始EEG信号 Returns: logits: (B, 3) 类别logits """ x = self.pool1(self.relu1(self.bn1(self.conv1(x)))) x = self.pool2(self.relu2(self.bn2(self.conv2(x)))) x = self.pool3(self.relu3(self.bn3(self.conv3(x)))) x = x.view(x.size(0), -1) x = self.dropout(self.relu4(self.fc1(x))) x = self.fc2(x) return x def predict_intention(self, eeg_segment: np.ndarray) -> dict: """ 实时意图预测 Args: eeg_segment: (64, T) EEG段 Returns: prediction: 意图分类+置信度 """ x = torch.FloatTensor(eeg_segment).unsqueeze(0) with torch.no_grad(): logits = self.forward(x) probs = torch.softmax(logits, dim=1) predicted = torch.argmax(probs, dim=1).item() confidence = probs[0, predicted].item() intentions = ['left_turn', 'right_turn', 'straight'] return { 'intention': intentions[predicted], 'confidence': confidence, 'all_probs': { intentions[i]: probs[0, i].item() for i in range(len(intentions)) }, }
if __name__ == "__main__": np.random.seed(42) model = EEGDriverIntentionCNN( num_channels=64, num_classes=3, sampling_rate=512, segment_sec=2.0 ) eeg_segment = np.random.randn(64, 1024) * 10 prediction = model.predict_intention(eeg_segment) print(f"=== EEG 驾驶意图预测 ===") print(f"输入: 64通道 × 1024样本 (2秒@512Hz)") print(f"预测意图: {prediction['intention']}") print(f"置信度: {prediction['confidence']:.3f}") print(f"各类概率:") for intent, prob in prediction['all_probs'].items(): print(f" {intent}: {prob:.3f}") print(f"\n=== 论文报告性能 ===") print(f"总准确率: 83.7% (3类分类)") print(f"右转准确率: 最高 (空间偏侧效应)") print(f"左转准确率: 中等") print(f"直行准确率: 最低 (基线状态难区分)") print(f"被试: 10名 (1男9女, 22-44岁)") print(f"EEG: 64通道 gel cap, 512Hz") print(f"预处理: 极少 (CNN端到端)") total_params = sum(p.numel() for p in model.parameters()) print(f"\n模型参数量: {total_params:,}") print(f"模型大小: ~{total_params * 4 / 1024 / 1024:.1f} MB (float32)")
|