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
| class DomainRandomization: """ 域随机化:增强数据多样性 随机化维度: 1. 光照(强度/颜色/位置) 2. 材质(反射率/粗糙度) 3. 姿态(乘员坐姿) 4. 遮挡(手部/物体) """ def randomize_lighting(self): """ 光照随机化 模拟: - 白天/夜晚/黄昏 - 阴天/晴天 - 进入隧道/树荫 """ import random sun_intensity = random.uniform(100, 1000) sun_angle = random.uniform(0, 90) ambient_color = ( random.uniform(0.8, 1.0), random.uniform(0.8, 1.0), random.uniform(0.8, 1.0) ) return { 'sun_intensity': sun_intensity, 'sun_angle': sun_angle, 'ambient_color': ambient_color } def randomize_occupant_pose(self): """ 乘员姿态随机化 变化: - 头部俯仰角:-20°~20° - 身体倾斜:-15°~15° - 手臂位置:多种遮挡 """ import random pose = { 'head_pitch': random.uniform(-20, 20), 'head_yaw': random.uniform(-30, 30), 'head_roll': random.uniform(-10, 10), 'body_slouch': random.uniform(0, 15), 'arm_position': random.choice(['normal', 'crossed', 'on_wheel', 'phone']) } return pose def randomize_occlusion(self): """ 遮挡随机化 场景: - 手持手机 - 戴墨镜 - 戴口罩 - 遮挡部分面部 """ occlusions = [ {'type': 'sunglasses', 'coverage': 0.3}, {'type': 'mask', 'coverage': 0.5}, {'type': 'hand_near_face', 'coverage': 0.2}, {'type': 'none', 'coverage': 0.0} ] return random.choice(occlusions)
|