#!/usr/bin/env python """ 检查pickle文件的基本信息 """ import pickle import sys import os def inspect_pickle_file(filepath): """检查pickle文件的基本结构""" print(f"检查文件: {filepath}") print(f"文件大小: {os.path.getsize(filepath)} bytes") try: with open(filepath, 'rb') as f: # 只读取文件头信息 magic = f.read(2) print(f"Pickle协议版本: {magic}") # 尝试读取基本结构 f.seek(0) try: data = pickle.load(f) print(f"成功加载! 类型: {type(data)}") if isinstance(data, list): print(f"列表长度: {len(data)}") if len(data) > 0: print(f"第一个元素类型: {type(data[0])}") if isinstance(data[0], dict): print(f"第一个样本的键: {list(data[0].keys())}") # 检查各个字段 for key, value in data[0].items(): if hasattr(value, 'shape'): print(f" {key}: 形状 {value.shape}, 类型 {type(value)}") elif isinstance(value, list): print(f" {key}: 列表长度 {len(value)}, 类型 {type(value)}") else: print(f" {key}: {type(value)}") elif isinstance(data, dict): print(f"字典键: {list(data.keys())}") except Exception as e: print(f"加载失败: {e}") # 尝试只读取前几个字节来了解结构 f.seek(0) header = f.read(100) print(f"文件头: {header[:50]}...") except Exception as e: print(f"文件读取错误: {e}") def main(): result_file = '/data/infer_test/20251120_124755/one_batch_results.pkl' if not os.path.exists(result_file): print(f"文件不存在: {result_file}") # 查找可能的其他文件 import glob possible_files = glob.glob('/data/infer_test/*/*.pkl') if possible_files: print(f"找到 {len(possible_files)} 个pickle文件:") for f in possible_files: print(f" {f}") result_file = possible_files[-1] inspect_pickle_file(result_file) if __name__ == '__main__': main()