Add hdppo-InvertedDoublePendulum-v5 package (weights, code, model card)
Browse files- README.md +1 -0
- record_video.py +42 -44
- replay.mp4 +0 -0
README.md
CHANGED
|
@@ -107,6 +107,7 @@ python train_hdppo.py
|
|
| 107 |
|------|-------------|
|
| 108 |
| `hdppo-InvertedDoublePendulum-v5/weights.npz` | Published actor (+ critic if HD) and FPE encoder (D=64) |
|
| 109 |
| `hdppo-InvertedDoublePendulum-v5/weights_D512_teacher.npz` | Teacher checkpoint (D=512) |
|
|
|
|
| 110 |
| `results.json` | Evaluation summary for the published checkpoint |
|
| 111 |
| `results_D512_teacher.json` | Evaluation summary for the teacher |
|
| 112 |
| `config.yml` | Training hyperparameters |
|
|
|
|
| 107 |
|------|-------------|
|
| 108 |
| `hdppo-InvertedDoublePendulum-v5/weights.npz` | Published actor (+ critic if HD) and FPE encoder (D=64) |
|
| 109 |
| `hdppo-InvertedDoublePendulum-v5/weights_D512_teacher.npz` | Teacher checkpoint (D=512) |
|
| 110 |
+
| `replay.mp4` | Sample rollout video from the published min-D checkpoint |
|
| 111 |
| `results.json` | Evaluation summary for the published checkpoint |
|
| 112 |
| `results_D512_teacher.json` | Evaluation summary for the teacher |
|
| 113 |
| `config.yml` | Training hyperparameters |
|
record_video.py
CHANGED
|
@@ -1,44 +1,42 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
env_kwargs =
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
if __name__ == "__main__":
|
| 44 |
-
main()
|
|
|
|
| 1 |
+
import argparse
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
import gymnasium as gym
|
| 5 |
+
import imageio.v2 as imageio
|
| 6 |
+
|
| 7 |
+
from enjoy import load_policy_from_checkpoint
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def record(weights_path, output_path, seed=42, max_steps=1000):
|
| 11 |
+
encoder, actor, cfg = load_policy_from_checkpoint(weights_path, seed=seed)
|
| 12 |
+
env_kwargs = dict(cfg.get("env_kwargs", {}))
|
| 13 |
+
env_kwargs["render_mode"] = "rgb_array"
|
| 14 |
+
env = gym.make("InvertedDoublePendulum-v5", **env_kwargs)
|
| 15 |
+
frames = []
|
| 16 |
+
obs, _ = env.reset(seed=seed)
|
| 17 |
+
for _ in range(max_steps):
|
| 18 |
+
Hr, Hi = encoder.encode(obs)
|
| 19 |
+
action = actor.greedy_action_np(Hr, Hi)
|
| 20 |
+
obs, reward, term, trunc, _ = env.step(action)
|
| 21 |
+
frames.append(env.render())
|
| 22 |
+
if term or trunc:
|
| 23 |
+
break
|
| 24 |
+
env.close()
|
| 25 |
+
os.makedirs(os.path.dirname(output_path) or ".", exist_ok=True)
|
| 26 |
+
imageio.mimsave(output_path, frames, fps=30)
|
| 27 |
+
return len(frames)
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def main():
|
| 31 |
+
parser = argparse.ArgumentParser(description="Record InvertedDoublePendulum-v5 replay video")
|
| 32 |
+
parser.add_argument("--weights", default="hdppo-InvertedDoublePendulum-v5/weights.npz")
|
| 33 |
+
parser.add_argument("--output", default="replay.mp4")
|
| 34 |
+
parser.add_argument("--seed", type=int, default=42)
|
| 35 |
+
parser.add_argument("--max-steps", type=int, default=1000)
|
| 36 |
+
args = parser.parse_args()
|
| 37 |
+
n = record(args.weights, args.output, seed=args.seed, max_steps=args.max_steps)
|
| 38 |
+
print(f"saved {n} frames to {args.output}")
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
if __name__ == "__main__":
|
| 42 |
+
main()
|
|
|
|
|
|
replay.mp4
ADDED
|
Binary file (58.2 kB). View file
|
|
|