# SPDX-License-Identifier: Apache-2.0 """Render media/demo_sample.png: the shipped sample's two cameras and the action chunk this package served for it, next to the fp32 CPU reference and the official LeRobot fp32 output of the same request (host only; matplotlib). python code/scripts/make_demo.py --response --out media/demo_sample.png ``--response``: e.g. the ``--out`` file of ``server/smoke_test.py``, or ``sample_response`` of the stress-gate log. """ from __future__ import annotations import argparse import json import sys from pathlib import Path CODE = Path(__file__).resolve().parents[1] sys.path.insert(0, str(CODE)) def main() -> int: ap = argparse.ArgumentParser(description=__doc__.split("\n\n")[0]) ap.add_argument("--response", required=True, type=Path) ap.add_argument("--out", required=True, type=Path) a = ap.parse_args() import matplotlib matplotlib.use("Agg") import matplotlib.pyplot as plt import numpy as np from PIL import Image from tt_vla_jepa.api import SAMPLE_DIR body = json.loads(a.response.read_text()) body = body.get("sample_response", body) ref = json.loads((SAMPLE_DIR / "reference.json").read_text()) meta = json.loads((SAMPLE_DIR / "sample.json").read_text()) dev = np.array(body["actions_normalized"]) cpu = np.array(ref["actions_normalized"]) off = np.array(ref["official_fp32"]["actions_normalized"]) cams = [Image.open(SAMPLE_DIR / meta[k]["file"]).convert("RGB") for k in ("observation.images.image", "observation.images.wrist_image")] fig = plt.figure(figsize=(13, 5.2), dpi=110) gs = fig.add_gridspec(2, 5, width_ratios=[1.15, 1, 1, 1, 1], hspace=0.45, wspace=0.35) for i, (im, name) in enumerate(zip(cams, ("camera 1 (exterior_1_left)", "camera 2 (exterior_2_left)"))): ax = fig.add_subplot(gs[i, 0]) ax.imshow(im) ax.set_title(name, fontsize=9) ax.axis("off") steps = np.arange(dev.shape[0]) labels = [f"value {j}" for j in range(6)] + ["value 6 (gripper)"] for j in range(7): ax = fig.add_subplot(gs[j // 4, 1 + j % 4]) ax.plot(steps, off[:, j], "o", color="#999999", ms=5, label="official LeRobot fp32 (CPU)") ax.plot(steps, cpu[:, j], "-", color="#1f77b4", lw=1.6, label="fp32 CPU reference") ax.plot(steps, dev[:, j], "--", color="#d62728", lw=1.6, label="this package (p150)") if j == 6: ax.axhline(0.5, color="#555555", lw=0.8, ls=":") ax.set_title(labels[j], fontsize=9) ax.tick_params(labelsize=7) ax.set_xticks(steps) ax = fig.add_subplot(gs[1, 4]) ax.axis("off") err = np.abs(dev - off) ax.text(0.0, 0.95, f"7-step chunk, normalised actions\nseed 0, prompt bucket {body.get('prompt_bucket')}\n\n" f"max |p150 - official fp32|:\n arm (values 0-5) {err[:, :6].max():.4f}\n gripper {err[:, 6].max():.4f}\n\n" f"x: future step 0-6\neach panel has its own\ny scale\n\ndotted line: gripper snap\nthreshold 0.5", fontsize=8, va="top", family="monospace") h, lab = fig.axes[2].get_legend_handles_labels() fig.legend(h, lab, loc="lower center", ncol=3, fontsize=8, frameon=False) fig.suptitle(f"VLA-JEPA (lerobot/VLA-JEPA-Pretrain): \"{meta['task']}\"", fontsize=10) a.out.parent.mkdir(parents=True, exist_ok=True) fig.savefig(a.out, bbox_inches="tight") print(f"wrote {a.out}") return 0 if __name__ == "__main__": sys.exit(main())