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
Files changed (1) hide show
  1. app.py +57 -50
app.py CHANGED
@@ -1,56 +1,63 @@
1
  import gradio as gr
2
  import pandas as pd
3
 
4
- imagenet_df = pd.read_csv('https://raw.githubusercontent.com/huggingface/pytorch-image-models/main/results/results-imagenet.csv')
5
- imagenet_real_df = pd.read_csv('https://raw.githubusercontent.com/huggingface/pytorch-image-models/main/results/results-imagenet-real.csv')
6
- imagenetv2_df = pd.read_csv('https://raw.githubusercontent.com/huggingface/pytorch-image-models/main/results/results-imagenetv2-matched-frequency.csv')
7
- sketch_df = pd.read_csv('https://raw.githubusercontent.com/huggingface/pytorch-image-models/main/results/results-sketch.csv')
8
- imagenet_a_df = pd.read_csv('https://raw.githubusercontent.com/huggingface/pytorch-image-models/main/results/results-imagenet-a.csv')
9
- imagenet_r_df = pd.read_csv('https://raw.githubusercontent.com/huggingface/pytorch-image-models/main/results/results-imagenet-r.csv')
10
-
11
- # columns to remove from each dataframe
12
- remove_column_names = ["top1_err", "top5_err", "top1_diff", "top5_diff", "rank_diff"]
13
- for remove_column_name in remove_column_names:
14
- if remove_column_name in imagenet_df.columns:
15
- imagenet_df = imagenet_df.drop(columns=remove_column_name)
16
- if remove_column_name in imagenet_real_df.columns:
17
- imagenet_real_df = imagenet_real_df.drop(columns=remove_column_name)
18
- if remove_column_name in imagenetv2_df.columns:
19
- imagenetv2_df = imagenetv2_df.drop(columns=remove_column_name)
20
- if remove_column_name in sketch_df.columns:
21
- sketch_df = sketch_df.drop(columns=remove_column_name)
22
- if remove_column_name in imagenet_a_df.columns:
23
- imagenet_a_df = imagenet_a_df.drop(columns=remove_column_name)
24
- if remove_column_name in imagenet_r_df.columns:
25
- imagenet_r_df = imagenet_r_df.drop(columns=remove_column_name)
26
-
27
- # Rename top1 and top5 columns to the name of the dataframe+top1/top5
28
- imagenet_df = imagenet_df.rename(columns={"top1": "imagenet_top1", "top5": "imagenet_top5"})
29
- imagenet_real_df = imagenet_real_df.rename(columns={"top1": "imagenet_real_top1", "top5": "imagenet_real_top5"})
30
- imagenetv2_df = imagenetv2_df.rename(columns={"top1": "imagenetv2_top1", "top5": "imagenetv2_top5"})
31
- sketch_df = sketch_df.rename(columns={"top1": "sketch_top1", "top5": "sketch_top5"})
32
- imagenet_a_df = imagenet_a_df.rename(columns={"top1": "imagenet_a_top1", "top5": "imagenet_a_top5"})
33
- imagenet_r_df = imagenet_r_df.rename(columns={"top1": "imagenet_r_top1", "top5": "imagenet_r_top5"})
34
-
35
- # Merge all dataframes
36
- result = pd.merge(imagenet_df, imagenet_real_df, on=['model', 'param_count', 'img_size', 'crop_pct', 'interpolation'], how='outer')
37
- result = pd.merge(result, imagenetv2_df, on=['model', 'param_count', 'img_size', 'crop_pct', 'interpolation'], how='outer')
38
- result = pd.merge(result, sketch_df, on=['model', 'param_count', 'img_size', 'crop_pct', 'interpolation'], how='outer')
39
- result = pd.merge(result, imagenet_a_df, on=['model', 'param_count', 'img_size', 'crop_pct', 'interpolation'], how='outer')
40
- result = pd.merge(result, imagenet_r_df, on=['model', 'param_count', 'img_size', 'crop_pct', 'interpolation'], how='outer')
41
-
42
- # Average top1 and top5 and add the average column after `model` column
43
- result['average_top1'] = result[['imagenet_top1', 'imagenet_real_top1', 'imagenetv2_top1', 'sketch_top1', 'imagenet_a_top1', 'imagenet_r_top1']].mean(axis=1)
44
- result['average_top5'] = result[['imagenet_top5', 'imagenet_real_top5', 'imagenetv2_top5', 'sketch_top5', 'imagenet_a_top5', 'imagenet_r_top5']].mean(axis=1)
45
- 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']]
46
- result = result.sort_values(by='average_top1', ascending=False)
47
-
48
- # Round the values to 3 decimal places
49
- result = result.round(3)
50
-
51
- with gr.Blocks("Timm Leaderboard") as leaderboard:
 
 
 
 
 
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(result)
 
 
55
 
56
- leaderboard.launch()
 
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()