asuzuki commited on
Commit
10493fa
1 Parent(s): 1a9a233

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +34 -2
README.md CHANGED
@@ -30,8 +30,40 @@ 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
+ import gym
34
+
35
+ from huggingface_sb3 import load_from_hub, package_to_hub, push_to_hub
36
+ from huggingface_hub import notebook_login # To log to our Hugging Face account to be able to upload models to the Hub.
37
+
38
+ from stable_baselines3 import PPO
39
+ from stable_baselines3.common.evaluation import evaluate_policy
40
+ from stable_baselines3.common.env_util import make_vec_env
41
+
42
+ # Create the environment
43
+ env = make_vec_env('LunarLander-v2', n_envs=16)
44
+
45
+ model = PPO(
46
+ policy = 'MlpPolicy',
47
+ env = env,
48
+ n_steps = 1024,
49
+ batch_size = 64,
50
+ n_epochs = 4,
51
+ gamma = 0.999,
52
+ gae_lambda = 0.98,
53
+ ent_coef = 0.01,
54
+ verbose=1)
55
+
56
+ # Train it for 1,000,000 timesteps
57
+ model.learn(total_timesteps=1000000)
58
+
59
+ # Save the model
60
+ model_name = "unit1-ppo-LunarLander-v2"
61
+ model.save(model_name)
62
+
63
+ #evaluate model
64
+ eval_env = gym.make("LunarLander-v2")
65
+ mean_reward, std_reward = evaluate_policy(model, eval_env, n_eval_episodes=30, deterministic=True)
66
+ print(f"mean_reward={mean_reward:.2f} +/- {std_reward}")
67
 
68
  ...
69
  ```