Views
No views yet
1from huggingface_sb3 import load_from_hub
2
3from stable_baselines3.common.env_util import make_vec_env
4from stable_baselines3 import PPO
5from stable_baselines3.common.evaluation import evaluate_policy
6
7model_checkpoint = load_from_hub( # Download model from the hub
8 repo_id="mriusero/ppo-LunarLander-v2",
9 filename="ppo-LunarLander-v2.zip",
10)
11env = make_vec_env("LunarLander-v2", n_envs=1) # Create a vectorized environment
12model = PPO.load(model_checkpoint, env=env) # Load the model
13
14print("Evaluating model") # Evaluate the model
15mean_reward, std_reward = evaluate_policy(
16 model,
17 env,
18 n_eval_episodes=10,
19 deterministic=True,
20)
21print(f"Mean reward = {mean_reward:.2f} +/- {std_reward}")
22