Update README.md
Browse files
README.md
CHANGED
@@ -30,8 +30,32 @@ TODO: Add your code
|
|
30 |
|
31 |
|
32 |
```python
|
33 |
-
|
|
|
|
|
|
|
|
|
34 |
from huggingface_sb3 import load_from_hub
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
...
|
37 |
```
|
|
|
30 |
|
31 |
|
32 |
```python
|
33 |
+
import gymnasium
|
34 |
+
from stable_baselines3 import PPO
|
35 |
+
from stable_baselines3.common.env_util import make_vec_env
|
36 |
+
from stable_baselines3.common.evaluation import evaluate_policy
|
37 |
+
from stable_baselines3.common.monitor import Monitor
|
38 |
from huggingface_sb3 import load_from_hub
|
39 |
|
40 |
+
repo_id = "AdanLee/ppo-LunarLander-v2" # The repo_id
|
41 |
+
filename = "ppo-LunarLander-v2.zip" # The model filename.zip
|
42 |
+
|
43 |
+
# When the model was trained on Python 3.8 the pickle protocol is 5
|
44 |
+
# But Python 3.6, 3.7 use protocol 4
|
45 |
+
# In order to get compatibility we need to:
|
46 |
+
# 1. Install pickle5 (we done it at the beginning of the colab)
|
47 |
+
# 2. Create a custom empty object we pass as parameter to PPO.load()
|
48 |
+
custom_objects = {
|
49 |
+
"learning_rate": 0.0,
|
50 |
+
"lr_schedule": lambda _: 0.0,
|
51 |
+
"clip_range": lambda _: 0.0,
|
52 |
+
}
|
53 |
+
|
54 |
+
checkpoint = load_from_hub(repo_id, filename)
|
55 |
+
model = PPO.load(checkpoint, custom_objects=custom_objects, print_system_info=True)
|
56 |
+
|
57 |
+
eval_env = Monitor(gym.make("LunarLander-v2"))
|
58 |
+
mean_reward, std_reward = evaluate_policy(model, eval_env, n_eval_episodes=10, deterministic=True)
|
59 |
+
print(f"mean_reward={mean_reward:.2f} +/- {std_reward}")
|
60 |
...
|
61 |
```
|