Views
No views yet
!pip install stable-baselines3 gymnasium huggingface_sb3 shimmy1from huggingface_sb3 import load_from_hub
2from stable_baselines3 import PPO
3import gymnasium as gym
4
5# Download model
6repo_id = "ashaduzzaman/ppo-LunarLander-v2" # Replace with your repo
7filename = "ppo-LunarLander-v2.zip"
8checkpoint = load_from_hub(repo_id, filename)
9
10# Load model with compatibility settings
11custom_objects = {
12 "learning_rate": 0.0,
13 "lr_schedule": lambda _: 0.0,
14 "clip_range": lambda _: 0.0,
15}
16model = PPO.load(checkpoint, custom_objects=custom_objects)
17
18# Evaluate
19from stable_baselines3.common.evaluation import evaluate_policy
20eval_env = gym.make("LunarLander-v2")
21mean_reward, std_reward = evaluate_policy(model, eval_env, n_eval_episodes=10)
22print(f"Mean reward: {mean_reward:.2f} ± {std_reward:.2f}")1PPO(
2 policy="MlpPolicy",
3 n_steps=1024,
4 batch_size=64,
5 n_epochs=4,
6 gamma=0.999,
7 gae_lambda=0.98,
8 ent_coef=0.01,
9 learning_rate=0.00025,
10 verbose=1
11)| Metric | Value |
|---|---|
| Mean Reward | 257.67 |
| Std Reward | 24.70 |
| Success Rate | 100% |
| Avg Episode Length | 270 steps |
result = mean_reward - std_reward = 257.67 - 24.70 = 232.97