Spaces:
Runtime error
Runtime error
MohamedRashad
commited on
Commit
·
3eaf01d
1
Parent(s):
ca938da
feat: Add Gradio and Pandas dependencies, and create a leaderboard for PyTorch Image Models
Browse files
app.py
CHANGED
@@ -1,56 +1,63 @@
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
result = pd.merge(
|
38 |
-
result = pd.merge(result,
|
39 |
-
result = pd.merge(result,
|
40 |
-
result = pd.merge(result,
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
result['
|
45 |
-
result = result[['
|
46 |
-
result = result
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
52 |
gr.HTML("<center><h1>PyTorch Image Models Leaderboard</h1></center>")
|
53 |
gr.Markdown("This leaderboard is based on the results of the models from the [PyTorch Image Models]('https://github.com/huggingface/pytorch-image-models') repository.")
|
54 |
-
gr.DataFrame(
|
|
|
|
|
55 |
|
56 |
-
|
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
|
4 |
+
def load_leaderboard():
|
5 |
+
imagenet_df = pd.read_csv('https://raw.githubusercontent.com/huggingface/pytorch-image-models/main/results/results-imagenet.csv')
|
6 |
+
imagenet_real_df = pd.read_csv('https://raw.githubusercontent.com/huggingface/pytorch-image-models/main/results/results-imagenet-real.csv')
|
7 |
+
imagenetv2_df = pd.read_csv('https://raw.githubusercontent.com/huggingface/pytorch-image-models/main/results/results-imagenetv2-matched-frequency.csv')
|
8 |
+
sketch_df = pd.read_csv('https://raw.githubusercontent.com/huggingface/pytorch-image-models/main/results/results-sketch.csv')
|
9 |
+
imagenet_a_df = pd.read_csv('https://raw.githubusercontent.com/huggingface/pytorch-image-models/main/results/results-imagenet-a.csv')
|
10 |
+
imagenet_r_df = pd.read_csv('https://raw.githubusercontent.com/huggingface/pytorch-image-models/main/results/results-imagenet-r.csv')
|
11 |
+
|
12 |
+
# columns to remove from each dataframe
|
13 |
+
remove_column_names = ["top1_err", "top5_err", "top1_diff", "top5_diff", "rank_diff"]
|
14 |
+
for remove_column_name in remove_column_names:
|
15 |
+
if remove_column_name in imagenet_df.columns:
|
16 |
+
imagenet_df = imagenet_df.drop(columns=remove_column_name)
|
17 |
+
if remove_column_name in imagenet_real_df.columns:
|
18 |
+
imagenet_real_df = imagenet_real_df.drop(columns=remove_column_name)
|
19 |
+
if remove_column_name in imagenetv2_df.columns:
|
20 |
+
imagenetv2_df = imagenetv2_df.drop(columns=remove_column_name)
|
21 |
+
if remove_column_name in sketch_df.columns:
|
22 |
+
sketch_df = sketch_df.drop(columns=remove_column_name)
|
23 |
+
if remove_column_name in imagenet_a_df.columns:
|
24 |
+
imagenet_a_df = imagenet_a_df.drop(columns=remove_column_name)
|
25 |
+
if remove_column_name in imagenet_r_df.columns:
|
26 |
+
imagenet_r_df = imagenet_r_df.drop(columns=remove_column_name)
|
27 |
+
|
28 |
+
# Rename top1 and top5 columns to the name of the dataframe+top1/top5
|
29 |
+
imagenet_df = imagenet_df.rename(columns={"top1": "imagenet_top1", "top5": "imagenet_top5"})
|
30 |
+
imagenet_real_df = imagenet_real_df.rename(columns={"top1": "imagenet_real_top1", "top5": "imagenet_real_top5"})
|
31 |
+
imagenetv2_df = imagenetv2_df.rename(columns={"top1": "imagenetv2_top1", "top5": "imagenetv2_top5"})
|
32 |
+
sketch_df = sketch_df.rename(columns={"top1": "sketch_top1", "top5": "sketch_top5"})
|
33 |
+
imagenet_a_df = imagenet_a_df.rename(columns={"top1": "imagenet_a_top1", "top5": "imagenet_a_top5"})
|
34 |
+
imagenet_r_df = imagenet_r_df.rename(columns={"top1": "imagenet_r_top1", "top5": "imagenet_r_top5"})
|
35 |
+
|
36 |
+
# Merge all dataframes
|
37 |
+
result = pd.merge(imagenet_df, imagenet_real_df, on=['model', 'param_count', 'img_size', 'crop_pct', 'interpolation'], how='outer')
|
38 |
+
result = pd.merge(result, imagenetv2_df, on=['model', 'param_count', 'img_size', 'crop_pct', 'interpolation'], how='outer')
|
39 |
+
result = pd.merge(result, sketch_df, on=['model', 'param_count', 'img_size', 'crop_pct', 'interpolation'], how='outer')
|
40 |
+
result = pd.merge(result, imagenet_a_df, on=['model', 'param_count', 'img_size', 'crop_pct', 'interpolation'], how='outer')
|
41 |
+
result = pd.merge(result, imagenet_r_df, on=['model', 'param_count', 'img_size', 'crop_pct', 'interpolation'], how='outer')
|
42 |
+
|
43 |
+
# Average top1 and top5 and add the average column after `model` column
|
44 |
+
result['average_top1'] = result[['imagenet_top1', 'imagenet_real_top1', 'imagenetv2_top1', 'sketch_top1', 'imagenet_a_top1', 'imagenet_r_top1']].mean(axis=1)
|
45 |
+
result['average_top5'] = result[['imagenet_top5', 'imagenet_real_top5', 'imagenetv2_top5', 'sketch_top5', 'imagenet_a_top5', 'imagenet_r_top5']].mean(axis=1)
|
46 |
+
result = result[['model', 'average_top1', 'average_top5', 'param_count', 'img_size', 'crop_pct', 'interpolation', 'imagenet_top1', 'imagenet_top5', 'imagenet_real_top1', 'imagenet_real_top5', 'imagenetv2_top1', 'imagenetv2_top5', 'sketch_top1', 'sketch_top5', 'imagenet_a_top1', 'imagenet_a_top5', 'imagenet_r_top1', 'imagenet_r_top5']]
|
47 |
+
result = result.sort_values(by='average_top1', ascending=False)
|
48 |
+
|
49 |
+
# Round the values to 3 decimal places
|
50 |
+
result = result.round(3)
|
51 |
+
|
52 |
+
return result
|
53 |
+
|
54 |
+
df = load_leaderboard()
|
55 |
+
|
56 |
+
with gr.Blocks("Timm Leaderboard") as app:
|
57 |
gr.HTML("<center><h1>PyTorch Image Models Leaderboard</h1></center>")
|
58 |
gr.Markdown("This leaderboard is based on the results of the models from the [PyTorch Image Models]('https://github.com/huggingface/pytorch-image-models') repository.")
|
59 |
+
leaderboard = gr.DataFrame(df)
|
60 |
+
refresh_button = gr.Button(value="Refresh Leaderboard", variant="primary")
|
61 |
+
refresh_button.click(load_leaderboard, outputs=[leaderboard])
|
62 |
|
63 |
+
app.launch()
|