MohamedRashad commited on
Commit
ca938da
·
1 Parent(s): 466a0b7

chore: Add Gradio and Pandas dependencies, and create a leaderboard for PyTorch Image Models

Browse files
Files changed (2) hide show
  1. app.py +56 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio
2
+ pandas