#!/usr/bin/env python3 """ 检查程序运行时是否使用了 TensorRT """ import sys import re def check_log_for_tensorrt(log_file=None): """检查日志文件中是否有 TensorRT 相关信息""" if log_file: try: with open(log_file, 'r', encoding='utf-8') as f: content = f.read() except: print(f"无法读取日志文件: {log_file}") return False else: print("请提供日志文件路径,或直接查看程序输出") return None # 检查 TensorRT 相关关键词 tensorrt_indicators = [ r"Compiling models with TensorRT", r"TensorRT optimization completed", r"SuperPoint compiled with TensorRT", r"Precision: (fp16|fp32|int8)", # TensorRT 精度设置 ] found = False for pattern in tensorrt_indicators: if re.search(pattern, content, re.IGNORECASE): print(f"✓ 找到 TensorRT 使用证据: {pattern}") found = True if not found: # 检查是否有警告信息 if "Warning: TensorRT" in content or "Failed to compile with TensorRT" in content: print("✗ TensorRT 编译失败或未启用") else: print("✗ 未找到 TensorRT 使用证据") print(" 可能原因:") print(" 1. 运行时未使用 --use_tensorrt 参数") print(" 2. TensorRT 编译失败,回退到 PyTorch") print(" 3. 程序在 CPU 上运行(TensorRT 需要 CUDA)") return found def check_command_line(): """检查命令行参数""" print("="*60) print("如何判断是否使用了 TensorRT:") print("="*60) print() print("1. 查看程序启动时的输出:") print(" 如果使用了 TensorRT,会看到:") print(" ============================================================") print(" Compiling models with TensorRT...") print(" Precision: fp16") print(" This may take several minutes on first run...") print(" ============================================================") print() print("2. 编译成功后会看到:") print(" ✓ SuperPoint compiled with TensorRT") print(" ✓ TensorRT optimization completed") print() print("3. 检查运行命令:") print(" 必须包含 --use_tensorrt 参数") print() print("4. 性能对比:") print(" - PyTorch FP16: ~22 FPS") print(" - TensorRT FP16: ~35-45 FPS") print(" 如果 FPS 明显提升,说明使用了 TensorRT") print() print("="*60) print("正确的运行命令应该是:") print("="*60) print() print('python demo_lightglue_camera_position_async.py ^') print(' --input "udp://0.0.0.0:12346" ^') print(' --max_keypoints 128 ^') print(' --use_fp16 ^') print(' --use_tensorrt ^') print(' --tensorrt_precision fp16') print() if __name__ == "__main__": if len(sys.argv) > 1: log_file = sys.argv[1] check_log_for_tensorrt(log_file) else: check_command_line()