michaelsh commited on
Commit
5e63573
·
verified ·
1 Parent(s): 1087dc9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +175 -59
app.py CHANGED
@@ -1,46 +1,47 @@
1
  import gradio as gr
2
  import plotly.graph_objects as go
3
- import numpy as np
4
  import pandas as pd
5
 
6
- def create_sota_plot(df):
 
7
  """
8
- Create a plot showing model performance evolution over time.
9
-
10
  Parameters:
11
- df: DataFrame with columns ['model_name', 'release_date', 'score']
 
12
  """
13
  # Sort by release date to ensure chronological order
14
  df_sorted = df.sort_values('release_date').copy()
15
-
16
- # Calculate cumulative best (SOTA) for each point
17
- df_sorted['cumulative_best'] = df_sorted['score'].cummax()
18
-
19
- # Identify which models are SOTA (where score equals cumulative best)
20
- df_sorted['is_sota'] = df_sorted['score'] == df_sorted['cumulative_best']
21
-
22
  # Get SOTA models for the line
23
  sota_df = df_sorted[df_sorted['is_sota']].copy()
24
-
25
  # Create the plot
26
  fig = go.Figure()
27
-
28
  # Add all models as scatter points (gray for non-SOTA, cyan for SOTA)
29
  fig.add_trace(go.Scatter(
30
  x=df_sorted['release_date'],
31
- y=df_sorted['score'],
32
  mode='markers',
33
  name='All models',
34
  marker=dict(
35
- color=['#00CED1' if is_sota else 'lightgray'
36
  for is_sota in df_sorted['is_sota']],
37
  size=8,
38
  opacity=0.7
39
  ),
40
  text=df_sorted['model_name'],
41
- hovertemplate='<b>%{text}</b><br>Date: %{x}<br>Score: %{y:.2f}%<extra></extra>'
42
  ))
43
-
44
  # Add SOTA line (cumulative best)
45
  fig.add_trace(go.Scatter(
46
  x=df_sorted['release_date'],
@@ -48,14 +49,14 @@ def create_sota_plot(df):
48
  mode='lines',
49
  name='State-of-the-art (cumulative best)',
50
  line=dict(color='#00CED1', width=2, dash='solid'),
51
- hovertemplate='SOTA Score: %{y:.2f}%<br>Date: %{x}<extra></extra>'
52
  ))
53
-
54
  # Add labels for SOTA models (models that improved the best score)
55
  for _, row in sota_df.iterrows():
56
  fig.add_annotation(
57
  x=row['release_date'],
58
- y=row['score'],
59
  text=row['model_name'],
60
  showarrow=True,
61
  arrowhead=2,
@@ -66,12 +67,12 @@ def create_sota_plot(df):
66
  ay=-30,
67
  font=dict(size=10)
68
  )
69
-
70
  # Update layout
71
  fig.update_layout(
72
- title='Evolution of Model Performance Over Time',
73
  xaxis_title='Release Date',
74
- yaxis_title='Score (%)',
75
  xaxis=dict(
76
  showgrid=True,
77
  gridcolor='lightgray'
@@ -91,17 +92,18 @@ def create_sota_plot(df):
91
  ),
92
  hovermode='closest'
93
  )
94
-
95
  return fig
96
 
 
97
  def create_sample_dataframe():
98
  """
99
- Create a sample DataFrame with model performance data.
100
  """
101
- # Create sample data
102
  data = {
103
  'model_name': [
104
- 'SIFT + FVs', 'AlexNet', 'VGG-16', 'GoogLeNet', 'ResNet-50',
105
  'SPPNet', 'Inception V2', 'Inception V3', 'ResNet-152', 'DenseNet',
106
  'MobileNet', 'NASNET-A(6)', 'EfficientNet', 'Vision Transformer',
107
  'CoAtNet-7', 'CLIP', 'DALL-E', 'GPT-Vision', 'Model-X', 'Model-Y',
@@ -118,71 +120,185 @@ def create_sample_dataframe():
118
  '2013-03-10', '2013-07-22', '2014-01-15', '2015-03-20', '2016-02-14',
119
  '2017-06-30', '2018-09-12', '2019-02-28', '2020-04-15', '2021-08-30'
120
  ]),
