Ernie_trained_for_LIC / organ_result.py
Miaode's picture
Add files using upload-large-folder tool
9c14756 verified
#!/usr/bin/env python3
# collect_acc_table_pivot.py
"""
递归遍历 result 目录 -> 提取 acc ->
pivot 成 行 = benchmark, 列 = model 的矩阵
"""
import os
import json
import pandas as pd
from glob import glob
# === 修改为你实际存放结果的根路径 ===
ROOT_DIR = "/cpfs/user/boyuan/verl_workspace/baidu/Qwen2.5-Math/evaluation/result"
records = []
# 遍历 <model>/<benchmark> 目录层级
for model_name in sorted(os.listdir(ROOT_DIR)):
model_path = os.path.join(ROOT_DIR, model_name)
if not os.path.isdir(model_path):
continue
for bench_name in sorted(os.listdir(model_path)):
bench_path = os.path.join(model_path, bench_name)
if not os.path.isdir(bench_path):
continue
# 找 *_metrics.json(默认只取第一个)
metric_files = glob(os.path.join(bench_path, "*_metrics.json"))
if not metric_files:
continue
with open(metric_files[0], "r", encoding="utf-8") as f:
acc = json.load(f).get("acc")
if acc is not None:
records.append(
{"benchmark": bench_name, "model": model_name, "acc": acc}
)
# 汇总为 DataFrame
df_long = pd.DataFrame(records)
# 透视表:行 = benchmark,列 = model
df_pivot = (
df_long.pivot(index="benchmark", columns="model", values="acc")
.sort_index() # 按 benchmark 名字排序行
.sort_index(axis=1) # 按 model 名字排序列
)
# 保存 & 打印
csv_path = os.path.join(ROOT_DIR, "benchmark_vs_models_acc.csv")
df_pivot.to_csv(csv_path, float_format="%.4g", encoding="utf-8")
print("\n=== Benchmark × Model ACC 表 ===")
print(df_pivot)
print(f"\n已保存为: {csv_path}")