epsil commited on
Commit
0672a4f
1 Parent(s): fe36401

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +34 -2
README.md CHANGED
@@ -24,7 +24,39 @@ model-index:
24
  This is a trained model of a **PPO** agent playing **LunarLander-v2** using the [stable-baselines3 library](https://github.com/DLR-RM/stable-baselines3).
25
 
26
  ## Usage (with Stable-baselines3)
27
- Created by Saurabh Mishra
28
 
29
- Made with ♥ in India
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
 
24
  This is a trained model of a **PPO** agent playing **LunarLander-v2** using the [stable-baselines3 library](https://github.com/DLR-RM/stable-baselines3).
25
 
26
  ## Usage (with Stable-baselines3)
27
+ ```
28
 
29
+ import gym
30
+
31
+ from huggingface_sb3 import load_from_hub
32
+ from stable_baselines3 import PPO
33
+ from stable_baselines3.common.evaluation import evaluate_policy
34
+
35
+ # Retrieve the model from the hub
36
+ ## repo_id = id of the model repository from the Hugging Face Hub (repo_id = {organization}/{repo_name})
37
+ ## filename = name of the model zip file from the repository
38
+ checkpoint = load_from_hub(repo_id="epsil/ppo-LunarLander-v2", filename="ppo-LunarLander-v2.zip")
39
+
40
+ model = PPO.load(checkpoint)
41
+
42
+ # Evaluate the agent
43
+ eval_env = gym.make('LunarLander-v2')
44
+ mean_reward, std_reward = evaluate_policy(model, eval_env, n_eval_episodes=10, deterministic=True)
45
+ print(f"mean_reward={mean_reward:.2f} +/- {std_reward}")
46
+
47
+ # Watch the agent play
48
+ obs = eval_env.reset()
49
+ for i in range(1000):
50
+ action, _state = model.predict(obs)
51
+ obs, reward, done, info = eval_env.step(action)
52
+ eval_env.render()
53
+ if done:
54
+ obs = eval_env.reset()
55
+ eval_env.close()
56
+
57
+ ```
58
+
59
+ ### Created by Saurabh Mishra
60
+
61
+ Made with 💖 in India
62