Trained PPO agent on
LunarLander-v2 (Gymnasium) as part of the
Hugging Face Deep RL Course — Unit 1.
1from stable_baselines3 import PPO
2from stable_baselines3.common.vec_env import DummyVecEnv, VecNormalize
3from stable_baselines3.common.monitor import Monitor
4from huggingface_hub import hf_hub_download
5import gymnasium as gym
6
7# Load model
8model = PPO.load(hf_hub_download("muhrivandysetiawan/ppo-LunarLander-v2", "PPO-LunarLander-v2.zip"))
9
10# Load normalization stats
11vec_path = hf_hub_download("muhrivandysetiawan/ppo-LunarLander-v2", "vec_normalize.pkl")
12eval_env = DummyVecEnv([lambda: Monitor(gym.make("LunarLander-v2", render_mode="rgb_array"))])
13eval_env = VecNormalize.load(vec_path, eval_env)
14eval_env.training = False
15eval_env.norm_reward = False
16
17obs = eval_env.reset()
18done = False
19while not done:
20 action, _ = model.predict(obs, deterministic=True)
21 obs, reward, done, info = eval_env.step(action)