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 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
| import numpy as np from typing import List, Dict
class IsaacSimSDG: """ Isaac Sim合成数据生成管道 用于IMS/DMS/OMS数据生成 """ def __init__(self, output_dir: str = "/data/synthetic", num_scenarios: int = 1000): """ 初始化 Args: output_dir: 输出目录 num_scenarios: 场景数量 """ self.output_dir = output_dir self.num_scenarios = num_scenarios self.replicator = ReplicatorConfig() def generate_dms_dataset(self): """ 生成DMS数据集 """ for i in range(self.num_scenarios): scenario = self.randomize_scenario() driver = self.generate_driver(scenario) behavior = self.inject_behavior(driver) sensor_data = self.capture_sensors(scenario, driver) annotations = self.auto_annotate(driver, behavior) self.save_data(i, sensor_data, annotations) def randomize_scenario(self) -> dict: """ 场景随机化 Returns: scenario: 场景参数 """ lighting = { 'intensity': np.random.uniform(0.3, 1.0), 'color_temp': np.random.randint(3000, 7000), 'direction': np.random.randn(3), 'ambient': np.random.uniform(0.1, 0.3) } cabin = { 'temperature': np.random.randint(15, 35), 'materials': np.random.choice(['leather', 'fabric', 'plastic']), 'seat_position': np.random.uniform(-0.1, 0.1, 3) } external = { 'time_of_day': np.random.randint(6, 21), 'weather': np.random.choice(['sunny', 'cloudy', 'rainy']), 'road_type': np.random.choice(['highway', 'urban', 'rural']) } return { 'lighting': lighting, 'cabin': cabin, 'external': external } def generate_driver(self, scenario: dict) -> dict: """ 生成驾驶员模型 Args: scenario: 场景参数 Returns: driver: 驾驶员模型 """ body = { 'gender': np.random.choice(['male', 'female']), 'age': np.random.randint(18, 70), 'height': np.random.normal(170, 10), 'weight': np.random.normal(70, 15), 'skin_tone': np.random.randint(1, 10), 'hair_style': np.random.choice(['short', 'medium', 'long', 'bald']), 'glasses': np.random.choice([True, False], p=[0.3, 0.7]) } accessories = { 'hat': np.random.choice([True, False], p=[0.1, 0.9]), 'mask': np.random.choice([True, False], p=[0.05, 0.95]), 'sunglasses': np.random.choice([True, False], p=[0.1, 0.9]) } pose = { 'head_pose': np.random.randn(6), 'gaze_direction': np.random.randn(3), 'eye_openness': np.random.uniform(0.5, 1.0, 2), 'mouth_openness': np.random.uniform(0, 0.5) } return { 'body': body, 'accessories': accessories, 'pose': pose } def inject_behavior(self, driver: dict) -> dict: """ 注入分心/疲劳行为 Args: driver: 驾驶员模型 Returns: behavior: 行为参数 """ behavior_type = np.random.choice([ 'normal', 'phone_call', 'texting', 'eating', 'drowsy', 'yawning', 'talking', 'looking_away', 'adjusting_radio', 'reaching' ], p=[0.3, 0.15, 0.15, 0.1, 0.1, 0.05, 0.05, 0.05, 0.05, 0.05]) behavior_params = { 'type': behavior_type, 'duration': np.random.uniform(2, 10), 'intensity': np.random.uniform(0.5, 1.0), 'start_frame': np.random.randint(0, 100) } if behavior_type in ['phone_call', 'texting']: behavior_params['hand'] = np.random.choice(['left', 'right']) behavior_params['phone_position'] = np.random.randn(3) * 0.1 elif behavior_type == 'drowsy': behavior_params['perclos_threshold'] = np.random.uniform(0.2, 0.5) behavior_params['blink_rate'] = np.random.uniform(10, 30) elif behavior_type == 'looking_away': behavior_params['gaze_offset'] = np.random.uniform(30, 60) behavior_params['direction'] = np.random.choice(['left', 'right', 'up', 'down']) return behavior_params def capture_sensors(self, scenario: dict, driver: dict) -> dict: """ 传感器数据采集 Args: scenario: 场景参数 driver: 驾驶员模型 Returns: sensor_data: 传感器数据 """ rgb_image = self.render_rgb(scenario, driver) depth_image = self.render_depth(scenario, driver) ir_image = self.render_ir(scenario, driver) eye_tracking = self.simulate_eye_tracking(driver) return { 'rgb': rgb_image, 'depth': depth_image, 'ir': ir_image, 'eye_tracking': eye_tracking } def auto_annotate(self, driver: dict, behavior: dict) -> dict: """ 自动标注 零成本,精确标注 Returns: annotations: 标注数据 """ facial_landmarks = self.get_facial_landmarks(driver) eye_landmarks = self.get_eye_landmarks(driver) gaze_vector = driver['pose']['gaze_direction'] head_pose = driver['pose']['head_pose'] behavior_label = behavior['type'] perclos = self.calculate_perclos(driver, behavior) return { 'facial_landmarks': facial_landmarks, 'eye_landmarks': eye_landmarks, 'gaze_vector': gaze_vector, 'head_pose': head_pose, 'behavior_label': behavior_label, 'perclos': perclos, 'timestamp': np.random.uniform(0, 10) } def calculate_perclos(self, driver: dict, behavior: dict) -> float: """ 计算PERCLOS值 """ if behavior['type'] == 'drowsy': return behavior['perclos_threshold'] * np.random.uniform(0.8, 1.2) else: return np.random.uniform(0.05, 0.15)
class ReplicatorConfig: """Omniverse Replicator配置""" pass
|