Download vlac/scripts/plot_one_episode.py from Vio1etV/Robustness_of_progress_model: direct link, hf CLI and curl.
- Browser
- Download file 2.58 kB
-
https://huggingface.co/datasets/Vio1etV/Robustness_of_progress_model/resolve/main/vlac/scripts/plot_one_episode.py
- Command line
-
hf download hf://datasets/Vio1etV/Robustness_of_progress_model/vlac/scripts/plot_one_episode.py
-
curl -L -o plot_one_episode.py https://huggingface.co/datasets/Vio1etV/Robustness_of_progress_model/resolve/main/vlac/scripts/plot_one_episode.py
2.58 kB
| #!/usr/bin/env python3 | |
| """Plot the 5 sampling-path accumulated values (at 4 target frames) for one 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 = ["dense_all", "stride2", "stride4", "front_dense", "back_dense"] | |
| REFERENCE_MODE = "dense_all" | |
| COLORS = {"dense_all": "tab:blue", "stride2": "tab:orange", | |
| "stride4": "tab:green", "front_dense": "tab:red", | |
| "back_dense": "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())) | |
| xt = np.arange(len(FRACS)) | |
| fig, ax = plt.subplots(figsize=(11, 6)) | |
| for m in MODES: | |
| if m not in data: | |
| continue | |
| ys = [data[m]["checkpoints"][frac]["value"] for frac in FRACS] | |
| ax.plot(xt, ys, "-o", color=COLORS[m], lw=1.8, ms=7, label=m) | |
| # gray min-max spread bar at each checkpoint | |
| for i, frac in enumerate(FRACS): | |
| vals = [data[m]["checkpoints"][frac]["value"] for m in MODES if m in data] | |
| ax.plot([i, i], [min(vals), max(vals)], color="0.8", lw=2, zorder=0) | |
| scores = {frac: [data[m]["checkpoints"][frac]["value"] for m in MODES if m in data] | |
| for frac in FRACS} | |
| rngs = ", ".join(f"{frac}: {max(v)-min(v):.1f}" for frac, v in scores.items()) | |
| ax.set_xticks(xt) | |
| ax.set_xticklabels([f"{frac}\n(t={meta0['checkpoints'][frac]['target_t']})" for frac in FRACS]) | |
| ax.set_title(f"{a.episode_dir} ({meta0['camera']}, seq={meta0['pool_n']} @ " | |
| f"{meta0['compressed_fps']:.0f}fps/{meta0['target_size'][0]}px)\n" | |
| f"task: {meta0['task'][:100]}\nPrefix Range @ checkpoints -> {rngs}", | |
| fontsize=10) | |
| ax.set_xlabel("target frame (checkpoint)") | |
| ax.set_ylabel("accumulated value (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) | |