Add landing videos (mp4 + gif) and record_video.py; embed in model card
Browse files- .gitattributes +2 -0
- README.md +14 -0
- lunarlander-14params.gif +3 -0
- lunarlander-14params.mp4 +3 -0
- record_video.py +77 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
lunarlander-14params.gif filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
lunarlander-14params.mp4 filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
|
@@ -25,6 +25,18 @@ symmetry of the environment (`x -> -x`, `vx -> -vx`, `angle -> -angle`,
|
|
| 25 |
are self-paired). The 14 parameters live in `model.safetensors` as `sym_theta` (shape `(14,)`);
|
| 26 |
`model.py` materialises the 8x4 matrix at load time, so the model really has 14 parameters.
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
## Evaluation
|
| 29 |
|
| 30 |
Deterministic greedy policy; "landing" and "crash" are the environment's own terminal `+100` / `-100`
|
|
@@ -73,6 +85,8 @@ while not done:
|
|
| 73 |
| `model.safetensors` | the 14 weights (`sym_theta`, shape `(14,)`) |
|
| 74 |
| `config.json` | architecture and environment metadata |
|
| 75 |
| `verify.py` | structural checks and live Gymnasium evaluation |
|
|
|
|
|
|
|
| 76 |
| `requirements.txt` | dependencies |
|
| 77 |
|
| 78 |
## License
|
|
|
|
| 25 |
are self-paired). The 14 parameters live in `model.safetensors` as `sym_theta` (shape `(14,)`);
|
| 26 |
`model.py` materialises the 8x4 matrix at load time, so the model really has 14 parameters.
|
| 27 |
|
| 28 |
+
## Landing
|
| 29 |
+
|
| 30 |
+
Greedy landings recorded from the environment (three episodes, returns 294.4 / 287.1 / 272.9):
|
| 31 |
+
|
| 32 |
+
<video controls autoplay loop muted style="max-width: 600px">
|
| 33 |
+
<source src="lunarlander-14params.mp4" type="video/mp4" />
|
| 34 |
+
</video>
|
| 35 |
+
|
| 36 |
+
Single episode as an animated GIF:
|
| 37 |
+
|
| 38 |
+

