epsil commited on
Commit
cccb074
1 Parent(s): 3a834c6

Updated Model Card

Browse files
Files changed (1) hide show
  1. README.md +29 -1
README.md CHANGED
@@ -24,5 +24,33 @@ model-index:
24
  This is a trained model of a **DQN** agent playing **LunarLander-v2** 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 **DQN** agent playing **LunarLander-v2** using the [stable-baselines3 library](https://github.com/DLR-RM/stable-baselines3).
25
 
26
  ## Usage (with Stable-baselines3)
27
+ ```
28
+ import gym
29
+
30
+ from huggingface_sb3 import load_from_hub
31
+ from stable_baselines3 import DQN
32
+ from stable_baselines3.common.evaluation import evaluate_policy
33
+
34
+ # Retrieve the model from the hub
35
+ ## repo_id = id of the model repository from the Hugging Face Hub (repo_id = {organization}/{repo_name})
36
+ ## filename = name of the model zip file from the repository
37
+ checkpoint = load_from_hub(repo_id="epsil/dqn-LunarLander-v2", filename="dqn-LunarLander-v2.zip")
38
+
39
+ model = DQN.load(checkpoint)
40
+
41
+ # Evaluate the agent
42
+ eval_env = gym.make('LunarLander-v2')
43
+ mean_reward, std_reward = evaluate_policy(model, eval_env, n_eval_episodes=10, deterministic=True)
44
+ print(f"mean_reward={mean_reward:.2f} +/- {std_reward}")
45
+
46
+ # Watch the agent play
47
+ obs = eval_env.reset()
48
+ for i in range(1000):
49
+ action, _state = model.predict(obs)
50
+ obs, reward, done, info = eval_env.step(action)
51
+ eval_env.render()
52
+ if done:
53
+ obs = eval_env.reset()
54
+ eval_env.close()
55
+ ```
56