Reinforcement Learning
stable-baselines3
LunarLander-v2
deep-reinforcement-learning
Eval Results (legacy)
Instructions to use lushy/ppo-LunarLander-v2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- stable-baselines3
How to use lushy/ppo-LunarLander-v2 with stable-baselines3:
from huggingface_sb3 import load_from_hub checkpoint = load_from_hub( repo_id="lushy/ppo-LunarLander-v2", filename="{MODEL FILENAME}.zip", ) - Notebooks
- Google Colab
- Kaggle
PPO Agent playing LunarLander-v2
This is a trained model of a PPO agent playing LunarLander-v2 using the stable-baselines3 library.
Usage (with Stable-baselines3)
The code below downloads the model and runs 3 episodes and saves the videos to "lunar_lander_videos/".
import gymnasium as gym
from stable_baselines3 import PPO
from huggingface_hub import hf_hub_download
import imageio
import os
# Configuration
MODEL_REPO = "lushy/ppo-LunarLander-v2"
OUTPUT_DIR = "lunar_lander_videos"
NUM_EPISODES = 3
VIDEO_FPS = 30
# Create output directory
os.makedirs(OUTPUT_DIR, exist_ok=True)
# Download and load model from Hugging Face
print("Loading model from Hugging Face...")
model_path = hf_hub_download(repo_id=MODEL_REPO, filename="ppo-LunarLander-v2.zip")
model = PPO.load(model_path)
# Create environment
print("Creating Lunar Lander environment...")
env = gym.make("LunarLander-v3", render_mode="rgb_array")
# Record all episodes into one list
all_frames = []
for episode in range(NUM_EPISODES):
print(f"\nRecording episode {episode + 1}/{NUM_EPISODES}...")
observation, info = env.reset()
episode_reward = 0
done = False
while not done:
# Render frame
frame = env.render()
if frame is not None:
# Resize frame to 1080p
import cv2
frame = cv2.resize(frame, (VIDEO_WIDTH, VIDEO_HEIGHT))
all_frames.append(frame)
# Get action from model
action, _ = model.predict(observation, deterministic=True)
# Step environment
observation, reward, terminated, truncated, info = env.step(action)
episode_reward += reward
done = terminated or truncated
print(f"Episode {episode + 1} reward: {episode_reward:.2f}")
# Save all episodes as one video
video_path = os.path.join(OUTPUT_DIR, "lunar_lander_all_episodes.mp4")
print(f"\nSaving combined video to {video_path}...")
imageio.mimsave(video_path, all_frames, fps=VIDEO_FPS, codec='libx264', pixelformat='yuv420p')
env.close()
print(f"Video saved to {OUTPUT_DIR}/lunar_lander_all_episodes.mp4")
- Downloads last month
- -
Evaluation results
- mean_reward on LunarLander-v2self-reported283.01 +/- 19.15