Download eval/source/robot_tools/droid/scripts/make_grid.py from JiayiWuLeo/RobotZero: direct link, hf CLI and curl.
- Browser
- Download file 4.63 kB
-
https://huggingface.co/datasets/JiayiWuLeo/RobotZero/resolve/main/eval/source/robot_tools/droid/scripts/make_grid.py
- Command line
-
hf download hf://datasets/JiayiWuLeo/RobotZero/eval/source/robot_tools/droid/scripts/make_grid.py
-
curl -L -o make_grid.py https://huggingface.co/datasets/JiayiWuLeo/RobotZero/resolve/main/eval/source/robot_tools/droid/scripts/make_grid.py
4.63 kB
| """Build a review grid per camera: rows = sampled steps, | |
| cols = [real | render | overlay | camera-space normal]. | |
| Uses the v2 API: EpisodeSession picks the per-episode arm URDF (data/robot_model_map.json), the mount | |
| params (calib/mount_params.json) and data/<uuid>/calib_refined_v2.json when present (else superset | |
| extrinsics + 37 ms); K is taken at the real MP4 size (sess.K_mp4). The header of every tile row shows | |
| the calibration actually used (calib version, time offset, per-camera v2 status). | |
| Usage: python make_grid.py <episode_dir> [--rows N] [--serials S1 S2] [--wrist] [--scale 0.5] | |
| [--out-root DIR] [--legacy-geometry] | |
| Writes out/<uuid>/grid_<serial>.jpg (or <out-root>/<uuid>/grid_<serial>.jpg). | |
| """ | |
| import argparse | |
| from pathlib import Path | |
| import cv2 | |
| import numpy as np | |
| from dutils import ROOT | |
| from render_episode import EpisodeSession, overlay_frame | |
| def main(argv=None): | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("ep_dir") | |
| ap.add_argument("--rows", type=int, default=5) | |
| ap.add_argument("--serials", nargs="*", default=None) | |
| ap.add_argument("--wrist", action="store_true") | |
| ap.add_argument("--scale", type=float, default=0.5) | |
| ap.add_argument("--out-root", default=None, help="output root (default <repo>/out)") | |
| ap.add_argument("--legacy-geometry", action="store_true", help="pre-2026-10 geometry (before/after comparison)") | |
| args = ap.parse_args(argv) | |
| sess = EpisodeSession(args.ep_dir, wrist=args.wrist, legacy_geometry=args.legacy_geometry) | |
| rr = sess.rr | |
| ep_dir, uuid = sess.ep_dir, sess.uuid | |
| serials = [str(s) for s in (args.serials or sess.serials)] | |
| out_root = Path(args.out_root) if args.out_root else ROOT / "out" | |
| calib_tag = (f"calib v{sess.calib_version} dt {sess.dt_ms:+.1f} ms | arm {sess.arm_type} | " | |
| f"mount {Path(str(sess.urdf_info['mount_source'])).name} {str(sess.urdf_info['mount_params_md5'])[:8]}") | |
| for serial in serials: | |
| if serial not in sess.K: | |
| print(f"cam {serial}: no intrinsics; skipped") | |
| continue | |
| mp4 = ep_dir / f"recordings/MP4/{serial}.mp4" | |
| if not mp4.exists(): | |
| print(f"cam {serial}: no MP4; skipped") | |
| continue | |
| cap = cv2.VideoCapture(str(mp4)) | |
| wh = (int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)), int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))) | |
| K = sess.K_mp4.get(serial, sess.K[serial]) | |
| sw, sh = int(round(wh[0] * args.scale)), int(round(wh[1] * args.scale)) | |
| n = min(sess.n, int(cap.get(cv2.CAP_PROP_FRAME_COUNT)), len(sess.cap_ts.get(serial, []))) | |
| steps = np.unique(np.linspace(0, n - 1, args.rows).astype(int)) | |
| q = sess.quality.get(serial, {}) if isinstance(sess.quality, dict) else {} | |
| q_tag = (f"v2 {q.get('status')} {q.get('metric_name', '')} {q.get('metric_before')}->{q.get('metric_after')}" | |
| if q else ("no v2 (superset + default dt)" if sess.calib_version != 2 else "v2 (no quality record)")) | |
| grid_rows = [] | |
| for step in steps: | |
| cap.set(cv2.CAP_PROP_POS_FRAMES, int(step)) | |
| ok, frame = cap.read() | |
| if not ok: | |
| continue | |
| T = sess.set_step(serial, int(step)) | |
| rgb, mask, normal = rr.render(T, K, wh, with_normals=True) | |
| render_bgr = rgb[:, :, ::-1].copy() | |
| render_bgr[~mask] = 255 | |
| ov = overlay_frame(frame, rgb, mask, 0.55) | |
| tiles = [] | |
| for img, label in [(frame, f"real step {step}"), | |
| (render_bgr, "render"), | |
| (ov, "overlay"), | |
| (normal[:, :, ::-1], "camera-space normal")]: | |
| t = cv2.resize(np.ascontiguousarray(img), (sw, sh)) | |
| cv2.putText(t, label, (10, 30), 0, 0.9 * args.scale * 2, (0, 0, 255), 2) | |
| tiles.append(t) | |
| grid_rows.append(np.hstack(tiles)) | |
| cap.release() | |
| if not grid_rows: | |
| print(f"cam {serial}: no decodable frames; skipped") | |
| continue | |
| header = np.full((36, grid_rows[0].shape[1], 3), 255, np.uint8) | |
| cv2.putText(header, f"{uuid} cam {serial}{' (wrist)' if serial == sess.wrist_serial else ''} | {calib_tag} | {q_tag}", | |
| (10, 26), 0, 0.6, (0, 0, 0), 1) | |
| out = out_root / uuid / f"grid_{serial}.jpg" | |
| out.parent.mkdir(parents=True, exist_ok=True) | |
| if not cv2.imwrite(str(out), np.vstack([header] + grid_rows)): | |
| raise RuntimeError(f"imwrite failed: {out}") | |
| print("wrote", out) | |
| if __name__ == "__main__": | |
| main() | |