|
| 39 |
+
|
| 40 |
## Evaluation
|
| 41 |
|
| 42 |
Deterministic greedy policy; "landing" and "crash" are the environment's own terminal `+100` / `-100`
|
|
|
|
| 85 |
| `model.safetensors` | the 14 weights (`sym_theta`, shape `(14,)`) |
|
| 86 |
| `config.json` | architecture and environment metadata |
|
| 87 |
| `verify.py` | structural checks and live Gymnasium evaluation |
|
| 88 |
+
| `record_video.py` | records `lunarlander-14params.mp4` / `.gif` (headless, `rgb_array`) |
|
| 89 |
+
| `lunarlander-14params.mp4`, `.gif` | landing videos (3 episodes / 1 episode) |
|
| 90 |
| `requirements.txt` | dependencies |
|
| 91 |
|
| 92 |
## License
|
lunarlander-14params.gif
ADDED
|
Git LFS Details
|
lunarlander-14params.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:75e56098f831992dd2034c1ef5b964f9acfc92ca274cbb9ed25ab192f4da0547
|
| 3 |
+
size 404926
|
record_video.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Record landing videos of the 14-parameter LunarLander policy (headless).
|
| 3 |
+
|
| 4 |
+
Writes `lunarlander-14params.mp4` (a few episodes) and `lunarlander-14params.gif`
|
| 5 |
+
(one episode, downscaled) next to this file.
|
| 6 |
+
"""
|
| 7 |
+
import os
|
| 8 |
+
|
| 9 |
+
os.environ.setdefault("SDL_VIDEODRIVER", "dummy")
|
| 10 |
+
os.environ.setdefault("SDL_AUDIODRIVER", "dummy")
|
| 11 |
+
|
| 12 |
+
import numpy as np
|
| 13 |
+
import gymnasium as gym
|
| 14 |
+
import imageio.v2 as imageio
|
| 15 |
+
|
| 16 |
+
from model import TinyLunarPolicy
|
| 17 |
+
|
| 18 |
+
FPS = 50
|
| 19 |
+
N_MP4_EPISODES = 3
|
| 20 |
+
HERE = os.path.dirname(os.path.abspath(__file__))
|
| 21 |
+
SEEDS = [40122, 42940, 51305, 55316, 60944, 61197, 93978, 96327, 103680, 157789]
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def record(policy, n_episodes, min_return=250.0):
|
| 25 |
+
env = gym.make("LunarLander-v3", render_mode="rgb_array")
|
| 26 |
+
clips = []
|
| 27 |
+
for seed in SEEDS:
|
| 28 |
+
for ep in range(100):
|
| 29 |
+
o, _ = env.reset(seed=seed * 1000 + ep)
|
| 30 |
+
frames, tot, last, term, trunc = [], 0.0, 0.0, False, False
|
| 31 |
+
frames.append(env.render())
|
| 32 |
+
while not (term or trunc):
|
| 33 |
+
o, r, term, trunc, _ = env.step(policy.act(o))
|
| 34 |
+
tot += r
|
| 35 |
+
last = r
|
| 36 |
+
frames.append(env.render())
|
| 37 |
+
if term and not trunc and last == 100.0 and tot >= min_return:
|
| 38 |
+
clips.append((seed, ep, tot, frames))
|
| 39 |
+
print(" клип: seed %d ep %d возврат %.1f кадров %d" % (seed, ep, tot, len(frames)),
|
| 40 |
+
flush=True)
|
| 41 |
+
if len(clips) >= n_episodes:
|
| 42 |
+
env.close()
|
| 43 |
+
return clips
|
| 44 |
+
env.close()
|
| 45 |
+
return clips
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def main():
|
| 49 |
+
policy = TinyLunarPolicy.from_safetensors(os.path.join(HERE, "model.safetensors"))
|
| 50 |
+
print("запись эпизодов...", flush=True)
|
| 51 |
+
clips = record(policy, N_MP4_EPISODES)
|
| 52 |
+
if not clips:
|
| 53 |
+
raise SystemExit("не нашёл подходящих эпизодов")
|
| 54 |
+
|
| 55 |
+
# mp4: склеиваем клипы с короткой белой паузой между ними
|
| 56 |
+
white = np.full_like(clips[0][3][0], 255)
|
| 57 |
+
frames = []
|
| 58 |
+
for i, (s, e, r, fr) in enumerate(clips):
|
| 59 |
+
frames += fr
|
| 60 |
+
frames += [white] * 15
|
| 61 |
+
mp4 = os.path.join(HERE, "lunarlander-14params.mp4")
|
| 62 |
+
with imageio.get_writer(mp4, fps=FPS, codec="libx264", quality=8,
|
| 63 |
+
pixelformat="yuv420p", macro_block_size=8) as w:
|
| 64 |
+
for f in frames:
|
| 65 |
+
w.append_data(np.asarray(f, np.uint8))
|
| 66 |
+
print("saved:", mp4, "| кадров", len(frames), "| ~%.1f c" % (len(frames) / FPS))
|
| 67 |
+
|
| 68 |
+
# gif: один клип, уменьшенный вдвое и 25 fps
|
| 69 |
+
fr = clips[0][3]
|
| 70 |
+
small = [np.asarray(f, np.uint8)[::2, ::2] for f in fr[::2]]
|
| 71 |
+
gif = os.path.join(HERE, "lunarlander-14params.gif")
|
| 72 |
+
imageio.mimsave(gif, small, fps=25)
|
| 73 |
+
print("saved:", gif, "| кадров", len(small), "| размер", small[0].shape)
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
if __name__ == "__main__":
|
| 77 |
+
main()
|