#!/usr/bin/env python3 """Debug script to inspect pkl structure""" import pickle import numpy as np pkl_file = 'results/declip_vitb16/predictions.pkl' print("Loading pkl...") with open(pkl_file, 'rb') as f: results = pickle.load(f) print(f"Type: {type(results)}") print(f"Length: {len(results)}") # Check first few results for i in range(min(3, len(results))): result = results[i] print(f"\n=== Result {i} ===") print(f" Type: {type(result)}") if isinstance(result, (list, tuple)): print(f" Length: {len(result)}") for j, item in enumerate(result[:3]): print(f" [{j}] Type: {type(item)}, Shape: {getattr(item, 'shape', 'N/A')}, Len: {len(item) if hasattr(item, '__len__') else 'N/A'}") if hasattr(item, '__len__') and len(item) > 0: if hasattr(item, 'shape'): print(f" First elem shape: {item[0].shape if len(item) > 0 else 'empty'}") if len(item) > 0 and len(item[0]) > 0: print(f" First box: {item[0]}") # Find first non-empty bbox print("\n=== Finding non-empty predictions ===") for i in range(min(100, len(results))): result = results[i] if isinstance(result, (list, tuple)): for j, bboxes in enumerate(result): if hasattr(bboxes, '__len__') and len(bboxes) > 0: print(f"Image {i}, Class {j}: {len(bboxes)} boxes") print(f" Type: {type(bboxes)}, Shape: {bboxes.shape if hasattr(bboxes, 'shape') else 'N/A'}") if len(bboxes) > 0: print(f" First box: {bboxes[0]}") print(f" First box type: {type(bboxes[0])}") print(f" First box shape: {bboxes[0].shape if hasattr(bboxes[0], 'shape') else len(bboxes[0])}") break else: continue break