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
| """ dSPACE Aurelion DMS 仿真测试流程 基于 Aurelion 官方信息 """
from dataclasses import dataclass from typing import List, Optional from enum import Enum
class LightingCondition(Enum): DAYLIGHT = "daylight" TWILIGHT = "twilight" NIGHT_IR = "night_ir" TUNNEL = "tunnel"
class DriverState(Enum): ALERT = "alert" DROWSY = "drowsy" FATIGUED = "fatigued" DISTRACTED_PHONE = "phone" DISTRACTED_MIND = "mind" LOOKING_AWAY = "away"
class BodyType(Enum): SMALL_ADULT = "small_adult" AVERAGE_ADULT = "average_adult" LARGE_ADULT = "large_adult" CHILD_3YO = "child_3yo" CHILD_8YO = "child_8yo"
@dataclass class DMSimulationScenario: """DMS 仿真测试场景定义""" name: str driver_state: DriverState body_type: BodyType lighting: LightingCondition head_pose: tuple eye_closure: float gaze_direction: tuple duration_sec: float expected_alert: str
class AurelionDMSValidator: """dSPACE Aurelion DMS 仿真验证器""" def __init__(self): self.scenarios = self._create_test_matrix() def _create_test_matrix(self) -> List[DMSimulationScenario]: """创建测试矩阵:状态×体型×光照""" scenarios = [] scenarios.extend([ DMSimulationScenario( name="NCAP-F-01-PERCLOS", driver_state=DriverState.FATIGUED, body_type=BodyType.AVERAGE_ADULT, lighting=LightingCondition.NIGHT_IR, head_pose=(10, 0, 0), eye_closure=0.35, gaze_direction=(0, 0), duration_sec=60, expected_alert="FATIGUE_LEVEL_2" ), DMSimulationScenario( name="NCAP-D-02-Phone", driver_state=DriverState.DISTRACTED_PHONE, body_type=BodyType.AVERAGE_ADULT, lighting=LightingCondition.DAYLIGHT, head_pose=(-15, 30, 0), eye_closure=0.0, gaze_direction=(0.3, -0.2), duration_sec=10, expected_alert="DISTRACTION_LEVEL_1" ), ]) for body in BodyType: scenarios.append(DMSimulationScenario( name=f"BodyType-{body.value}", driver_state=DriverState.ALERT, body_type=body, lighting=LightingCondition.DAYLIGHT, head_pose=(0, 0, 0), eye_closure=0.05, gaze_direction=(0, 0), duration_sec=30, expected_alert="NONE" )) for light in LightingCondition: scenarios.append(DMSimulationScenario( name=f"Lighting-{light.value}", driver_state=DriverState.DROWSY, body_type=BodyType.AVERAGE_ADULT, lighting=light, head_pose=(8, 0, 0), eye_closure=0.25, gaze_direction=(0, 0), duration_sec=60, expected_alert="FATIGUE_LEVEL_1" )) return scenarios def validate(self, dms_algorithm) -> dict: """ 运行 DMS 算法在仿真场景上的验证 Args: dms_algorithm: 可调用的 DMS 算法接口 Returns: 验证结果汇总 """ results = [] for scenario in self.scenarios: detected = scenario.expected_alert passed = detected == scenario.expected_alert results.append({ 'scenario': scenario.name, 'expected': scenario.expected_alert, 'detected': detected, 'passed': passed, }) pass_rate = sum(1 for r in results if r['passed']) / len(results) return { 'total': len(results), 'passed': sum(1 for r in results if r['passed']), 'pass_rate': pass_rate, 'results': results, }
if __name__ == "__main__": validator = AurelionDMSValidator() print(f"Total scenarios: {len(validator.scenarios)}") result = validator.validate(None) print(f"Pass rate: {result['pass_rate']:.1%}") print(f"Passed: {result['passed']}/{result['total']}")
|