Download scripts/aggregate_results.py from ProAudience/agenthoi-eval: direct link, hf CLI and curl.
- Browser
- Download file 5.95 kB
-
https://huggingface.co/datasets/ProAudience/agenthoi-eval/resolve/main/scripts/aggregate_results.py
- Command line
-
hf download hf://datasets/ProAudience/agenthoi-eval/scripts/aggregate_results.py
-
curl -L -o aggregate_results.py https://huggingface.co/datasets/ProAudience/agenthoi-eval/resolve/main/scripts/aggregate_results.py
5.95 kB
| #!/usr/bin/env python3 | |
| """Aggregate metric outputs into a single Excel summary. | |
| Walks through one or more `*_eval` directories produced by | |
| `run_all_metrics.sh` and produces a flattened summary table (one row per | |
| method) covering Object-DINO / VBench / TVA / InternVL. | |
| Usage: | |
| python aggregate_results.py --input_dir /path/to/<method>_eval | |
| python aggregate_results.py --input_dir /path/to/results --output summary.xlsx | |
| python aggregate_results.py --input_dirs /path/to/dir1 /path/to/dir2 | |
| """ | |
| from __future__ import annotations | |
| import argparse | |
| import json | |
| import os | |
| import glob | |
| def _read_json(path: str) -> dict | list | None: | |
| if not path or not os.path.isfile(path): | |
| return None | |
| try: | |
| with open(path, "r", encoding="utf-8") as f: | |
| return json.load(f) | |
| except Exception: | |
| return None | |
| def collect_obj_dino(root: str) -> dict: | |
| p = os.path.join(root, "obj_dino_result.json") | |
| data = _read_json(p) | |
| if not data or not isinstance(data, dict): | |
| return {} | |
| return { | |
| "obj_dino_avg_dino_subject": data.get("avg_dino_subject"), | |
| "obj_dino_total_frames": data.get("total_frame_count"), | |
| } | |
| def collect_vbench(root: str) -> dict: | |
| out = {} | |
| vbench_dir = os.path.join(root, "vbench_results") | |
| if not os.path.isdir(vbench_dir): | |
| return out | |
| candidates = glob.glob(os.path.join(vbench_dir, "*_eval_results.json")) | |
| if not candidates: | |
| return out | |
| latest = max(candidates, key=os.path.getmtime) | |
| data = _read_json(latest) | |
| if not data or not isinstance(data, dict): | |
| return out | |
| for dim in ["motion_smoothness", "dynamic_degree", "aesthetic_quality", "overall_consistency"]: | |
| val = data.get(dim) | |
| if val is not None: | |
| if isinstance(val, (list, tuple)) and len(val) > 0: | |
| out[f"vbench_{dim}"] = val[0] | |
| else: | |
| out[f"vbench_{dim}"] = val | |
| return out | |
| def collect_tva(root: str) -> dict: | |
| p = os.path.join(root, "TVA_result.json") | |
| data = _read_json(p) | |
| if not data or not isinstance(data, dict): | |
| return {} | |
| return { | |
| "tva_VQ": data.get("average_VQ_score"), | |
| "tva_MQ": data.get("average_MQ_score"), | |
| "tva_TA": data.get("average_TA_score"), | |
| "tva_Overall": data.get("average_Overall_score"), | |
| "tva_videos": data.get("total_videos_processed"), | |
| } | |
| def collect_internvl(root: str) -> dict: | |
| p = os.path.join(root, "internvl", "summary.json") | |
| data = _read_json(p) | |
| if not data or not isinstance(data, dict): | |
| return {} | |
| avg = data.get("average_scores") or {} | |
| return { | |
| "internvl_object": avg.get("object_score"), | |
| "internvl_human": avg.get("human_score"), | |
| "internvl_interaction": avg.get("interaction_score"), | |
| "internvl_total_avg": avg.get("total_average_score"), | |
| "internvl_videos": data.get("successfully_evaluated"), | |
| } | |
| def collect_one_dir(root: str, method_name: str | None = None) -> tuple[str, dict]: | |
| """Collect all metrics from a single eval directory. | |
| Returns (method_name, flat_metrics_dict). | |
| """ | |
| name = method_name or os.path.basename(root.rstrip("/")) | |
| if name.endswith("_eval"): | |
| name = name[: -len("_eval")] | |
| row = {"method": name} | |
| row.update(collect_obj_dino(root)) | |
| row.update(collect_vbench(root)) | |
| row.update(collect_tva(root)) | |
| row.update(collect_internvl(root)) | |
| return name, row | |
| def flatten_order() -> list[str]: | |
| """Column order for the summary table.""" | |
| return [ | |
| "method", | |
| "obj_dino_avg_dino_subject", | |
| "obj_dino_total_frames", | |
| "vbench_motion_smoothness", | |
| "vbench_dynamic_degree", | |
| "vbench_aesthetic_quality", | |
| "vbench_overall_consistency", | |
| "tva_VQ", | |
| "tva_MQ", | |
| "tva_TA", | |
| "tva_Overall", | |
| "tva_videos", | |
| "internvl_object", | |
| "internvl_human", | |
| "internvl_interaction", | |
| "internvl_total_avg", | |
| "internvl_videos", | |
| ] | |
| def main(): | |
| parser = argparse.ArgumentParser(description="Aggregate evaluation metrics into an Excel summary.") | |
| parser.add_argument( | |
| "--input_dir", | |
| type=str, | |
| default=None, | |
| help="Single eval directory, or a parent dir (will scan for *_eval children).", | |
| ) | |
| parser.add_argument( | |
| "--input_dirs", | |
| type=str, | |
| nargs="+", | |
| default=None, | |
| help="Multiple eval directories.", | |
| ) | |
| parser.add_argument( | |
| "--output", | |
| type=str, | |
| default="summary.xlsx", | |
| help="Output Excel path.", | |
| ) | |
| args = parser.parse_args() | |
| dirs = [] | |
| if args.input_dirs: | |
| dirs = [os.path.abspath(d) for d in args.input_dirs] | |
| elif args.input_dir: | |
| d = os.path.abspath(args.input_dir) | |
| if os.path.isdir(d): | |
| base = os.path.basename(d.rstrip("/")) | |
| if base.endswith("_eval"): | |
| dirs = [d] | |
| else: | |
| pattern = os.path.join(d, "*_eval") | |
| dirs = sorted(glob.glob(pattern)) | |
| if not dirs: | |
| dirs = [d] | |
| if not dirs: | |
| print("No eval directories specified or found.") | |
| return | |
| rows = [] | |
| for d in dirs: | |
| _, row = collect_one_dir(d) | |
| rows.append(row) | |
| try: | |
| import pandas as pd | |
| except ImportError: | |
| print("Needs pandas and openpyxl: pip install pandas openpyxl") | |
| return | |
| order = flatten_order() | |
| all_keys = set() | |
| for r in rows: | |
| all_keys.update(r.keys()) | |
| cols = [c for c in order if c in all_keys] + sorted(all_keys - set(order)) | |
| df = pd.DataFrame(rows, columns=cols) | |
| with pd.ExcelWriter(args.output, engine="openpyxl") as w: | |
| df.to_excel(w, sheet_name="summary", index=False) | |
| print(f"Written: {args.output}") | |
| print(f"Total methods: {len(rows)}") | |
| if __name__ == "__main__": | |
| main() | |