121
- 'score': [
122
  53.0, 65.0, 71.5, 74.8, 76.0,
123
  74.0, 78.0, 81.0, 77.8, 79.2,
124
  70.6, 82.7, 84.3, 85.2,
125
  90.88, 86.5, 87.0, 87.79, 87.73, 88.1,
126
- # Scores for non-SOTA models (below SOTA at their time)
127
  58.0, 62.0, 68.0, 72.0, 73.5,
128
  75.0, 78.5, 80.0, 82.0, 84.0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
  ]
130
  }
131
-
132
  return pd.DataFrame(data)
133
 
 
134
  # Create Gradio interface
135
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
136
- gr.Markdown("# State-of-the-Art Models Timeline with Cumulative Best")
137
  gr.Markdown("""
138
- This visualization shows the evolution of model performance over time.
139
- The line represents the cumulative best (SOTA) score achieved up to each point in time.
140
  """)
141
-
142
- plot = gr.Plot(label="Model Performance Evolution")
143
-
144
  # Create the main DataFrame inline
145
  df_main = create_sample_dataframe()
146
-
147
- # Display data info
 
 
 
148
  with gr.Row():
149
- with gr.Column():
 
150
  gr.Markdown(f"**Total models in dataset:** {len(df_main)}")
151
- gr.Markdown(f"**Date range:** {df_main['release_date'].min().date()} to {df_main['release_date'].max().date()}")
152
- gr.Markdown(f"**Best score achieved:** {df_main['score'].max():.2f}%")
153
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
  # Create plot on load
155
- demo.load(fn=lambda: create_sota_plot(df_main), outputs=plot)
156
-
 
 
 
 
 
 
 
 
 
 
157
  # Add interactive controls
158
  with gr.Row():
159
- refresh_btn = gr.Button("Refresh Plot")
160
- show_data_btn = gr.Button("Show DataFrame")
161
-
162
  # DataFrame display (initially hidden)
163
  df_display = gr.Dataframe(
164
  value=df_main,
165
  label="Model Performance Data",
166
  visible=False
167
  )
168
-
169
- refresh_btn.click(fn=lambda: create_sota_plot(df_main), outputs=plot)
170
-
171
- def toggle_dataframe(current_df):
172
- return gr.Dataframe(value=current_df, visible=True)
173
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
174
  show_data_btn.click(
175
- fn=lambda: toggle_dataframe(df_main),
176
  outputs=df_display
177
  )
178
-
 
 
 
 
 
179
  gr.Markdown("""
180
  ### About this visualization:
181
- - **Cyan line**: Cumulative best (SOTA) score over time - shows the highest score achieved up to each date
 
182
  - **Cyan dots**: Models that achieved a new SOTA when released
183
  - **Gray dots**: Other models that didn't beat the existing SOTA
184
- - **Hover over points**: See model names, release dates, and scores
185
- - The SOTA line only increases or stays flat, never decreases (cumulative maximum)
 
 
 
 
 
 
186
  """)
187
 
188
  demo.launch()
 
1
  import gradio as gr
2
  import plotly.graph_objects as go
 
3
  import pandas as pd
4
 
5
+
6
+ def create_sota_plot(df, metric='accuracy'):
7
  """
8
+ Create a plot showing model performance evolution over time for a selected metric.
9
+
10
  Parameters:
11
+ df: DataFrame with columns ['model_name', 'release_date', and metric columns]
12
+ metric: The metric column to visualize
13
  """
14
  # Sort by release date to ensure chronological order
15
  df_sorted = df.sort_values('release_date').copy()
