Neanderthal commited on
Commit
d8a57e2
1 Parent(s): 363e2e7

Create LunarLander-v2.py

Browse files
Files changed (1) hide show
  1. LunarLander-v2.py +26 -0
LunarLander-v2.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gym
2
+
3
+ from huggingface_sb3 import load_from_hub
4
+ from stable_baselines3 import PPO
5
+ from stable_baselines3.common.evaluation import evaluate_policy
6
+
7
+ # Retrieve the model from the hub
8
+ ## repo_id = id of the model repository from the Hugging Face Hub (repo_id = {organization}/{repo_name})
9
+ ## filename = name of the model zip file from the repository
10
+ checkpoint = load_from_hub(repo_id="ThomasSimonini/ppo-LunarLander-v2", filename="ppo-LunarLander-v2.zip")
11
+ model = PPO.load(checkpoint)
12
+
13
+ # Evaluate the agent
14
+ eval_env = gym.make('LunarLander-v2')
15
+ mean_reward, std_reward = evaluate_policy(model, eval_env, n_eval_episodes=10, deterministic=True)
16
+ print(f"mean_reward={mean_reward:.2f} +/- {std_reward}")
17
+
18
+ # Watch the agent play
19
+ obs = eval_env.reset()
20
+ for i in range(1000):
21
+ action, _state = model.predict(obs)
22
+ obs, reward, done, info = eval_env.step(action)
23
+ eval_env.render()
24
+ if done:
25
+ obs = eval_env.reset()
26
+ eval_env.close()