| |
| """Re-evaluate all runs in a sweep directory and refresh results.csv.""" |
|
|
| import argparse |
| import csv |
| import subprocess |
| from pathlib import Path |
|
|
|
|
| def main(): |
| parser = argparse.ArgumentParser() |
| parser.add_argument("--sweep_dir", required=True) |
| parser.add_argument("--baseline", required=True) |
| parser.add_argument("--eval_script", required=True) |
| args = parser.parse_args() |
|
|
| sweep = Path(args.sweep_dir) |
| csv_path = sweep / "report" / "results.csv" |
| rows = list(csv.DictReader(open(csv_path))) if csv_path.exists() else [] |
|
|
| updated = [] |
| for row in rows: |
| out = Path(row["video_path"]) |
| log = Path(row["log_path"]) |
| metric = out.parent / "metrics.json" |
| if not out.exists(): |
| updated.append(row) |
| continue |
| cmd = [ |
| "python3", args.eval_script, |
| "--baseline", args.baseline, |
| "--generated", str(out), |
| "--log", str(log), |
| ] |
| if metric.exists(): |
| cmd += ["--metric", str(metric)] |
| proc = subprocess.run(cmd, capture_output=True, text=True) |
| metrics = {} |
| for line in proc.stdout.splitlines(): |
| if "=" in line: |
| k, v = line.split("=", 1) |
| metrics[k] = v |
| row["psnr_db"] = metrics.get("PSNR", row.get("psnr_db", "NA")) |
| row["ssim"] = metrics.get("SSIM", row.get("ssim", "NA")) |
| row["black_ratio"] = metrics.get("BLACK", row.get("black_ratio", "NA")) |
| row["reuse_rate_pct"] = metrics.get("REUSE", row.get("reuse_rate_pct", "NA")) |
| row["peak_gb"] = metrics.get("PEAK", row.get("peak_gb", "NA")) |
| updated.append(row) |
| print(f"{row['variant']}: PSNR={row['psnr_db']} reuse={row['reuse_rate_pct']}%") |
|
|
| fieldnames = list(updated[0].keys()) if updated else [] |
| with open(csv_path, "w", newline="") as f: |
| w = csv.DictWriter(f, fieldnames=fieldnames) |
| w.writeheader() |
| w.writerows(updated) |
| print(f"Updated {csv_path}") |
|
|
|
|
| if __name__ == "__main__": |
| main() |
|
|