Download robometer/scripts/plot_one_episode.py from Vio1etV/Robustness_of_progress_model: direct link, hf CLI and curl.
- Browser
- Download file 2.73 kB
-
https://huggingface.co/datasets/Vio1etV/Robustness_of_progress_model/resolve/main/robometer/scripts/plot_one_episode.py
- Command line
-
hf download hf://datasets/Vio1etV/Robustness_of_progress_model/robometer/scripts/plot_one_episode.py
-
curl -L -o plot_one_episode.py https://huggingface.co/datasets/Vio1etV/Robustness_of_progress_model/resolve/main/robometer/scripts/plot_one_episode.py
2.73 kB
| #!/usr/bin/env python3 | |
| """Plot the 5 prefix-mode progress curves for a single episode. | |
| Usage: | |
| python plot_one_episode.py chunk-000_episode_000039 | |
| python plot_one_episode.py chunk-000_episode_000039 --out /tmp/x.png | |
| """ | |
| import argparse | |
| import json | |
| from pathlib import Path | |
| import numpy as np | |
| import matplotlib | |
| matplotlib.use("Agg") | |
| import matplotlib.pyplot as plt | |
| MODES = ["uniform", "front_biased", "back_biased", "random_seed0", "random_seed1"] | |
| COLORS = {"uniform": "tab:blue", "front_biased": "tab:orange", | |
| "back_biased": "tab:green", "random_seed0": "tab:red", | |
| "random_seed1": "tab:purple"} | |
| FRACS = ["1/4", "2/4", "3/4", "end"] | |
| p = argparse.ArgumentParser() | |
| p.add_argument("episode_dir", help="e.g. chunk-000_episode_000039") | |
| p.add_argument("--results-root", | |
| default=str(Path(__file__).resolve().parent.parent / "results_full")) | |
| p.add_argument("--out", default=None) | |
| a = p.parse_args() | |
| ep_dir = Path(a.results_root) / "episode_results" / a.episode_dir | |
| out = Path(a.out) if a.out else ep_dir / "curves.png" | |
| data = {} | |
| for m in MODES: | |
| f = ep_dir / f"{m}.json" | |
| if f.exists(): | |
| data[m] = json.loads(f.read_text()) | |
| if not data: | |
| raise SystemExit(f"no mode json found in {ep_dir}") | |
| meta0 = next(iter(data.values())) | |
| n = meta0["pool_n"] | |
| cps = [int((n - 1) * k / 4) for k in (1, 2, 3, 4)] | |
| xs = np.arange(n) # pool frame index | |
| fig, ax = plt.subplots(figsize=(13, 6)) | |
| for m in MODES: | |
| if m not in data: | |
| continue | |
| ax.plot(xs, data[m]["scores_100"], color=COLORS[m], lw=1.6, label=m) | |
| for frac, t in zip(FRACS, cps): | |
| ax.axvline(t, color="0.6", ls=":", lw=1) | |
| ax.text(t, 96, f"{frac} (t={t})", ha="center", fontsize=9, color="0.4") | |
| # secondary axis: original video frame index (pool is downsampled) | |
| raw_per_pool = meta0["total_raw_frames"] / max(n, 1) | |
| sec_ax = ax.secondary_xaxis( | |
| "top", | |
| functions=(lambda i: i * raw_per_pool, lambda r: r / raw_per_pool)) | |
| sec_ax.set_xlabel(f"original video frame index " | |
| f"(raw {meta0['total_raw_frames']} frames @ {meta0['native_fps']:.0f} fps)") | |
| scores = {frac: [data[m]["scores_100"][t] for m in MODES if m in data] | |
| for frac, t in zip(FRACS, cps)} | |
| rngs = ", ".join(f"{frac}: {max(v)-min(v):.1f}" for frac, v in scores.items()) | |
| meta = next(iter(data.values())) | |
| ax.set_title(f"{a.episode_dir} ({meta['camera']}, pool={n})\n" | |
| f"task: {meta['task'][:100]}\nPrefix Range @ checkpoints -> {rngs}", | |
| fontsize=10) | |
| ax.set_xlabel("pool frame index (3fps-downsampled sequence)") | |
| ax.set_xlim(0, n - 1) | |
| ax.set_ylabel("progress score (0-100)") | |
| ax.set_ylim(0, 100) | |
| ax.grid(alpha=0.25) | |
| ax.legend(fontsize=9) | |
| fig.tight_layout() | |
| fig.savefig(out, dpi=140) | |
| print("saved:", out) | |