Download Ctrl-World-Graph/scripts/summarize_query_val_eval.py from EndeavourDD/gnn_wm2: direct link, hf CLI and curl.
- Browser
- Download file 3.01 kB
-
https://huggingface.co/datasets/EndeavourDD/gnn_wm2/resolve/main/Ctrl-World-Graph/scripts/summarize_query_val_eval.py
- Command line
-
hf download hf://datasets/EndeavourDD/gnn_wm2/Ctrl-World-Graph/scripts/summarize_query_val_eval.py
-
curl -L -o summarize_query_val_eval.py https://huggingface.co/datasets/EndeavourDD/gnn_wm2/resolve/main/Ctrl-World-Graph/scripts/summarize_query_val_eval.py
3.01 kB
| from __future__ import annotations | |
| import argparse | |
| import json | |
| from pathlib import Path | |
| import numpy as np | |
| def summarize_variant(root: Path, tag: str) -> dict: | |
| ckpt_dir = root / tag / "checkpoint-100000" | |
| aggregate_files = sorted(ckpt_dir.glob("val_psnr_*.json")) | |
| if aggregate_files: | |
| data = json.loads(aggregate_files[-1].read_text(encoding="utf-8")) | |
| return { | |
| "tag": tag, | |
| "samples": data.get("num_samples", 0), | |
| "psnr_mean": data.get("psnr_mean"), | |
| "psnr_std": data.get("psnr_std"), | |
| "psnr_min": data.get("psnr_min"), | |
| "psnr_max": data.get("psnr_max"), | |
| "complete": True, | |
| } | |
| metrics_paths = sorted(ckpt_dir.glob("val*/metrics.json")) | |
| psnr_values = [] | |
| for path in metrics_paths: | |
| data = json.loads(path.read_text(encoding="utf-8")) | |
| value = data.get("psnr_mean") | |
| if value is not None and np.isfinite(value): | |
| psnr_values.append(float(value)) | |
| if not psnr_values: | |
| return { | |
| "tag": tag, | |
| "samples": 0, | |
| "psnr_mean": None, | |
| "psnr_std": None, | |
| "psnr_min": None, | |
| "psnr_max": None, | |
| "complete": False, | |
| } | |
| values = np.array(psnr_values, dtype=np.float64) | |
| return { | |
| "tag": tag, | |
| "samples": int(values.size), | |
| "psnr_mean": float(values.mean()), | |
| "psnr_std": float(values.std()), | |
| "psnr_min": float(values.min()), | |
| "psnr_max": float(values.max()), | |
| "complete": False, | |
| } | |
| def main() -> None: | |
| parser = argparse.ArgumentParser(description="Summarize query val PSNR eval outputs.") | |
| parser.add_argument("--root", type=Path, default=Path("/workspace/Ctrl-World-Graph/eval_query_val")) | |
| parser.add_argument( | |
| "--tags", | |
| nargs="*", | |
| default=[ | |
| "gps_query", | |
| "gine_query", | |
| "gatv2_query", | |
| "transformer_query", | |
| "edge_transformer_query", | |
| "hybrid_gine_transformer_query", | |
| ], | |
| ) | |
| parser.add_argument("--out", type=Path, default=None) | |
| args = parser.parse_args() | |
| rows = [summarize_variant(args.root, tag) for tag in args.tags] | |
| rows.sort(key=lambda row: float("-inf") if row["psnr_mean"] is None else row["psnr_mean"], reverse=True) | |
| header = "tag\tsamples\tcomplete\tpsnr_mean\tpsnr_std\tpsnr_min\tpsnr_max" | |
| lines = [header] | |
| for row in rows: | |
| fmt = lambda value: "NA" if value is None else f"{value:.4f}" | |
| lines.append( | |
| f"{row['tag']}\t{row['samples']}\t{row['complete']}\t" | |
| f"{fmt(row['psnr_mean'])}\t{fmt(row['psnr_std'])}\t" | |
| f"{fmt(row['psnr_min'])}\t{fmt(row['psnr_max'])}" | |
| ) | |
| text = "\n".join(lines) | |
| print(text) | |
| if args.out is not None: | |
| args.out.parent.mkdir(parents=True, exist_ok=True) | |
| args.out.write_text(text + "\n", encoding="utf-8") | |
| if __name__ == "__main__": | |
| main() | |