PPO Agent playing LunarLander-v3

This is a trained model of a PPO agent playing LunarLander-v3 using the stable-baselines3 library.

Usage (with Stable-Baselines3)

Install the required libraries:

pip install stable-baselines3 huggingface-sb3 "gymnasium[box2d]"

Load the trained PPO agent from the Hugging Face Hub:

import os
import gymnasium as gym

from stable_baselines3 import PPO
from stable_baselines3.common.evaluation import evaluate_policy
from huggingface_sb3 import load_from_hub

# Required by huggingface_sb3 when loading the model
# Only enable this for repositories you trust
os.environ["TRUST_REMOTE_CODE"] = "True"

# Download the trained model
checkpoint = load_from_hub(
    repo_id="roshana1s/ppo-LunarLander-v3",
    filename="ppo-LunarLander-v3.zip",
)

# Load the PPO model
model = PPO.load(checkpoint)

# Create the LunarLander environment
env = gym.make("LunarLander-v3")

# Evaluate the agent
mean_reward, std_reward = evaluate_policy(
    model,
    env,
    n_eval_episodes=10,
    deterministic=True
)

print(f"Mean reward: {mean_reward:.2f} +/- {std_reward:.2f}")

env.close()

Run the Agent

env = gym.make("LunarLander-v3", render_mode="human")

obs, info = env.reset()

terminated = False
truncated = False

while not (terminated or truncated):
    action, _ = model.predict(obs, deterministic=True)
    obs, reward, terminated, truncated, info = env.step(action)

env.close()
Downloads last month
28
Video Preview
loading

Evaluation results