rahuketu86 commited on
Commit
9cb3ecc
·
1 Parent(s): 3aaab30

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +96 -0
app.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # AUTOGENERATED! DO NOT EDIT! File to edit: 03a_image_archs.ipynb.
2
+
3
+ # %% auto 0
4
+ __all__ = ['result_options', 'activity_options', 'col_options', 'subs', 'is_fullmatch', 'drop_tf', 'result_option',
5
+ 'activity_option', 'col_option', 'size_col_option', 'title_dict', 'df', 'fig', 'col1', 'col2', 'get_results',
6
+ 'get_integrated_data', 'get_filtered_data', 'get_data', 'plot_selection']
7
+
8
+ # %% 03a_image_archs.ipynb 11
9
+ import pandas as pd
10
+ import plotly.express as px
11
+ from fastcore.all import *
12
+ import streamlit as st
13
+
14
+ # %% 03a_image_archs.ipynb 13
15
+ def get_results(result_option = 'original'):
16
+ suffix = "" if result_option == 'original' else "-real"
17
+ url_results = f"https://github.com/huggingface/pytorch-image-models/raw/main/results/results-imagenet{suffix}.csv"
18
+ df_results = pd.read_csv(url_results); df_results.head()
19
+ df_results['model_org'] = df_results['model']
20
+ df_results['model'] = df_results['model'].str.split('.').str[0]
21
+ return df_results
22
+
23
+ # %% 03a_image_archs.ipynb 15
24
+ def get_integrated_data(activity_option, result_option):
25
+ df_results = get_results(result_option)
26
+ url_benchmark = f"https://github.com/huggingface/pytorch-image-models/raw/main/results/benchmark-{activity_option}-amp-nhwc-pt112-cu113-rtx3090.csv"
27
+ df_benchmark = pd.read_csv(url_benchmark)
28
+ df_integrated = df_results.merge(df_benchmark, on='model')
29
+ df_integrated['is_tensorflow_model'] = df_integrated.model.str.split('_').str[0] =='tf'
30
+ df_integrated['family'] = df_integrated.model.str.removeprefix("tf_").str.removeprefix("legacy_").str.removeprefix("nf_").str.removeprefix("nf_").str.extract('^([a-z]+?(?:v2|v3)?)(?:\d|_|$)')[0].values
31
+ df_integrated.loc[df_integrated.model.str.contains('in22'), 'family'] = df_integrated.loc[df_integrated.model.str.contains('in22'), 'family'] + "_in22"
32
+ df_integrated.loc[df_integrated.model.str.contains('resnet.*d'), 'family'] = df_integrated.loc[df_integrated.model.str.contains('resnet.*d'), 'family'] + "d"
33
+ return df_integrated[~df_integrated.model.str.endswith('gn')] # Group norm models. Why Jeremy eliminated them from analysis?
34
+
35
+ # %% 03a_image_archs.ipynb 17
36
+ @st.cache_data
37
+ def get_filtered_data(df_integrated, subs, is_fullmatch=False, drop_tf=True):
38
+ if drop_tf: df_integrated = df_integrated[~df_integrated.is_tensorflow_model]
39
+ if not subs: return df_integrated
40
+ elif is_fullmatch: return df_integrated[df_integrated.family.str.fullmatch(subs)]
41
+ else: return df_integrated[df_integrated.model.str.contains(subs)]
42
+
43
+ # %% 03a_image_archs.ipynb 18
44
+ def get_data(col_option, activity_option, result_option, subs, is_fullmatch=False, drop_tf=True):
45
+ col = "_".join([activity_option, col_option])
46
+ df_integrated = get_integrated_data(activity_option, result_option)
47
+ df_integrated = get_filtered_data(df_integrated, subs, is_fullmatch=is_fullmatch, drop_tf=drop_tf)
48
+ df_integrated['secs'] =1./df_integrated[col]
49
+ return df_integrated
50
+
51
+ # %% 03a_image_archs.ipynb 19
52
+ def plot_selection(df, title, col_option, activity_option, w=1000, h=800):
53
+ size_col = "_".join([activity_option, col_option])
54
+ return px.scatter(df, width=w, height=h, size=df[size_col]**2,trendline="ols", trendline_options={'log_x':True},
55
+ title=title, x="secs",log_x=True, y='top1', log_y=True,
56
+ color="family", hover_name='model_org',
57
+ hover_data=[size_col])
58
+
59
+
60
+ # %% 03a_image_archs.ipynb 20
61
+ result_options = ['original', 'real'] #result = 'real'
62
+ activity_options = ['train', 'infer']
63
+ col_options = ['samples_per_sec', 'step_time', 'batch_size', 'img_size', 'gmacs', 'macts']
64
+ subs = '^re[sg]netd?|beit|convnext|levit|efficient|vit|vgg|swin'
65
+ is_fullmatch = False
66
+ drop_tf = False
67
+ subs = 'levit|resnetd?|regnetx|vgg|convnext.*|efficientnetv2|beit|swin'
68
+ is_fullmatch = True
69
+ result_option = result_options[0]
70
+ activity_option = activity_options[1]
71
+ col_option = col_options[0]
72
+ size_col_option = col_options[3]
73
+ title_dict = dict(zip(activity_options, ['Training', "Inference"]))
74
+ df = get_data(col_option, activity_option, result_option, subs, is_fullmatch=is_fullmatch, drop_tf=drop_tf)
75
+ fig = plot_selection(df, title_dict[activity_option], size_col_option, activity_option)
76
+
77
+ # %% 03a_image_archs.ipynb 24
78
+ st.set_page_config(page_title="Which Image Model is best?",layout="wide")
79
+ st.title("Which Image Model is best?")
80
+ col1, col2 = st.columns([1,3])
81
+ with col1:
82
+ st.header("Settings")
83
+ result_option = st.selectbox("Please choose dataset", result_options)
84
+ activity_option = st.selectbox("Please choose activity", activity_options)
85
+ subs = st.text_input("Subs", value='levit|resnetd?|regnetx|vgg|convnext.*|efficientnetv2|beit|swin')
86
+ is_fullmatch = st.checkbox("Is fullmatch", value=True)
87
+ drop_tf = st.checkbox("Drop Tensorflow Models", value=False)
88
+ col_option = st.selectbox("Please choose col_option", col_options)
89
+ size_col_option = st.selectbox("Please choose sizing col_option", col_options, index=3)
90
+ with col2:
91
+ title_dict = dict(zip(activity_options, ['Training', "Inference"]))
92
+ df = get_data(col_option, activity_option, result_option, subs, is_fullmatch=is_fullmatch, drop_tf=drop_tf)
93
+ fig = plot_selection(df, None, size_col_option, activity_option, h=500, w=1000)
94
+ # Plot!
95
+ st.header(title_dict[activity_option])
96
+ st.plotly_chart(fig, use_container_width=True, height=500)