低光照驾驶员睡意检测:双注意力机制+XAI可解释深度学习——隧道/夜间实时安全保障

论文信息

项目 内容
标题 Low-light driver drowsiness detection for real-time safety assistance using dual attention mechanisms in deep learning model
期刊 Scientific Reports (Nature)
发表 2026年4月20日
链接 https://www.nature.com/articles/s41598-026-44442-3
核心方法 双注意力CNN + Grad-CAM可解释AI
场景 低光照/夜间/隧道

核心创新

  1. 双注意力机制:空间注意力+通道注意力联合,低光照下聚焦关键面部区域
  2. Grad-CAM可解释性:热力图显示模型关注区域,满足ISO 26262要求
  3. 低光照专用:针对夜间/隧道光照不足场景优化
  4. 实时部署:轻量CNN满足边缘推理需求

方法详解

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
import torch
import torch.nn as nn
import numpy as np
from dataclasses import dataclass

class ChannelAttention(nn.Module):
"""通道注意力:聚焦重要特征通道"""

def __init__(self, in_channels: int, reduction: int = 16):
super().__init__()
self.avg_pool = nn.AdaptiveAvgPool2d(1)
self.max_pool = nn.AdaptiveMaxPool2d(1)

self.fc = nn.Sequential(
nn.Conv2d(in_channels, in_channels // reduction, 1),
nn.ReLU(),
nn.Conv2d(in_channels // reduction, in_channels, 1)
)

def forward(self, x):
avg_out = self.fc(self.avg_pool(x))
max_out = self.fc(self.max_pool(x))
return torch.sigmoid(avg_out + max_out)

class SpatialAttention(nn.Module):
"""空间注意力:聚焦关键面部区域"""

def __init__(self, kernel_size: int = 7):
super().__init__()
self.conv = nn.Conv2d(2, 1, kernel_size, padding=kernel_size//2)

def forward(self, x):
avg_out = torch.mean(x, dim=1, keepdim=True)
max_out, _ = torch.max(x, dim=1, keepdim=True)
cat = torch.cat([avg_out, max_out], dim=1)
return torch.sigmoid(self.conv(cat))

class DualAttentionBlock(nn.Module):
"""双注意力块:通道+空间"""

def __init__(self, in_channels: int):
super().__init__()
self.ca = ChannelAttention(in_channels)
self.sa = SpatialAttention()

def forward(self, x):
x = x * self.ca(x) # 通道注意力
x = x * self.sa(x) # 空间注意力
return x

class LowLightDrowsinessModel(nn.Module):
"""
低光照睡意检测模型

架构:
1. 低光照增强预处理
2. CNN骨干+双注意力
3. 分类+Grad-CAM解释
"""

def __init__(self, n_classes: int = 3):
super().__init__()

# 低光照增强
self.enhance = nn.Sequential(
nn.Conv2d(3, 3, 3, padding=1),
nn.BatchNorm2d(3),
nn.ReLU(),
nn.Conv2d(3, 3, 3, padding=1),
nn.Sigmoid(), # 光照增强
)

# CNN骨干
self.backbone = nn.Sequential(
nn.Conv2d(3, 32, 3, stride=2, padding=1),
nn.BatchNorm2d(32),
nn.ReLU6(),
DualAttentionBlock(32),
nn.Conv2d(32, 64, 3, stride=2, padding=1),
nn.BatchNorm2d(64),
nn.ReLU6(),
DualAttentionBlock(64),
nn.Conv2d(64, 128, 3, stride=2, padding=1),
nn.BatchNorm2d(128),
nn.ReLU6(),
DualAttentionBlock(128),
nn.AdaptiveAvgPool2d(1),
nn.Flatten(),
)

self.classifier = nn.Sequential(
nn.Linear(128, 64),
nn.ReLU(),
nn.Dropout(0.2),
nn.Linear(64, n_classes)
)

# 保存中间特征用于Grad-CAM
self.features = None

def forward(self, x):
enhanced = self.enhance(x)
feat = self.backbone(enhanced)
self.features = feat
return self.classifier(feat)

def grad_cam(self, x, target_class=None):
"""Grad-CAM可解释性分析"""
x.requires_grad_(True)
output = self.forward(x)

if target_class is None:
target_class = output.argmax(dim=1)

# 梯度回传
self.zero_grad()
target = output[0, target_class]
target.backward()

# 获取最后一个卷积层梯度
gradients = x.grad

# 生成热力图(简化)
heatmap = gradients.abs().mean(dim=1, keepdim=True)
heatmap = (heatmap - heatmap.min()) / (heatmap.max() - heatmap.min() + 1e-8)

return output, heatmap


# 测试
if __name__ == "__main__":
model = LowLightDrowsinessModel(n_classes=3)

# 正常光照
normal = torch.randn(1, 3, 96, 96)

# 低光照(暗度模拟)
low_light = torch.randn(1, 3, 96, 96) * 0.3 + 0.1

# 推理
out_normal = model(normal)
out_low = model(low_light)

print("=== 低光照睡意检测 ===")
print(f"正常光照输出: {out_normal[0]}")
print(f"低光照输出: {out_low[0]}")

# Grad-CAM
x = torch.randn(1, 3, 96, 96)
output, heatmap = model.grad_cam(x)
print(f"\nGrad-CAM热力图: {heatmap.shape}")
print(f"注意力区域均值: {heatmap.mean():.4f}")

params = sum(p.numel() for p in model.parameters())
print(f"\n总参数: {params:,}")

实验结果

光照条件对比

光照 传统CNN 双注意力 提升
白天(500lux) 94.2% 95.8% +1.6%
黄昏(50lux) 82.5% 91.3% +8.8%
夜间IR(10lux) 75.3% 89.7% +14.4%
隧道(5lux) 68.2% 86.5% +18.3%
极暗(<1lux) 52.1% 78.3% +26.2%

Grad-CAM可解释性

状态 模型关注区域 可解释性评分
清醒 眼睛+嘴部 0.92
疲劳 眼睑区域 0.88
睡意 眼睑+头部姿态 0.85

IMS开发启示

1. 低光照增强对IMS的价值

场景 问题 本论文方案
夜间驾驶 光照不足 光照增强+双注意力
隧道进出 突变光照 鲁棒特征提取
树荫间歇 斑驳光影 通道注意力过滤
驾驶室阴影 面部暗区 空间注意力聚焦

2. XAI满足ISO 26262

要求 本论文方案
模型透明 Grad-CAM热力图
决策可追溯 关注区域可视化
诊断覆盖 识别失败模式

3. 与已有管道集成

组件 来源 角色
低光照增强 本论文 预处理
双注意力 本论文 特征提取
自适应窗口 #13 时间窗口管理
疲劳干预 #15 LLM 干预策略
Grad-CAM 本论文 可解释性

总结

  1. 低光照+18.3%提升:隧道场景从68.2%提升至86.5%
  2. 双注意力:通道+空间联合,暗光下聚焦眼/嘴关键区域
  3. Grad-CAM可解释:满足ISO 26262功能安全要求
  4. 实时部署:轻量CNN+增强预处理,边缘友好
  5. 与LLM干预闭环:低光照检测→LLM对话干预→效果评估

https://dapalm.com/2026/09/22/2026-09-22-16-low-light-dual-attention-xai-drowsiness-ims/
作者
Mars
发布于
2026年9月22日
许可协议