File size: 2,074 Bytes
2bfd19c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python3
"""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()