16
+
17
+ # Calculate cumulative best (SOTA) for the selected metric
18
+ df_sorted['cumulative_best'] = df_sorted[metric].cummax()
19
+
20
+ # Identify which models are SOTA (where metric equals cumulative best)
21
+ df_sorted['is_sota'] = df_sorted[metric] == df_sorted['cumulative_best']
22
+
23
  # Get SOTA models for the line
24
  sota_df = df_sorted[df_sorted['is_sota']].copy()
25
+
26
  # Create the plot
27
  fig = go.Figure()
28
+
29
  # Add all models as scatter points (gray for non-SOTA, cyan for SOTA)
30
  fig.add_trace(go.Scatter(
31
  x=df_sorted['release_date'],
32
+ y=df_sorted[metric],
33
  mode='markers',
34
  name='All models',
35
  marker=dict(
36
+ color=['#00CED1' if is_sota else 'lightgray'
37
  for is_sota in df_sorted['is_sota']],
38
  size=8,
39
  opacity=0.7
40
  ),
41
  text=df_sorted['model_name'],
42
+ hovertemplate=f'<b>%{{text}}</b><br>Date: %{{x}}<br>{metric.capitalize()}: %{{y:.2f}}<extra></extra>'
43
  ))
44
+
45
  # Add SOTA line (cumulative best)
46
  fig.add_trace(go.Scatter(
47
  x=df_sorted['release_date'],
 
49
  mode='lines',
50
  name='State-of-the-art (cumulative best)',
51
  line=dict(color='#00CED1', width=2, dash='solid'),
52
+ hovertemplate=f'SOTA {metric.capitalize()}: %{{y:.2f}}<br>Date: %{{x}}<extra></extra>'
53
  ))
54
+
55
  # Add labels for SOTA models (models that improved the best score)
56
  for _, row in sota_df.iterrows():
57
  fig.add_annotation(
58
  x=row['release_date'],
59
+ y=row[metric],
60
  text=row['model_name'],
61
  showarrow=True,
62
  arrowhead=2,
 
67
  ay=-30,
68
  font=dict(size=10)
69
  )
70
+
71
  # Update layout
72
  fig.update_layout(
73
+ title=f'Evolution of Model Performance Over Time - {metric.upper()}',
74
  xaxis_title='Release Date',
75
+ yaxis_title=f'{metric.capitalize()} Score',
76
  xaxis=dict(
77
  showgrid=True,
78
  gridcolor='lightgray'
 
92
  ),
93
  hovermode='closest'
94
  )
95
+
96
  return fig
97
 
98
+
99
  def create_sample_dataframe():
100
  """
101
+ Create a sample DataFrame with multiple metrics for model performance.
102
  """
103
+ # Create sample data with multiple metrics
104
  data = {
105
  'model_name': [
106
+ 'SIFT + FVs', 'AlexNet', 'VGG-16', 'GoogLeNet', 'ResNet-50',
107
  'SPPNet', 'Inception V2', 'Inception V3', 'ResNet-152', 'DenseNet',
108
  'MobileNet', 'NASNET-A(6)', 'EfficientNet', 'Vision Transformer',
109
  'CoAtNet-7', 'CLIP', 'DALL-E', 'GPT-Vision', 'Model-X', 'Model-Y',
 
120
  '2013-03-10', '2013-07-22', '2014-01-15', '2015-03-20', '2016-02-14',
121
  '2017-06-30', '2018-09-12', '2019-02-28', '2020-04-15', '2021-08-30'
122
  ]),
