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
| """ 四种视线估计模型的统一推理接口
适用场景: DMS 开发选型评估 """
import torch import numpy as np import cv2 from typing import Dict, Tuple, List
class GazeModelComparison: """四种视线模型统一对比接口""" def __init__(self, device='cuda'): self.device = device self.models = {} def load_gazelle(self, model_path): """加载 Gaze-LLE""" pass def load_l2cs(self, model_path): """加载 L2CS-Net""" pass def load_gaze3d(self, model_path): """加载 Gaze3D""" pass def load_gazeanywhere(self, model_path): """加载 GazeAnywhere""" pass def benchmark(self, image, head_boxes, num_runs=100): """基准测试""" import time results = {} for name, model in self.models.items(): times = [] for _ in range(num_runs): torch.cuda.synchronize() start = time.perf_counter() if name == 'gazelle': output = model(image, head_boxes) elif name == 'l2cs': crops = [self._crop_face(image, box) for box in head_boxes] output = model(crops) elif name == 'gaze3d': crops = [self._crop_face(image, box) for box in head_boxes] output = model(crops, image) elif name == 'gazeanywhere': output = model(image, "driver") torch.cuda.synchronize() times.append((time.perf_counter() - start) * 1000) results[name] = { 'mean_ms': np.mean(times), 'p99_ms': np.percentile(times, 99), 'fps': 1000 / np.mean(times), } return results def _crop_face(self, image, box): """裁剪人脸区域""" x1, y1, x2, y2 = map(int, box) return cv2.resize(image[y1:y2, x1:x2], (224, 224))
def dms_model_selection_guide(): """DMS 视线模型选型决策指南""" scenarios = { '高速实时DMS(<20ms)': { 'recommend': 'L2CS-Net', 'reason': '25M参数,ResNet-50骨干,推理<10ms', 'tradeoff': '仅单人,需额外映射视线落点', }, '多乘员全舱监测': { 'recommend': 'GazeAnywhere / Gaze-LLE', 'reason': '原生多人物支持,无需循环', 'tradeoff': '推理延迟较高,需优化', }, '视线落点直接输出': { 'recommend': 'Gaze-LLE / GazeAnywhere', 'reason': '直接输出热图,无需角度映射', 'tradeoff': '热图分辨率有限(64×64)', }, '车规NPU部署': { 'recommend': 'L2CS-Net / Gaze3D', 'reason': 'ResNet骨干量化友好,INT8后<5MB', 'tradeoff': '功能有限,需扩展', }, '研发验证+最高精度': { 'recommend': 'GazeAnywhere', 'reason': 'CVPR 2026 SOTA,提示驱动灵活', 'tradeoff': '模型大,需大幅压缩才能车规部署', }, '与EyeCue认知分心融合': { 'recommend': 'GazeAnywhere → EyeCue', 'reason': 'GazeAnywhere提供凝视坐标→EyeCue分类', 'tradeoff': '两阶段管线,延迟需评估', }, } for scenario, info in scenarios.items(): print(f"\n场景: {scenario}") print(f" 推荐: {info['recommend']}") print(f" 原因: {info['reason']}") print(f" 权衡: {info['tradeoff']}")
if __name__ == "__main__": dms_model_selection_guide()
|