ChirathD commited on
Commit
34ff700
·
verified ·
1 Parent(s): 1dbe253

Add hdppo-Pendulum-v1 package (weights, code, model card)

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