Buckets:
| """Frame collage of one episode with each reward model's progress curve beside it. | |
| One row per reward model: the same 5 overhead frames, and that model's progress for the whole | |
| episode on the right. Layout follows the VLAC-style figure (frames left, curve right). | |
| Values are read from what the video scripts already wrote under final_videos/: | |
| <model>_raw/episode_XXXXXX/pred.npy per-frame prediction (make_sarm2_video.py, model mode) | |
| <model>_spiral/episode_XXXXXX/reward.npy the progress column SPIRAL trains on | |
| Usage (from Thesis_Code/): | |
| Thesis/.venv/bin/python opensarm/tools/make_reward_collage.py --episode 18 \ | |
| --frames 0 141 231 348 545 | |
| """ | |
| import argparse | |
| from pathlib import Path | |
| import cv2 | |
| import matplotlib.pyplot as plt | |
| import numpy as np | |
| from matplotlib.patches import FancyBboxPatch | |
| FPS = 15 | |
| ROOT = Path(__file__).resolve().parents[1] / "final_videos" | |
| VIDEO = (Path.home() / ".cache/huggingface/lerobot/local/teleop57_daggerrlt1_v21/videos/chunk-000/" | |
| "observation.images.left_top/episode_{:06d}.mp4") | |
| # teleop57_daggerrlt1_v21 holds the 57 teleop demos first, so DAgger episode e is episode 57 + e. | |
| DAGGER_OFFSET = 57 | |
| BLUE, ORANGE = "#2a78d6", "#eb6834" | |
| ROWS = [ # folder, file, title, colour | |
| ("rm1_raw", "pred.npy", "RM1: raw per-frame prediction", BLUE), | |
| ("rm2_raw", "pred.npy", "RM2: raw per-frame prediction", ORANGE), | |
| ("rm1_spiral", "reward.npy", "RM1: progress label used by SPIRAL", BLUE), | |
| ("rm2_spiral", "reward.npy", "RM2: progress label used by SPIRAL", ORANGE), | |
| ] | |
| def read_frames(path, indices): | |
| cap = cv2.VideoCapture(str(path)) | |
| out = [] | |
| for i in indices: | |
| cap.set(cv2.CAP_PROP_POS_FRAMES, i) | |
| ok, img = cap.read() | |
| if not ok: | |
| raise RuntimeError(f"cannot read frame {i} of {path}") | |
| out.append(cv2.cvtColor(img, cv2.COLOR_BGR2RGB)) | |
| return out | |
| def main(): | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("--episode", type=int, default=18) | |
| ap.add_argument("--frames", type=int, nargs=5, default=[0, 141, 231, 348, 545]) | |
| ap.add_argument("--task", default="Fold the long sleeved T-shirt on the table") | |
| ap.add_argument("--labels", nargs=5, default=None, | |
| help="stage name under each frame, e.g. 'flat' 'first sleeve in' ...") | |
| ap.add_argument("--out", default=None) | |
| args = ap.parse_args() | |
| ep = f"episode_{args.episode:06d}" | |
| frames = read_frames(Path(str(VIDEO).format(DAGGER_OFFSET + args.episode)), args.frames) | |
| curves = [(np.load(ROOT / d / ep / f), t, c) for d, f, t, c in ROWS] | |
| n = len(ROWS) | |
| fig = plt.figure(figsize=(13, 2.15 * n + 0.9), dpi=200) | |
| fig.patch.set_facecolor("white") | |
| # left block: 5 frames per row; right block: one curve per row | |
| left, right = 0.015, 0.78 | |
| top, bot = 0.92, 0.065 | |
| row_h = (top - bot) / n | |
| fw = (right - left - 0.03) / 5 | |
| fig.text((left + right) / 2, 0.965, f"Task: {args.task}", ha="center", va="center", | |
| fontsize=13, style="italic") | |
| for r, (y, title, color) in enumerate(curves): | |
| y0 = top - (r + 1) * row_h | |
| # tinted box behind the frames | |
| # the last row carries the frame captions underneath, so its box reaches lower | |
| ext = (0.035 if args.labels else 0.012) if r == n - 1 else 0.0 | |
| box = FancyBboxPatch((left, y0 + 0.012 - ext), right - left, row_h - 0.02 + ext, | |
| boxstyle="round,pad=0.002,rounding_size=0.008", | |
| transform=fig.transFigure, facecolor=color, alpha=0.08, | |
| edgecolor=color, linewidth=1.2) | |
| fig.patches.append(box) | |
| fig.text(left + 0.008, y0 + row_h - 0.022, title, fontsize=10.5, weight="bold", | |
| color="#222222", va="center") | |
| fig.text(right - 0.008, y0 + row_h - 0.022, f"final progress {y[-1]:.2f}", fontsize=9.5, | |
| color="#444444", va="center", ha="right") | |
| for k, img in enumerate(frames): | |
| ax = fig.add_axes([left + 0.015 + k * fw, y0 + 0.03, fw - 0.006, row_h - 0.075]) | |
| ax.imshow(img) | |
| ax.set_xticks([]); ax.set_yticks([]) | |
| for s in ax.spines.values(): | |
| s.set_edgecolor("#bbbbbb"); s.set_linewidth(0.6) | |
| if r == n - 1: | |
| cap = f"t = {args.frames[k] / FPS:.1f} s" | |
| if args.labels: | |
| cap = f"{args.labels[k]}\n{cap}" | |
| ax.set_xlabel(cap, fontsize=9, color="#444444") | |
| ax = fig.add_axes([right + 0.04, y0 + 0.04, 0.17, row_h - 0.085]) | |
| t = np.arange(len(y)) / FPS | |
| ax.plot(t, y, color=color, linewidth=2) | |
| ax.set_ylim(-0.05, 1.05); ax.set_xlim(0, t[-1]) | |
| ax.set_yticks([0, 0.5, 1.0]) | |
| ax.tick_params(labelsize=8, colors="#555555") | |
| ax.grid(color="#e6e6e6", linewidth=0.6) | |
| for s in ("top", "right"): | |
| ax.spines[s].set_visible(False) | |
| for s in ("left", "bottom"): | |
| ax.spines[s].set_color("#999999") | |
| ax.set_ylabel("Progress", fontsize=8.5, color="#444444") | |
| if r == n - 1: | |
| ax.set_xlabel("time (s)", fontsize=8.5, color="#444444") | |
| out = Path(args.out) if args.out else ROOT / f"collage_{ep}.png" | |
| fig.savefig(out, facecolor="white") | |
| fig.savefig(out.with_suffix(".pdf"), facecolor="white") | |
| print(out, out.with_suffix(".pdf")) | |
| if __name__ == "__main__": | |
| main() | |
Xet Storage Details
- Size:
- 5.4 kB
- Xet hash:
- 7634da849bb83209793ab7dc8957004f09bec218b4e3aae4a9f30bbdc817d70b
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.