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
| """ NVIDIA Cosmos 3 座舱场景生成管道
依赖: Cosmos 3 API (GTC 2025后开放) 用途: 生成DMS/OMS训练数据
核心思路: 1. 定义场景提示词模板 2. Cosmos生成场景变体 3. Isaac Sim验证+标注 4. 输出训练数据 """
from dataclasses import dataclass from typing import List, Dict, Optional import json
@dataclass class CosmosPrompt: """Cosmos场景生成提示词""" driver_state: str fatigue_level: str = "" distraction_type: str = "" body_type: str = "medium_male" age_group: str = "adult" lighting: str = "day_clear" weather: str = "clear" camera_type: str = "dms_standard" camera_angle: str = "front" def to_prompt(self) -> str: """生成文本提示词""" parts = [ f"interior view of a car cabin from {self.camera_type} camera", f"driver in {self.driver_state} state", ] if self.fatigue_level: parts.append(f"fatigue level: {self.fatigue_level}") if self.distraction_type: parts.append(f"distraction: {self.distraction_type}") parts.append(f"driver body type: {self.body_type}") parts.append(f"age: {self.age_group}") parts.append(f"lighting: {self.lighting}") parts.append(f"weather outside: {self.weather}") return ", ".join(parts)
class CosmosCabinDataPipeline: """ Cosmos 3 + Isaac Sim 融合数据生成管道 """ def __init__(self): self.prompt_templates = self._init_templates() def _init_templates(self) -> List[CosmosPrompt]: """初始化场景模板""" templates = [] for body in ['small_female', 'medium_male', 'large_male']: for level in ['mild', 'moderate', 'severe']: for light in ['day_clear', 'night_urban', 'tunnel', 'sunset']: templates.append(CosmosPrompt( driver_state='fatigue', fatigue_level=level, body_type=body, lighting=light, )) for body in ['small_female', 'medium_male', 'large_male']: for dist in ['phone_texting', 'phone_ear', 'reach_passenger', 'turn_back']: for light in ['day_clear', 'night_urban']: templates.append(CosmosPrompt( driver_state='distracted', distraction_type=dist, body_type=body, lighting=light, )) for body in ['small_female', 'medium_male', 'large_male', 'child']: for oop in ['forward_bent', 'side_leaning', 'feet_up', 'head_on_wheel']: templates.append(CosmosPrompt( driver_state='oop', body_type=body, lighting='day_clear', )) return templates def generate_dataset_spec(self) -> Dict: """生成数据集规格""" n_templates = len(self.prompt_templates) variants_per_template = 10 frames_per_variant = 300 total_images = n_templates * variants_per_template * frames_per_variant return { 'total_templates': n_templates, 'variants_per_template': variants_per_template, 'frames_per_variant': frames_per_variant, 'total_images': total_images, 'estimated_size_gb': total_images * 2 / 1024, 'generation_time_hours': total_images / (1000 * 3600), 'cost_estimate_usd': total_images / (1000 * 3600) * 3, } def to_isaac_sim_config(self, cosmos_output: Dict) -> Dict: """将Cosmos输出转换为Isaac Sim验证配置""" return { 'scene_type': cosmos_output.get('driver_state', 'normal'), 'body_type': cosmos_output.get('body_type', 'medium_male'), 'lighting': cosmos_output.get('lighting', 'day_clear'), 'camera_config': 'dms_standard', 'validation_checks': [ 'face_visible', 'eyes_detectable', 'posture_correct', 'lighting_adequate', 'no_artifacts', ], 'auto_label': True, 'label_classes': [ 'face', 'eyes', 'mouth', 'hands', 'steering_wheel', 'phone', 'seatbelt', ], }
if __name__ == "__main__": pipeline = CosmosCabinDataPipeline() spec = pipeline.generate_dataset_spec() print("=== Cosmos + Isaac 数据生成规格 ===") for k, v in spec.items(): if isinstance(v, float): print(f" {k}: {v:.1f}") else: print(f" {k}: {v}") print(f"\n=== 前5个场景提示词 ===") for i, t in enumerate(pipeline.prompt_templates[:5]): print(f" [{i}] {t.to_prompt()}") example_output = { 'driver_state': 'fatigue', 'body_type': 'medium_male', 'lighting': 'night_urban', } isaac_config = pipeline.to_isaac_sim_config(example_output) print(f"\n=== Isaac Sim验证配置 ===") print(json.dumps(isaac_config, indent=2))
|