123
+ 'accuracy': [
124
  53.0, 65.0, 71.5, 74.8, 76.0,
125
  74.0, 78.0, 81.0, 77.8, 79.2,
126
  70.6, 82.7, 84.3, 85.2,
127
  90.88, 86.5, 87.0, 87.79, 87.73, 88.1,
128
+ # Scores for non-SOTA models
129
  58.0, 62.0, 68.0, 72.0, 73.5,
130
  75.0, 78.5, 80.0, 82.0, 84.0
131
+ ],
132
+ 'top5_accuracy': [
133
+ 71.0, 82.0, 89.5, 91.2, 92.5,
134
+ 91.0, 93.5, 95.0, 94.0, 94.5,
135
+ 89.5, 96.2, 97.1, 97.5,
136
+ 98.5, 97.8, 98.0, 98.2, 98.1, 98.3,
137
+ # Top-5 scores for non-SOTA models
138
+ 75.0, 80.0, 85.0, 88.0, 90.0,
139
+ 91.5, 93.0, 95.5, 96.0, 96.5
140
+ ],
141
+ 'parameters_millions': [
142
+ 0.5, 62, 138, 6.8, 25.6,
143
+ 21.0, 11.2, 23.8, 60.3, 7.9,
144
+ 4.2, 88.9, 66.0, 86.0,
145
+ 2185.0, 428.0, 1200.0, 1750.0, 890.0, 920.0,
146
+ # Parameters for non-SOTA models
147
+ 2.5, 3.8, 15.0, 8.5, 5.2,
148
+ 12.0, 3.5, 6.7, 9.0, 11.5
149
+ ],
150
+ 'flops_billions': [
151
+ 0.1, 1.5, 15.5, 1.5, 3.8,
152
+ 2.5, 2.0, 5.7, 11.3, 2.8,
153
+ 0.57, 23.8, 9.9, 16.9,
154
+ 420.0, 85.0, 250.0, 380.0, 180.0, 195.0,
155
+ # FLOPs for non-SOTA models
156
+ 0.3, 0.5, 2.0, 1.2, 0.8,
157
+ 1.8, 0.4, 1.0, 1.5, 2.2
158
+ ],
159
+ 'inference_time_ms': [
160
+ 85, 23, 45, 28, 35,
161
+ 32, 26, 30, 48, 38,
162
+ 18, 65, 42, 55,
163
+ 120, 75, 95, 110, 88, 92,
164
+ # Inference time for non-SOTA models
165
+ 15, 20, 30, 25, 22,
166
+ 28, 12, 18, 24, 35
167
  ]
168
  }
169
+
170
  return pd.DataFrame(data)
171
 
172
+
173
  # Create Gradio interface
174
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
175
+ gr.Markdown("# State-of-the-Art Models Timeline with Multiple Metrics")
176
  gr.Markdown("""
177
+ This visualization shows the evolution of model performance over time across different metrics.
178
+ Use the dropdown to switch between metrics. The line represents the cumulative best (SOTA) score achieved up to each point in time.
179
  """)
180
+
 
 
181
  # Create the main DataFrame inline
182
  df_main = create_sample_dataframe()
183
+
184
+ # Get available metrics (exclude non-metric columns)
185
+ metric_columns = [col for col in df_main.columns if col not in ['model_name', 'release_date']]
186
+
187
+ # Create layout with dropdown in upper right
188
  with gr.Row():
189
+ with gr.Column(scale=3):
190
+ # Display data info
191
  gr.Markdown(f"**Total models in dataset:** {len(df_main)}")
