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