Jeroen Van Goey commited on
Commit
291684e
1 Parent(s): 0db9094

Add code to README

Browse files
Files changed (1) hide show
  1. README.md +24 -2
README.md CHANGED
@@ -29,8 +29,30 @@ TODO: Add your code
29
 
30
 
31
  ```python
32
- from stable_baselines3 import ...
 
33
  from huggingface_sb3 import load_from_hub
 
 
 
 
 
 
 
 
34
 
35
- ...
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  ```
 
29
 
30
 
31
  ```python
32
+ import gym
33
+
34
  from huggingface_sb3 import load_from_hub
35
+ from stable_baselines3 import PPO
36
+ from stable_baselines3.common.evaluation import evaluate_policy
37
+
38
+ # Retrieve the model from the hub
39
+ ## repo_id = id of the model repository from the Hugging Face Hub (repo_id = {organization}/{repo_name})
40
+ ## filename = name of the model zip file from the repository
41
+ checkpoint = load_from_hub(repo_id="BioGeek/PPO-LunarLander-v2", filename="ppo-LunarLander-v2.zip")
42
+ model = PPO.load(checkpoint)
43
 
44
+ # Evaluate the agent
45
+ eval_env = gym.make('LunarLander-v2')
46
+ mean_reward, std_reward = evaluate_policy(model, eval_env, n_eval_episodes=10, deterministic=True)
47
+ print(f"mean_reward={mean_reward:.2f} +/- {std_reward}")
48
+
49
+ # Watch the agent play
50
+ obs = eval_env.reset()
51
+ for i in range(1000):
52
+ action, _state = model.predict(obs)
53
+ obs, reward, done, info = eval_env.step(action)
54
+ eval_env.render()
55
+ if done:
56
+ obs = eval_env.reset()
57
+ eval_env.close()
58
  ```