192
+ gr.Markdown(
193
+ f"**Date range:** {df_main['release_date'].min().date()} to {df_main['release_date'].max().date()}")
194
+ with gr.Column(scale=1):
195
+ metric_dropdown = gr.Dropdown(
196
+ choices=metric_columns,
197
+ value='accuracy',
198
+ label="Select Metric",
199
+ interactive=True
200
+ )
201
+
202
+ plot = gr.Plot(label="Model Performance Evolution")
203
+
204
+
205
+ # Function to update plot and statistics
206
+ def update_plot_and_stats(selected_metric):
207
+ fig = create_sota_plot(df_main, selected_metric)
208
+ best_value = df_main[selected_metric].max()
209
+ best_model = df_main.loc[df_main[selected_metric].idxmax(), 'model_name']
210
+
211
+ # Format statistics based on metric type
212
+ if selected_metric == 'parameters_millions':
213
+ stats_text = f"**Best {selected_metric.replace('_', ' ').title()}:** {best_value:.1f}M ({best_model})"
214
+ elif selected_metric == 'flops_billions':
215
+ stats_text = f"**Best {selected_metric.replace('_', ' ').title()}:** {best_value:.1f}B ({best_model})"
216
+ elif selected_metric == 'inference_time_ms':
217
+ stats_text = f"**Best {selected_metric.replace('_', ' ').title()}:** {best_value:.1f}ms ({best_model})"
218
+ else:
219
+ stats_text = f"**Best {selected_metric.replace('_', ' ').title()}:** {best_value:.2f}% ({best_model})"
220
+
221
+ return fig, stats_text
222
+
223
+
224
+ # Display best score for selected metric
225
+ metric_stats = gr.Markdown()
226
+
227
  # Create plot on load
228
+ demo.load(
229
+ fn=lambda: update_plot_and_stats('accuracy'),
230
+ outputs=[plot, metric_stats]
231
+ )
232
+
233
+ # Update plot when metric changes
234
+ metric_dropdown.change(
235
+ fn=update_plot_and_stats,
236
+ inputs=metric_dropdown,
237
+ outputs=[plot, metric_stats]
238
+ )
239
+
240
  # Add interactive controls
241
  with gr.Row():
242
+ show_data_btn = gr.Button("Show/Hide DataFrame")
243
+ export_stats_btn = gr.Button("Export Statistics")
244
+
245
  # DataFrame display (initially hidden)
246
  df_display = gr.Dataframe(
247
  value=df_main,
248
  label="Model Performance Data",
249
  visible=False
250
  )
251
+
252
+
253
+ def toggle_dataframe():
254
+ return gr.Dataframe(value=df_main, visible=True)
255
+
256
+
257
+ def export_statistics():
258
+ stats = []
259
+ for metric in metric_columns:
260
+ best_value = df_main[metric].max()
261
+ best_model = df_main.loc[df_main[metric].idxmax(), 'model_name']
262
+ avg_value = df_main[metric].mean()
263
+ stats.append({
264
+ 'Metric': metric.replace('_', ' ').title(),
265
+ 'Best Value': f"{best_value:.2f}",
266
+ 'Best Model': best_model,
267
+ 'Average': f"{avg_value:.2f}"
268
+ })
269
+ stats_df = pd.DataFrame(stats)
270
+ return gr.Dataframe(value=stats_df, visible=True)
271
+
272
+
273
+ stats_display = gr.Dataframe(
274
+ label="Statistics Summary",
275
+ visible=False
276
+ )
277
+
278
  show_data_btn.click(
279
+ fn=toggle_dataframe,
280
  outputs=df_display
281
  )
282
+
283
+ export_stats_btn.click(
284
+ fn=export_statistics,
285
+ outputs=stats_display
286
+ )
287
+
288
  gr.Markdown("""
289
  ### About this visualization:
290
+ - **Metric Selector**: Use the dropdown in the upper right to switch between different performance metrics
291
+ - **Cyan line**: Cumulative best (SOTA) score over time for the selected metric
292
  - **Cyan dots**: Models that achieved a new SOTA when released
293
  - **Gray dots**: Other models that didn't beat the existing SOTA
294
+ - **Hover over points**: See model names, release dates, and metric values
295
+
296
+ ### Available Metrics:
297
+ - **Accuracy**: Top-1 accuracy on ImageNet (%)
298
+ - **Top5 Accuracy**: Top-5 accuracy on ImageNet (%)
299
+ - **Parameters (Millions)**: Model size in millions of parameters
300
+ - **FLOPs (Billions)**: Computational cost in billions of operations
301
+ - **Inference Time (ms)**: Time to process a single image
302
  """)
303
 
304
  demo.launch()