bev-project/INSPECT_FAST_RESULTS.py

136 lines
5.2 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""
检查fast_results.pkl文件的结构和内容
显示评估结果的统计信息
"""
import os
import sys
import pickle
def load_results_sample(file_path, max_samples=5):
"""安全地加载结果文件的一部分"""
print(f"📂 分析文件: {file_path}")
# 检查文件大小
file_size = os.path.getsize(file_path)
print(f"📏 文件大小: {file_size / (1024**3):.2f} GB")
if file_size > 50 * 1024**3: # 50GB
print("⚠️ 文件过大,将只分析前几个样本")
try:
with open(file_path, 'rb') as f:
# 尝试加载
results = pickle.load(f)
print(f"✅ 成功加载数据")
print(f"📊 数据类型: {type(results)}")
if isinstance(results, list):
analyze_list_results(results, max_samples)
else:
print(f"⚠️ 意外的数据类型: {type(results)}")
except Exception as e:
print(f"❌ 加载失败: {e}")
return None
def analyze_list_results(results, max_samples=5):
"""分析列表类型的评估结果"""
total_samples = len(results)
print(f"📏 总样本数: {total_samples}")
if total_samples == 0:
print("⚠️ 结果列表为空")
return
# 分析前几个样本
samples_to_analyze = min(max_samples, total_samples)
print(f"🔍 分析前 {samples_to_analyze} 个样本:")
sample_stats = {
'has_boxes_3d': 0,
'has_scores_3d': 0,
'has_labels_3d': 0,
'has_masks_bev': 0,
'total_boxes': 0,
'box_score_ranges': [],
'mask_shapes': []
}
for i in range(samples_to_analyze):
sample = results[i]
print(f"\n 样本 {i+1}:")
if isinstance(sample, dict):
# 检查3D检测结果
if 'boxes_3d' in sample:
sample_stats['has_boxes_3d'] += 1
boxes = sample['boxes_3d']
if hasattr(boxes, 'tensor'):
num_boxes = boxes.tensor.shape[0]
else:
num_boxes = len(boxes) if hasattr(boxes, '__len__') else 0
sample_stats['total_boxes'] += num_boxes
print(f" 📦 boxes_3d: {num_boxes} 个检测框")
if 'scores_3d' in sample:
sample_stats['has_scores_3d'] += 1
scores = sample['scores_3d']
if hasattr(scores, '__len__') and len(scores) > 0:
score_range = [float(np.min(scores)), float(np.max(scores))]
sample_stats['box_score_ranges'].append(score_range)
print(f" 🎯 scores_3d: 范围 [{score_range[0]:.4f}, {score_range[1]:.4f}]")
if 'labels_3d' in sample:
sample_stats['has_labels_3d'] += 1
labels = sample['labels_3d']
if hasattr(labels, '__len__') and len(labels) > 0:
unique_labels = np.unique(labels)
print(f" 🏷️ labels_3d: {len(unique_labels)} 个类别 {unique_labels}")
# 检查BEV分割结果
if 'masks_bev' in sample:
sample_stats['has_masks_bev'] += 1
masks = sample['masks_bev']
if hasattr(masks, 'shape'):
shape = masks.shape
sample_stats['mask_shapes'].append(shape)
print(f" 🗺️ masks_bev: 形状 {shape}")
print(f" 分割类别数: {shape[0]}, BEV尺寸: {shape[1]}×{shape[2]}")
# 统计每个类别的像素占比
for c in range(min(3, shape[0])): # 只显示前3个类别
if hasattr(masks, 'shape') and len(shape) >= 3:
pixel_count = np.sum(masks[c])
total_pixels = shape[1] * shape[2]
percentage = pixel_count / total_pixels * 100
print(f" 类别{c}: {pixel_count}像素 ({percentage:.2f}%)")
else:
print(f" ⚠️ 意外的样本类型: {type(sample)}")
# 汇总统计
print(f"\n📈 统计汇总 (前{samples_to_analyze}个样本):")
print(f" 📦 包含3D检测框: {sample_stats['has_boxes_3d']}/{samples_to_analyze}")
print(f" 🎯 包含检测分数: {sample_stats['has_scores_3d']}/{samples_to_analyze}")
print(f" 🏷️ 包含检测标签: {sample_stats['has_labels_3d']}/{samples_to_analyze}")
print(f" 🗺️ 包含BEV分割: {sample_stats['has_masks_bev']}/{samples_to_analyze}")
print(f" 📊 总检测框数: {sample_stats['total_boxes']}")
if sample_stats['box_score_ranges']:
all_scores = [r for ranges in sample_stats['box_score_ranges'] for r in ranges]
print(f" 🎯 检测分数范围: [{min(all_scores):.4f}, {max(all_scores):.4f}]")
if sample_stats['mask_shapes']:
shapes = sample_stats['mask_shapes']
print(f" 🔲 BEV分割形状: {shapes[0] if shapes else 'N/A'}")
def main():
if len(sys.argv) != 2:
print("用法: python INSPECT_FAST_RESULTS.py <results_file>")
sys.exit(1)
results_file = sys.argv[1]
load_results_sample(results_file)
if __name__ == "__main__":
main()