Download source/project/scripts/finalize_proxy_benchmark.py from lupele/StatePlay-Reward-2280: direct link, hf CLI and curl.
- Browser
- Download file 3.51 kB
-
https://huggingface.co/datasets/lupele/StatePlay-Reward-2280/resolve/main/source/project/scripts/finalize_proxy_benchmark.py
- Command line
-
hf download hf://datasets/lupele/StatePlay-Reward-2280/source/project/scripts/finalize_proxy_benchmark.py
-
curl -L -o finalize_proxy_benchmark.py https://huggingface.co/datasets/lupele/StatePlay-Reward-2280/resolve/main/source/project/scripts/finalize_proxy_benchmark.py
3.51 kB
| #!/usr/bin/env python3 | |
| """Validate generated proxy videos and write mechanics/visual evaluator manifests.""" | |
| from __future__ import annotations | |
| import argparse | |
| import csv | |
| import hashlib | |
| import json | |
| import os | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parents[1] | |
| def sha256_file(path: Path) -> str: | |
| digest = hashlib.sha256() | |
| with path.open("rb") as handle: | |
| for chunk in iter(lambda: handle.read(16 * 1024 * 1024), b""): | |
| digest.update(chunk) | |
| return digest.hexdigest() | |
| def main() -> None: | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument("--selection", type=Path, default=ROOT / "evaluation/proxy100/selection.json") | |
| parser.add_argument("--run-name", required=True) | |
| parser.add_argument("--checkpoint", type=Path, required=True) | |
| parser.add_argument("--generated-root", type=Path, default=ROOT / "evaluation/proxy100/generated") | |
| args = parser.parse_args() | |
| selection = json.loads(args.selection.resolve().read_text(encoding="utf-8")) | |
| output_dir = (args.generated_root / args.run_name).resolve() | |
| mechanics_rows = [] | |
| visual_rows = [] | |
| missing = [] | |
| for sample in selection["samples"]: | |
| prediction = output_dir / sample["output_name"] | |
| if not prediction.is_file() or prediction.stat().st_size == 0: | |
| missing.append(str(prediction)) | |
| continue | |
| relative_prediction = prediction.relative_to(args.selection.resolve().parent).as_posix() | |
| mechanics_rows.append({"id": sample["id"], "prediction": relative_prediction, "label": sample["label"]}) | |
| if sample.get("reference_video"): | |
| reference = ROOT / sample["reference_video"] | |
| visual_rows.append( | |
| { | |
| "id": sample["id"], | |
| "prediction": relative_prediction, | |
| "reference": os.path.relpath(reference, args.selection.resolve().parent), | |
| "label": sample["label"], | |
| } | |
| ) | |
| if missing: | |
| raise FileNotFoundError(f"Missing {len(missing)} generated videos; first: {missing[0]}") | |
| mechanics_path = args.selection.resolve().parent / f"manifest_{args.run_name}_mechanics.csv" | |
| with mechanics_path.open("w", newline="", encoding="utf-8") as handle: | |
| writer = csv.DictWriter(handle, fieldnames=("id", "prediction", "label")) | |
| writer.writeheader(); writer.writerows(mechanics_rows) | |
| visual_path = args.selection.resolve().parent / f"manifest_{args.run_name}_visual.csv" | |
| with visual_path.open("w", newline="", encoding="utf-8") as handle: | |
| writer = csv.DictWriter(handle, fieldnames=("id", "prediction", "reference", "label")) | |
| writer.writeheader(); writer.writerows(visual_rows) | |
| provenance = { | |
| "run_name": args.run_name, | |
| "selection": str(args.selection.resolve().relative_to(ROOT)), | |
| "checkpoint": str(args.checkpoint.resolve().relative_to(ROOT)), | |
| "checkpoint_sha256": sha256_file(args.checkpoint.resolve()), | |
| "mechanics_samples": len(mechanics_rows), | |
| "visual_samples": len(visual_rows), | |
| "mechanics_manifest": str(mechanics_path.relative_to(ROOT)), | |
| "visual_manifest": str(visual_path.relative_to(ROOT)), | |
| } | |
| (args.selection.resolve().parent / f"provenance_{args.run_name}.json").write_text( | |
| json.dumps(provenance, indent=2) + "\n", encoding="utf-8" | |
| ) | |
| print(json.dumps(provenance, indent=2)) | |
| if __name__ == "__main__": | |
| main() | |