Commit
Β·
581a790
0
Parent(s):
Duplicate from huggingface-projects/Deep-Reinforcement-Learning-Leaderboard
Browse files- .gitattributes +27 -0
- .gitignore +1 -0
- README.md +13 -0
- app.py +235 -0
- utils.py +14 -0
.gitattributes
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
19 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
26 |
+
*.zstandard filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
__pycache__/*
|
README.md
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Deep Reinforcement Learning Leaderboard
|
3 |
+
emoji: π
|
4 |
+
colorFrom: green
|
5 |
+
colorTo: indigo
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.11.0
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
duplicated_from: huggingface-projects/Deep-Reinforcement-Learning-Leaderboard
|
11 |
+
---
|
12 |
+
|
13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces#reference
|
app.py
ADDED
@@ -0,0 +1,235 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
|
3 |
+
import requests
|
4 |
+
|
5 |
+
from datasets import load_dataset
|
6 |
+
import gradio as gr
|
7 |
+
from huggingface_hub import HfApi, hf_hub_download
|
8 |
+
from huggingface_hub.repocard import metadata_load
|
9 |
+
import pandas as pd
|
10 |
+
from utils import *
|
11 |
+
|
12 |
+
|
13 |
+
block = gr.Blocks()
|
14 |
+
|
15 |
+
# Containing the data
|
16 |
+
rl_envs = [
|
17 |
+
{
|
18 |
+
"rl_env_beautiful": "LunarLander-v2 π",
|
19 |
+
"rl_env": "LunarLander-v2",
|
20 |
+
"video_link": "",
|
21 |
+
"global": None
|
22 |
+
},
|
23 |
+
{
|
24 |
+
"rl_env_beautiful": "CartPole-v1",
|
25 |
+
"rl_env": "CartPole-v1",
|
26 |
+
"video_link": "https://huggingface.co/sb3/ppo-CartPole-v1/resolve/main/replay.mp4",
|
27 |
+
"global": None
|
28 |
+
},
|
29 |
+
{
|
30 |
+
"rl_env_beautiful": "FrozenLake-v1-4x4-no_slippery βοΈ",
|
31 |
+
"rl_env": "FrozenLake-v1-4x4-no_slippery",
|
32 |
+
"video_link": "",
|
33 |
+
"global": None
|
34 |
+
},
|
35 |
+
{
|
36 |
+
"rl_env_beautiful": "FrozenLake-v1-8x8-no_slippery βοΈ",
|
37 |
+
"rl_env": "FrozenLake-v1-8x8-no_slippery",
|
38 |
+
"video_link": "",
|
39 |
+
"global": None
|
40 |
+
},
|
41 |
+
{
|
42 |
+
"rl_env_beautiful": "FrozenLake-v1-4x4 βοΈ",
|
43 |
+
"rl_env": "FrozenLake-v1-4x4",
|
44 |
+
"video_link": "",
|
45 |
+
"global": None
|
46 |
+
},
|
47 |
+
{
|
48 |
+
"rl_env_beautiful": "FrozenLake-v1-8x8 βοΈ",
|
49 |
+
"rl_env": "FrozenLake-v1-8x8",
|
50 |
+
"video_link": "",
|
51 |
+
"global": None
|
52 |
+
},
|
53 |
+
{
|
54 |
+
"rl_env_beautiful": "Taxi-v3 π",
|
55 |
+
"rl_env": "Taxi-v3",
|
56 |
+
"video_link": "",
|
57 |
+
"global": None
|
58 |
+
},
|
59 |
+
{
|
60 |
+
"rl_env_beautiful": "CarRacing-v0 ποΈ",
|
61 |
+
"rl_env": "CarRacing-v0",
|
62 |
+
"video_link": "",
|
63 |
+
"global": None
|
64 |
+
},
|
65 |
+
{
|
66 |
+
"rl_env_beautiful": "MountainCar-v0 β°οΈ",
|
67 |
+
"rl_env": "MountainCar-v0",
|
68 |
+
"video_link": "",
|
69 |
+
"global": None
|
70 |
+
},
|
71 |
+
{
|
72 |
+
"rl_env_beautiful": "SpaceInvadersNoFrameskip-v4 πΎ",
|
73 |
+
"rl_env": "SpaceInvadersNoFrameskip-v4",
|
74 |
+
"video_link": "",
|
75 |
+
"global": None
|
76 |
+
},
|
77 |
+
{
|
78 |
+
"rl_env_beautiful": "BipedalWalker-v3",
|
79 |
+
"rl_env": "BipedalWalker-v3",
|
80 |
+
"video_link": "",
|
81 |
+
"global": None
|
82 |
+
},
|
83 |
+
{
|
84 |
+
"rl_env_beautiful": "Walker2DBulletEnv-v0",
|
85 |
+
"rl_env": "Walker2DBulletEnv-v0",
|
86 |
+
"video_link": "",
|
87 |
+
"global": None
|
88 |
+
},
|
89 |
+
{
|
90 |
+
"rl_env_beautiful": "AntBulletEnv-v0",
|
91 |
+
"rl_env": "AntBulletEnv-v0",
|
92 |
+
"video_link": "",
|
93 |
+
"global": None
|
94 |
+
},
|
95 |
+
{
|
96 |
+
"rl_env_beautiful": "HalfCheetahBulletEnv-v0",
|
97 |
+
"rl_env": "HalfCheetahBulletEnv-v0",
|
98 |
+
"video_link": "",
|
99 |
+
"global": None
|
100 |
+
}
|
101 |
+
]
|
102 |
+
|
103 |
+
|
104 |
+
|
105 |
+
def get_metadata(model_id):
|
106 |
+
try:
|
107 |
+
readme_path = hf_hub_download(model_id, filename="README.md")
|
108 |
+
return metadata_load(readme_path)
|
109 |
+
except requests.exceptions.HTTPError:
|
110 |
+
# 404 README.md not found
|
111 |
+
return None
|
112 |
+
|
113 |
+
def parse_metrics_accuracy(meta):
|
114 |
+
if "model-index" not in meta:
|
115 |
+
return None
|
116 |
+
result = meta["model-index"][0]["results"]
|
117 |
+
metrics = result[0]["metrics"]
|
118 |
+
accuracy = metrics[0]["value"]
|
119 |
+
return accuracy
|
120 |
+
|
121 |
+
# We keep the worst case episode
|
122 |
+
def parse_rewards(accuracy):
|
123 |
+
default_std = -1000
|
124 |
+
default_reward=-1000
|
125 |
+
if accuracy != None:
|
126 |
+
accuracy = str(accuracy)
|
127 |
+
parsed = accuracy.split(' +/- ')
|
128 |
+
if len(parsed)>1:
|
129 |
+
mean_reward = float(parsed[0])
|
130 |
+
std_reward = float(parsed[1])
|
131 |
+
elif len(parsed)==1: #only mean reward
|
132 |
+
mean_reward = float(parsed[0])
|
133 |
+
std_reward = float(0)
|
134 |
+
|
135 |
+
else:
|
136 |
+
mean_reward = float(default_std)
|
137 |
+
std_reward = float(default_reward)
|
138 |
+
|
139 |
+
else:
|
140 |
+
mean_reward = float(default_std)
|
141 |
+
std_reward = float(default_reward)
|
142 |
+
return mean_reward, std_reward
|
143 |
+
|
144 |
+
|
145 |
+
def get_model_ids(rl_env):
|
146 |
+
api = HfApi()
|
147 |
+
models = api.list_models(filter=rl_env)
|
148 |
+
model_ids = [x.modelId for x in models]
|
149 |
+
print(model_ids)
|
150 |
+
return model_ids
|
151 |
+
|
152 |
+
def get_model_dataframe(rl_env):
|
153 |
+
# Get model ids associated with rl_env
|
154 |
+
model_ids = get_model_ids(rl_env)
|
155 |
+
print(model_ids)
|
156 |
+
data = []
|
157 |
+
for model_id in model_ids:
|
158 |
+
"""
|
159 |
+
readme_path = hf_hub_download(model_id, filename="README.md")
|
160 |
+
meta = metadata_load(readme_path)
|
161 |
+
"""
|
162 |
+
meta = get_metadata(model_id)
|
163 |
+
#LOADED_MODEL_METADATA[model_id] = meta if meta is not None else ''
|
164 |
+
if meta is None:
|
165 |
+
continue
|
166 |
+
user_id = model_id.split('/')[0]
|
167 |
+
row = {}
|
168 |
+
row["User"] = make_clickable_user(user_id)
|
169 |
+
row["Model"] = make_clickable_model(model_id)
|
170 |
+
accuracy = parse_metrics_accuracy(meta)
|
171 |
+
mean_reward, std_reward = parse_rewards(accuracy)
|
172 |
+
mean_reward = mean_reward if not pd.isna(mean_reward) else 0
|
173 |
+
std_reward = std_reward if not pd.isna(std_reward) else 0
|
174 |
+
row["Results"] = mean_reward - std_reward
|
175 |
+
row["Mean Reward"] = mean_reward
|
176 |
+
row["Std Reward"] = std_reward
|
177 |
+
data.append(row)
|
178 |
+
ranked_dataframe = rank_dataframe(pd.DataFrame.from_records(data))
|
179 |
+
print("RANKED", ranked_dataframe)
|
180 |
+
return ranked_dataframe
|
181 |
+
|
182 |
+
|
183 |
+
def rank_dataframe(dataframe):
|
184 |
+
print("DATAFRAME", dataframe)
|
185 |
+
dataframe = dataframe.sort_values(by=['Results'], ascending=False)
|
186 |
+
if not 'Ranking' in dataframe.columns:
|
187 |
+
dataframe.insert(0, 'Ranking', [i for i in range(1,len(dataframe)+1)])
|
188 |
+
else:
|
189 |
+
dataframe['Ranking'] = [i for i in range(1,len(dataframe)+1)]
|
190 |
+
return dataframe
|
191 |
+
|
192 |
+
|
193 |
+
with block:
|
194 |
+
gr.Markdown(f"""
|
195 |
+
# π The Deep Reinforcement Learning Course Leaderboard π
|
196 |
+
|
197 |
+
This is the leaderboard of trained agents during the Deep Reinforcement Learning Course. A free course from beginner to expert.
|
198 |
+
|
199 |
+
Just choose which environment you trained your agent on and with Ctrl+F find your rank π
|
200 |
+
|
201 |
+
**If you don't find your model, go to the bottom of the page and click on the refresh button**
|
202 |
+
|
203 |
+
We use **lower bound result to sort the models: mean_reward - std_reward.**
|
204 |
+
|
205 |
+
You **can click on the model's name** to be redirected to its model card which includes documentation.
|
206 |
+
|
207 |
+
π€ You want to try to train your agents? <a href="https://huggingface.co/deep-rl-course/unit0/introduction?fw=pt" target="_blank"> Check the Hugging Face free Deep Reinforcement Learning Course π€ </a>.
|
208 |
+
|
209 |
+
You want to compare two agents? <a href="https://huggingface.co/spaces/ThomasSimonini/Compare-Reinforcement-Learning-Agents" target="_blank">It's possible using this Spaces demo π </a>.
|
210 |
+
|
211 |
+
π§ There is an **environment missing?** Please open an issue.
|
212 |
+
""")
|
213 |
+
|
214 |
+
#for rl_env in RL_ENVS:
|
215 |
+
for i in range(0, len(rl_envs)):
|
216 |
+
rl_env = rl_envs[i]
|
217 |
+
|
218 |
+
with gr.TabItem(rl_env["rl_env_beautiful"]) as rl_tab:
|
219 |
+
with gr.Row():
|
220 |
+
markdown = """
|
221 |
+
# {name_leaderboard}
|
222 |
+
|
223 |
+
""".format(name_leaderboard = rl_env["rl_env_beautiful"], video_link = rl_env["video_link"])
|
224 |
+
gr.Markdown(markdown)
|
225 |
+
with gr.Row():
|
226 |
+
rl_env["global"] = gr.components.Dataframe(value= get_model_dataframe(rl_env["rl_env"]), headers=["Ranking π", "User π€", "Model id π€", "Results", "Mean Reward", "Std Reward"], datatype=["number", "markdown", "markdown", "number", "number", "number"])
|
227 |
+
with gr.Row():
|
228 |
+
data_run = gr.Button("Refresh")
|
229 |
+
print("rl_env", rl_env["rl_env"])
|
230 |
+
val = gr.Variable(value=[rl_env["rl_env"]])
|
231 |
+
data_run.click(get_model_dataframe, inputs=[val], outputs =rl_env["global"])
|
232 |
+
|
233 |
+
|
234 |
+
block.launch()
|
235 |
+
|
utils.py
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Based on Omar Sanseviero work
|
2 |
+
# Make model clickable link
|
3 |
+
def make_clickable_model(model_name):
|
4 |
+
# remove user from model name
|
5 |
+
model_name_show = ' '.join(model_name.split('/')[1:])
|
6 |
+
|
7 |
+
link = "https://huggingface.co/" + model_name
|
8 |
+
return f'<a target="_blank" href="{link}">{model_name_show}</a>'
|
9 |
+
|
10 |
+
# Make user clickable link
|
11 |
+
def make_clickable_user(user_id):
|
12 |
+
link = "https://huggingface.co/" + user_id
|
13 |
+
return f'<a target="_blank" href="{link}">{user_id}</a>'
|
14 |
+
|