File size: 1,088 Bytes
ae1ed83 | 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 | #!/usr/bin/env python3
"""Data Factory pilot: render agentview mp4s for one valid pair per
layout (both goals) from the saved episode arrays."""
import json
from pathlib import Path
import cv2
import numpy as np
EXP = Path.home() / "sera_v4_experiments"
OUT = EXP / "data_factory" / "pilot"
VID = OUT / "videos"
VID.mkdir(exist_ok=True)
man = json.loads((OUT / "manifest.json").read_text())
want = {}
for p in man["pairs"]:
if p["layout"] not in want:
want[p["layout"]] = p
for layout, pair in want.items():
for goal, ep_id in pair["episodes"].items():
d = np.load(OUT / "episodes" / f"{ep_id}.npz")
frames = d["agentview"]
path = VID / f"df_pair_{pair['pair_id']}_goal{goal}.mp4"
w = cv2.VideoWriter(str(path),
cv2.VideoWriter_fourcc(*"mp4v"), 10,
(256, 256))
for fr in frames:
w.write(cv2.cvtColor(fr, cv2.COLOR_RGB2BGR))
w.release()
print(path.name, len(frames), "frames",
path.stat().st_size, "bytes", flush=True)
print("DONE")
|