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
| import numpy as np import json from pathlib import Path
class DMSSyntheticPipeline: """ DMS合成数据生成与验证完整管道 Pipeline: 1. 场景定义 (NCAP场景模板) 2. 参数随机化 (Domain Randomization) 3. 渲染生成 (Omniverse Replicator) 4. 自动标注 (语义/关键点/包围盒) 5. 数据增强 (混合真实数据) 6. 模型训练与验证 """ SCENE_TEMPLATES = { 'D-01_phone_use': { 'description': '驾驶员手持手机', 'fatigue': False, 'distraction': True, 'required_objects': ['phone'], 'gaze_target': 'phone_screen', 'ncap_category': 'distraction' }, 'F-01_perclos': { 'description': 'PERCLOS ≥ 30%', 'fatigue': True, 'distraction': False, 'eye_openness': (0.0, 0.3), 'duration_sec': 5, 'ncap_category': 'fatigue' }, 'CPD-01_child_alone': { 'description': '婴儿独自留在车内', 'fatigue': False, 'person_type': 'infant', 'covered': True, 'ncap_category': 'cpd' }, 'OOP-01_forward_lean': { 'description': '驾驶员前倾(捡东西)', 'posture': 'forward_lean', 'lean_angle': (20, 45), 'ncap_category': 'oop' } } def generate_dataset( self, output_path: str, total_samples: int = 50000, scene_distribution: dict = None ) -> dict: """ 生成完整合成数据集 Args: output_path: 输出路径 total_samples: 总样本数 scene_distribution: 场景分布(比例) Returns: manifest: 数据集清单 """ if scene_distribution is None: scene_distribution = { 'D-01_phone_use': 0.15, 'D-05_gaze_away': 0.15, 'F-01_perclos': 0.10, 'F-04_microsleep': 0.10, 'CPD-01_child_alone': 0.15, 'OOP-01_forward_lean': 0.10, 'normal_driving': 0.25, } manifest = { 'total_samples': total_samples, 'scenes': {}, 'statistics': {} } for scene_name, ratio in scene_distribution.items(): n_samples = int(total_samples * ratio) manifest['scenes'][scene_name] = { 'count': n_samples, 'template': self.SCENE_TEMPLATES.get(scene_name, {}), 'output_dir': f"{output_path}/{scene_name}/" } manifest['statistics'] = { 'annotators': [ 'rgb', 'depth', 'semantic_seg', 'bbox_2d', 'bbox_3d', 'keypoints_2d', 'keypoints_3d', 'occlusion_mask', 'gaze_direction' ], 'image_resolution': '1920x1080', 'frame_rate': 30, 'diversity': { 'persons': 500, 'lighting': 20, 'vehicles': 10, 'cameras': 5, } } Path(output_path).mkdir(parents=True, exist_ok=True) with open(f"{output_path}/manifest.json", 'w') as f: json.dump(manifest, f, indent=2) return manifest
if __name__ == "__main__": pipeline = DMSSyntheticPipeline() manifest = pipeline.generate_dataset( output_path="/data/dms_synthetic_v2", total_samples=50000 ) print(f"总样本: {manifest['total_samples']}") print("场景分布:") for scene, info in manifest['scenes'].items(): print(f" {scene}: {info['count']} 张")
|