82 lines
2.5 KiB
Python
82 lines
2.5 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
完整的动态批次性能测试流程
|
|
1. 构建动态批次 TensorRT 引擎
|
|
2. 运行批次性能测试
|
|
3. 生成可视化报告
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
import subprocess
|
|
|
|
def run_command(cmd, description):
|
|
"""运行命令并显示进度"""
|
|
print(f"\n{'='*60}")
|
|
print(f"🚀 {description}")
|
|
print(f"{'='*60}")
|
|
|
|
result = subprocess.run(cmd, shell=True)
|
|
|
|
if result.returncode != 0:
|
|
print(f"❌ {description} 失败")
|
|
return False
|
|
|
|
print(f"✅ {description} 完成")
|
|
return True
|
|
|
|
def main():
|
|
"""主函数"""
|
|
print("完整的动态批次 TensorRT 性能测试流程")
|
|
print("="*60)
|
|
|
|
# 检查 conda 环境
|
|
print("\n📋 执行步骤:")
|
|
print(" 1. 构建动态批次 TensorRT 引擎")
|
|
print(" 2. 运行批次性能测试")
|
|
print(" 3. 生成可视化报告")
|
|
|
|
input("\n按 Enter 键开始...")
|
|
|
|
# 步骤 1: 构建动态批次引擎
|
|
engine_path = "C:/Users/16337/PycharmProjects/Security/yolo11n_dynamic.engine"
|
|
|
|
if not os.path.exists(engine_path):
|
|
print("\n🔧 步骤 1: 构建动态批次 TensorRT 引擎")
|
|
if not run_command("conda activate yolov11 && python dynamic_batch_tensorrt_builder.py",
|
|
"构建动态批次 TensorRT 引擎"):
|
|
return
|
|
else:
|
|
print(f"\n✅ 动态批次引擎已存在: {engine_path}")
|
|
print("跳过步骤 1")
|
|
|
|
# 步骤 2: 运行批次性能测试
|
|
print("\n📊 步骤 2: 运行批次性能测试")
|
|
if not run_command("conda activate yolov11 && python run_batch_performance_test.py",
|
|
"运行批次性能测试"):
|
|
return
|
|
|
|
# 步骤 3: 生成可视化报告
|
|
print("\n🎨 步骤 3: 生成可视化报告")
|
|
if not run_command("conda activate yolov11 && python visualize_batch_results.py",
|
|
"生成可视化报告"):
|
|
return
|
|
|
|
print("\n" + "="*60)
|
|
print("🎉 完整测试流程执行完成!")
|
|
print("="*60)
|
|
print("\n📁 查看结果:")
|
|
print(" - 测试数据: batch_test_results/")
|
|
print(" - 可视化图表: batch_test_results/visualizations/")
|
|
print(" - 总结报告: batch_test_results/visualizations/batch_performance_summary.txt")
|
|
|
|
if __name__ == "__main__":
|
|
try:
|
|
main()
|
|
except KeyboardInterrupt:
|
|
print("\n\n⏹️ 测试被用户中断")
|
|
except Exception as e:
|
|
print(f"\n❌ 执行过程中发生错误: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|