michaelsh commited on
Commit
7c3776d
·
verified ·
1 Parent(s): b6d5937

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +145 -123
app.py CHANGED
@@ -3,164 +3,186 @@ import plotly.graph_objects as go
3
  import numpy as np
4
  import pandas as pd
5
 
6
-
7
- def create_sota_plot():
8
- # State-of-the-art models data
9
- sota_models = {
10
- 'SIFT + FVs': (2012, 53),
11
- 'AlexNet': (2012.5, 65),
12
- 'SPPNet': (2014.5, 74),
13
- 'Inception V3': (2015.5, 81),
14
- 'NASNET-A(6)': (2017, 82.7),
15
- 'CoAtNet-7': (2021.5, 90.88),
16
- '': (2022, 87.79), # Last point
17
- '': (2022.2, 87.73) # Final value shown
18
- }
19
-
20
- # Extract data for SOTA models
21
- sota_years = [year for year, _ in sota_models.values() if year != '']
22
- sota_accuracy = [acc for _, acc in sota_models.values() if acc != '']
23
- sota_labels = [name for name in sota_models.keys() if name != '']
24
-
25
- # Generate synthetic "other models" data (gray points)
26
- np.random.seed(42)
27
- n_other = 300
28
- other_years = np.random.uniform(2010, 2023, n_other)
29
- # Create a distribution that's mostly below SOTA but with some variance
30
- other_accuracy = []
31
- for year in other_years:
32
- # Find approximate SOTA accuracy for this year
33
- sota_at_year = np.interp(year, sota_years[:len(sota_accuracy)], sota_accuracy[:len(sota_accuracy)])
34
- # Add models mostly below SOTA with some variance
35
- if year < 2012:
36
- acc = np.random.normal(45, 8)
37
- else:
38
- acc = np.random.normal(sota_at_year - 10, 5)
39
- # Some models can be close to SOTA
40
- if np.random.random() < 0.1:
41
- acc = sota_at_year - np.random.uniform(0, 3)
42
- other_accuracy.append(max(30, min(92, acc))) # Clip to reasonable range
43
-
44
  # Create the plot
45
  fig = go.Figure()
46
-
47
- # Add other models (gray scatter points)
48
  fig.add_trace(go.Scatter(
49
- x=other_years,
50
- y=other_accuracy,
51
  mode='markers',
52
- name='Other models',
53
  marker=dict(
54
- color='lightgray',
55
- size=6,
56
- opacity=0.5
 
57
  ),
58
- hovertemplate='Year: %{x:.1f}<br>Accuracy: %{y:.1f}%<extra></extra>'
 
59
  ))
60
-
61
- # Add SOTA models line
62
  fig.add_trace(go.Scatter(
63
- x=sota_years[:len(sota_accuracy)],
64
- y=sota_accuracy,
65
- mode='lines+markers',
66
- name='State-of-the-art models',
67
- line=dict(color='#00CED1', width=3),
68
- marker=dict(size=10, color='#00CED1'),
69
- hovertemplate='%{text}<br>Year: %{x:.1f}<br>Accuracy: %{y:.1f}%<extra></extra>',
70
- text=sota_labels[:len(sota_accuracy)]
71
  ))
72
-
73
- # Add labels for SOTA models
74
- for i, (name, (year, acc)) in enumerate(sota_models.items()):
75
- if name and i < len(sota_accuracy): # Only label points with names
76
- fig.add_annotation(
77
- x=year,
78
- y=acc,
79
- text=name,
80
- showarrow=False,
81
- yshift=15,
82
- font=dict(size=12)
83
- )
84
-
85
- # Add the final accuracy values
86
- fig.add_annotation(
87
- x=2022,
88
- y=87.79,
89
- text="87.79",
90
- showarrow=False,
91
- xshift=30,
92
- font=dict(size=12, weight='bold')
93
- )
94
-
95
- fig.add_annotation(
96
- x=2022.2,
97
- y=87.73,
98
- text="87.73",
99
- showarrow=False,
100
- xshift=30,
101
- yshift=-10,
102
- font=dict(size=12)
103
- )
104
-
105
  # Update layout
106
  fig.update_layout(
107
- title='Evolution of Model Performance on ImageNet',
108
- xaxis_title='Year',
109
- yaxis_title='TOP-1 ACCURACY',
110
  xaxis=dict(
111
- range=[2010, 2023],
112
- tickmode='linear',
113
- tick0=2012,
114
- dtick=2,
115
  showgrid=True,
116
  gridcolor='lightgray'
117
  ),
118
  yaxis=dict(
119
- range=[35, 100],
120
- tickmode='linear',
121
- tick0=40,
122
- dtick=10,
123
  showgrid=True,
124
  gridcolor='lightgray'
125
  ),
126
  plot_bgcolor='white',
127
  paper_bgcolor='white',
128
- height=500,
129
  legend=dict(
130
- yanchor="bottom",
131
- y=0.01,
132
- xanchor="center",
133
- x=0.5,
134
- orientation="h"
135
- )
136
  )
137
-
138
  return fig
139
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
 
141
  # Create Gradio interface
142
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
143
- gr.Markdown("# State-of-the-Art Models Timeline")
144
- gr.Markdown(
145
- "This visualization shows the evolution of state-of-the-art models' performance over time, similar to the ImageNet benchmark progression.")
146
-
 
 
147
  plot = gr.Plot(label="Model Performance Evolution")
148
-
 
 
 
 
 
 
 
 
 
 
149
  # Create plot on load
150
- demo.load(fn=create_sota_plot, outputs=plot)
151
-
152
  # Add interactive controls
153
  with gr.Row():
154
  refresh_btn = gr.Button("Refresh Plot")
155
-
156
- refresh_btn.click(fn=create_sota_plot, outputs=plot)
157
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
  gr.Markdown("""
159
  ### About this visualization:
160
- - **Cyan line**: State-of-the-art models showing the progression of best performance
161
- - **Gray dots**: Other models representing the broader research landscape
162
- - The plot shows how breakthrough models like AlexNet, Inception, and NASNET pushed the boundaries
163
- - Notice the rapid improvement from 2012-2018, followed by more incremental gains
 
164
  """)
165
 
166
  demo.launch()
 
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'],
47
+ y=df_sorted['cumulative_best'],
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,
62
+ arrowsize=1,
63
+ arrowwidth=1,
64
+ arrowcolor='gray',
65
+ ax=0,
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'
78
  ),
79
  yaxis=dict(
 
 
 
 
80
  showgrid=True,
81
  gridcolor='lightgray'
82
  ),
83
  plot_bgcolor='white',
84
  paper_bgcolor='white',
85
+ height=600,
86
  legend=dict(
87
+ yanchor="top",
88
+ y=0.99,
89
+ xanchor="left",
90
+ x=0.01
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',
108
+ # Add some models that don't improve SOTA
109
+ 'SmallNet-1', 'SmallNet-2', 'BasicCNN', 'SimpleDNN', 'QuickNet',
110
+ 'FastNet', 'LiteModel', 'CompactNet', 'MiniVGG', 'TinyResNet'
111
+ ],
112
+ 'release_date': pd.to_datetime([
113
+ '2012-01-15', '2012-09-30', '2014-04-10', '2014-09-17', '2015-12-10',
114
+ '2014-06-18', '2015-02-11', '2015-12-02', '2016-05-11', '2016-08-25',
115
+ '2017-04-17', '2017-11-04', '2019-05-28', '2020-10-22',
116
+ '2021-06-09', '2021-01-05', '2021-01-05', '2022-03-14', '2022-07-20', '2022-11-15',
117
+ # Dates for non-SOTA models
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()