bev-project/simple_demo.py

79 lines
1.9 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
"""
简化的BEVFusion推理脚本
直接加载epoch_19.pth并在少量样本上推理
避免复杂的配置文件系统
"""
import torch
import numpy as np
import matplotlib.pyplot as plt
from pathlib import Path
import sys
import os
import pickle
from tqdm import tqdm
# 添加路径
sys.path.insert(0, '/workspace/bevfusion')
os.chdir('/workspace/bevfusion')
print("="*80)
print("BEVFusion 简化推理 Demo")
print("="*80)
print("Checkpoint: epoch_19.pth")
print("推理样本: 5个")
print("="*80)
print()
# 1. 加载checkpoint
print("1. 加载checkpoint...")
checkpoint_path = 'runs/run-326653dc-74184412/epoch_19.pth'
checkpoint = torch.load(checkpoint_path, map_location='cpu')
print(f" ✅ Checkpoint加载成功")
print(f" - Epoch: {checkpoint.get('meta', {}).get('epoch', 'N/A')}")
print(f" - Keys: {len(checkpoint['state_dict'])}")
print()
# 2. 使用torchpack简单运行
print("2. 运行推理使用tools/test.py...")
print(" 配置: configs/nuscenes/det/transfusion/secfpn/camera+lidar/swint_v0p075/multitask.yaml")
print()
# 创建一个简单的运行脚本
run_cmd = """
cd /workspace/bevfusion
# 直接运行test.py使用单GPU评估前10个样本
CUDA_VISIBLE_DEVICES=0 /opt/conda/bin/python tools/test.py \
configs/nuscenes/det/transfusion/secfpn/camera+lidar/swint_v0p075/multitask.yaml \
runs/run-326653dc-74184412/epoch_19.pth \
--launcher none \
--eval bbox segm \
--out results_epoch19_demo.pkl \
2>&1 | tee inference_demo.log
"""
# 保存为脚本
with open('run_simple_inference.sh', 'w') as f:
f.write(run_cmd)
os.chmod('run_simple_inference.sh', 0o755)
print("✅ 推理脚本已创建: run_simple_inference.sh")
print()
print("="*80)
print("执行推理:")
print("="*80)
print("运行命令: bash run_simple_inference.sh")
print()
print("预计时间: 约30-60分钟完整验证集6019个样本")
print("="*80)