kingabzpro commited on
Commit
d6ef1ff
1 Parent(s): add9e4d

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +35 -1
README.md CHANGED
@@ -24,5 +24,39 @@ model-index:
24
  This is a trained model of a **PPO** agent playing **MountainCar-v0** using the [stable-baselines3 library](https://github.com/DLR-RM/stable-baselines3).
25
 
26
  ## Usage (with Stable-baselines3)
27
- TODO: Add your code
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
 
 
24
  This is a trained model of a **PPO** agent playing **MountainCar-v0** using the [stable-baselines3 library](https://github.com/DLR-RM/stable-baselines3).
25
 
26
  ## Usage (with Stable-baselines3)
27
+ Using this model becomes easy when you have stable-baselines3 and huggingface_sb3 installed:
28
+ ```
29
+ pip install stable-baselines3
30
+ pip install huggingface_sb3
31
+ ```
32
+ Then, you can use the model like this:
33
+ ```python
34
+ import gym
35
+
36
+ from huggingface_sb3 import load_from_hub
37
+ from stable_baselines3 import PPO
38
+ from stable_baselines3.common.evaluation import evaluate_policy
39
+
40
+ # Retrieve the model from the hub
41
+ ## repo_id = id of the model repository from the Hugging Face Hub (repo_id = {organization}/{repo_name})
42
+ ## filename = name of the model zip file from the repository
43
+ checkpoint = load_from_hub(repo_id="kingabzpro/Full-Force-MountainCar-v0", filename="Full-Force-MountainCar-v0.zip")
44
+ model = PPO.load(checkpoint)
45
+
46
+ # Evaluate the agent
47
+ eval_env = gym.make('MountainCar-v0')
48
+ mean_reward, std_reward = evaluate_policy(model, eval_env, n_eval_episodes=10, deterministic=True)
49
+ print(f"mean_reward={mean_reward:.2f} +/- {std_reward}")
50
+
51
+ # Watch the agent play
52
+ obs = eval_env.reset()
53
+ for i in range(1000):
54
+ action, _state = model.predict(obs)
55
+ obs, reward, done, info = eval_env.step(action)
56
+ eval_env.render()
57
+ if done:
58
+ obs = eval_env.reset()
59
+ eval_env.close()
60
+ ```
61
+
62