ravkumar commited on
Commit
2c8a742
·
1 Parent(s): bc061f2

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +35 -1
README.md CHANGED
@@ -30,8 +30,42 @@ TODO: Add your code
30
 
31
 
32
  ```python
33
- from stable_baselines3 import ...
 
 
 
34
  from huggingface_sb3 import load_from_hub
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  ...
37
  ```
 
30
 
31
 
32
  ```python
33
+ from stable_baselines3 import PPO
34
+ from stable_baselines3.common.env_util import make_vec_env
35
+ from stable_baselines3.common.evaluation import evaluate_policy
36
+
37
  from huggingface_sb3 import load_from_hub
38
 
39
+
40
+ # Download the model checkpoint
41
+ model_checkpoint = load_from_hub("ravkumar/ppo-LunarLander-v2", "ppo-LunarLander-v2.zip")
42
+ # Create a vectorized environment
43
+ env = make_vec_env("LunarLander-v2", n_envs=1)
44
+
45
+ # Load the model
46
+ model = PPO.load(model_checkpoint, env=env)
47
+
48
+ # Evaluate
49
+ print("Evaluating model")
50
+ mean_reward, std_reward = evaluate_policy(
51
+ model,
52
+ env,
53
+ n_eval_episodes=30,
54
+ deterministic=True,
55
+ )
56
+ print(f"Mean reward = {mean_reward:.2f} +/- {std_reward}")
57
+
58
+ # Start a new episode
59
+ obs = env.reset()
60
+
61
+ try:
62
+ while True:
63
+ action, state = model.predict(obs, deterministic=True)
64
+ obs, reward, done, info = env.step(action)
65
+ env.render()
66
+
67
+ except KeyboardInterrupt:
68
+ pass
69
+
70
  ...
71
  ```