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
| """ ISU-Test 搜索式测试方法
核心思想: 将 VLM 测试建模为优化问题,系统修改场景参数生成多样场景 """
import numpy as np from typing import List, Dict, Tuple from dataclasses import dataclass
@dataclass class SceneParameters: """座舱场景参数""" driver_posture: str head_pose: Tuple[float, float, float] eye_gaze: Tuple[float, float] illumination: float time_of_day: str weather: str phone_present: bool phone_position: Tuple[float, float] seatbelt_status: str
def generate_diverse_scenes( base_params: SceneParameters, num_scenes: int = 100 ) -> List[SceneParameters]: """ 生成多样座舱场景 Args: base_params: 基线场景参数 num_scenes: 生成场景数 Returns: scenes: 多样场景列表 ISU-Test 方法: 系统修改场景参数,覆盖多样化配置 """ scenes = [] for _ in range(num_scenes): new_scene = SceneParameters( driver_posture=base_params.driver_posture, head_pose=base_params.head_pose, eye_gaze=base_params.eye_gaze, illumination=base_params.illumination, time_of_day=base_params.time_of_day, weather=base_params.weather, phone_present=base_params.phone_present, phone_position=base_params.phone_position, seatbelt_status=base_params.seatbelt_status ) if np.random.rand() > 0.5: new_scene.driver_posture = np.random.choice( ['normal', 'forward', 'side'] ) if np.random.rand() > 0.5: new_scene.head_pose = ( np.random.uniform(-30, 30), np.random.uniform(-45, 45), np.random.uniform(-20, 20) ) if np.random.rand() > 0.5: new_scene.illumination = np.random.uniform(0.1, 1.0) if np.random.rand() > 0.5: new_scene.time_of_day = np.random.choice(['day', 'night']) if np.random.rand() > 0.5: new_scene.phone_present = not new_scene.phone_present if np.random.rand() > 0.5: new_scene.seatbelt_status = np.random.choice( ['normal', 'lap_only', 'unbuckled'] ) scenes.append(new_scene) return scenes
def evaluate_vlm_on_scenes( vlm_model, scenes: List[SceneParameters], task: str = 'question_answering' ) -> Dict: """ 在多样场景上评估 VLM Args: vlm_model: VLM 模型 scenes: 场景列表 task: 任务类型(question_answering/captioning) Returns: evaluation: 评估结果 ISU-Test 方法: 比较 VLM 在多样场景上的表现 """ correct = 0 total = len(scenes) for scene in scenes: pass accuracy = correct / total if total > 0 else 0 return { 'accuracy': accuracy, 'total_scenes': total, 'correct': correct }
if __name__ == "__main__": base_params = SceneParameters( driver_posture='normal', head_pose=(0, 0, 0), eye_gaze=(0, 0), illumination=0.8, time_of_day='day', weather='clear', phone_present=False, phone_position=(0, 0), seatbelt_status='normal' ) scenes = generate_diverse_scenes(base_params, num_scenes=100) print("="*60) print("ISU-Test 座舱场景生成测试") print("="*60) print(f"生成场景数: {len(scenes)}") postures = [s.driver_posture for s in scenes] print(f"姿态分布: {dict((p, postures.count(p)) for p in set(postures))}") seatbelts = [s.seatbelt_status for s in scenes] print(f"安全带分布: {dict((s, seatbelts.count(s)) for s in set(seatbelts))}")
|