Skip to content

Commit be250a0

Browse files
committed
results: Some plot/table prettification and writing
1 parent 46e49f8 commit be250a0

File tree

13 files changed

+210
-108
lines changed

13 files changed

+210
-108
lines changed

TODO.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ Remove dots at the end. 2.2, 2.6, 2.16 etc
6565
- Fix Github link, to be to final branch
6666
- Make sure final page is EVEN number
6767

68-
69-
7068
### After report
7169

7270

microesc/report.py

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,25 @@ def get_accuracies(confusions):
8787
assert len(accs) == 10, len(accs)
8888
return pandas.Series(accs)
8989

90-
def plot_accuracy_comparison(experiments, ylim=(0.60, 0.80), figsize=(12, 4)):
90+
def plot_accuracy_comparison(experiments, ylim=(0.0, 1.0), figsize=(12, 4)):
9191

9292
df = experiments.copy()
9393
df.index = experiments.nickname
9494
acc = df.confusions_test.apply(get_accuracies).T
95-
fig, ax = plt.subplots(1, figsize=figsize)
95+
fig, ax = plt.subplots(1, figsize=figsize, dpi=300)
9696

9797
acc.boxplot(ax=ax)
9898

99+
# Mark SOTA models
100+
ax.axhline(0.79, linestyle='dotted', color='green')
101+
ax.axhline(0.83, linestyle='dotted', color='green')
102+
103+
# FIXME: better no-information rate
104+
ax.axhline(0.10, linestyle='dotted', color='black')
105+
99106
ax.set_ylabel('Accuracy')
100107
ax.set_ylim(ylim)
108+
ax.set_yticks(numpy.arange(ylim[0], ylim[1], 0.1))
101109

102110
#ax.set_xticks(experiments.nickname)
103111
#ax.set_xlabel('Model')
@@ -106,7 +114,6 @@ def plot_accuracy_comparison(experiments, ylim=(0.60, 0.80), figsize=(12, 4)):
106114

107115
def plot_accuracy_vs_compute(experiments, ylim=(0.60, 0.80),
108116
perf_metric='utilization', figsize=(12,8)):
109-
# TODO: color experiment groups
110117
# TODO: add error bars?
111118

112119
acc = experiments.confusions_test.apply(get_accuracies).T
@@ -115,12 +122,23 @@ def plot_accuracy_vs_compute(experiments, ylim=(0.60, 0.80),
115122
numpy.testing.assert_allclose(df.test_acc_mean, df.accuracy)
116123
df['experiment'] = df.index
117124

118-
fig, ax = plt.subplots(1, figsize=figsize)
119-
df.plot.scatter(ax=ax, x=perf_metric, y='accuracy', logx=True)
125+
fig, ax = plt.subplots(1, figsize=figsize, dpi=300)
126+
def get_color(idx, nick):
127+
if nick.startswith('Stride-DS-') and not nick.endswith('3x3'):
128+
return 'C0'
129+
return 'C{}'.format(1+idx)
130+
131+
colors = [ get_color(i, n) for i, n in enumerate(df.nickname) ]
132+
df.plot.scatter(ax=ax, x=perf_metric, y='accuracy', c=colors, logx=True)
120133

121134
# Y axis
122135
ax.set_ylim(ylim)
123136
ax.set_ylabel('Accuracy')
137+
ax.grid(True)
138+
ax.tick_params(axis='y', grid_alpha=0.2, grid_color='black')
139+
140+
# X axis
141+
ax.tick_params(axis='x', grid_alpha=0.0)
124142

125143
if perf_metric == 'utilization':
126144
# mark feasible regions
@@ -135,20 +153,26 @@ def format_utilization(tick_val, tick_pos):
135153
return '{:d}%'.format(int(tick_val*100))
136154

137155
ax.xaxis.set_major_formatter(matplotlib.ticker.FuncFormatter(format_utilization))
138-
ax.set_xlabel('CPU utilization')
156+
ax.set_xlabel('CPU usage')
139157

140158
# Add markers
141159
def add_labels(row):
142160
xy = row[perf_metric], row.accuracy
143161
label = "{}".format(row.nickname)
162+
label = label.replace('Stride-DS-', 'S-DS-')
163+
label = label.replace('Stride-', 'S-')
164+
144165
ax.annotate(label, xy,
145-
xytext=(5,20),
166+
xytext=(2,5),
146167
textcoords='offset points',
147-
size=10,
148-
rotation=25,
168+
rotation_mode='anchor',
169+
size=7,
170+
rotation=80,
149171
color='darkslategrey')
150172
df.apply(add_labels, axis=1)
151173

174+
fig.tight_layout()
175+
152176
return fig
153177

154178

@@ -231,12 +255,16 @@ def main():
231255

232256
df['val_acc_mean'] = df.confusions_val.apply(get_accuracies).mean(axis=1)
233257
df['test_acc_mean'] = df.confusions_test.apply(get_accuracies).mean(axis=1)
258+
df['test_acc_std'] = df.confusions_test.apply(get_accuracies).std(axis=1)
234259
df = df.sort_index()
235260

236261
# TODO: add std-dev
237262
df['foreground_val_acc_mean'] = df.confusions_val_foreground.apply(get_accuracies).mean(axis=1)
238263
df['foreground_test_acc_mean'] = df.confusions_test_foreground.apply(get_accuracies).mean(axis=1)
239264
df['background_test_acc_mean'] = df.confusions_test_background.apply(get_accuracies).mean(axis=1)
265+
df['foreground_val_acc_std'] = df.confusions_val_foreground.apply(get_accuracies).std(axis=1)
266+
df['foreground_test_acc_std'] = df.confusions_test_foreground.apply(get_accuracies).std(axis=1)
267+
df['background_test_acc_std'] = df.confusions_test_background.apply(get_accuracies).std(axis=1)
240268

241269

242270
#df['grouped_test_acc_mean'] = grouped_confusion(df.confusions_test, groups).apply(get_accuracies).mean(axis=1)
@@ -271,12 +299,12 @@ def save(fig, name):
271299

272300

273301
# Split the variations from all models
274-
width_variations = df.nickname.str.startswith('Stride-DS-5x5-')
275-
fig = plot_accuracy_comparison(df[width_variations != True])
302+
width_variations = df.nickname.str.startswith('Stride-DS-')
303+
fig = plot_accuracy_comparison(df[width_variations != True], ylim=(0.0, 1.0), figsize=(7,3))
276304
save(fig, 'models_accuracy.png')
277305

278306
perf_metric = 'maccs_frame' if args.skip_device else 'utilization'
279-
fig = plot_accuracy_vs_compute(df, perf_metric=perf_metric)
307+
fig = plot_accuracy_vs_compute(df, perf_metric=perf_metric, figsize=(7,4), ylim=(0.5, 0.8))
280308
save(fig, 'models_efficiency.png')
281309

282310

models.csv

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
model,conv_block,n_stages,conv_size,downsample_size,filters,modelcheck,nickname
22
sbcnn,conv,3,5x5,3x2,24,skip,Baseline
33
sbcnn,depthwise_separable,3,5x5,3x2,24,,Baseline-DS
4-
strided,conv,3,5x5,2x2,22,,Stride-5x5
5-
strided,depthwise_separable,3,5x5,2x2,24,,Stride-DS-5x5
6-
strided,effnet,3,5x5,2x2,22,,Stride-Effnet-5x5
4+
strided,conv,3,5x5,2x2,22,,Stride
5+
strided,depthwise_separable,3,5x5,2x2,24,,Stride-DS-24
6+
strided,effnet,3,5x5,2x2,22,,Stride-Effnet
77
strided,depthwise_separable,4,3x3,2x2,24,,Stride-DS-3x3
8-
strided,bottleneck_ds,3,5x5,2x2,22,,Stride-BN-DS-5x5
9-
strided,depthwise_separable,3,5x5,2x2,20,,Stride-DS-5x5-20
10-
strided,depthwise_separable,3,5x5,2x2,16,,Stride-DS-5x5-16
11-
strided,depthwise_separable,3,5x5,2x2,12,,Stride-DS-5x5-12
8+
strided,bottleneck_ds,3,5x5,2x2,22,,Stride-BTLN-DS
9+
strided,depthwise_separable,3,5x5,2x2,20,,Stride-DS-20
10+
strided,depthwise_separable,3,5x5,2x2,16,,Stride-DS-16
11+
strided,depthwise_separable,3,5x5,2x2,12,,Stride-DS-12

report/plot.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def model_table(data_path):
3838

3939
return table.to_latex()
4040

41-
def plot_models(data_path, figsize=(8,4), max_params=128e3, max_maccs=4.5e6):
41+
def plot_models(data_path, figsize=(12,4), max_params=128e3, max_maccs=4.5e6):
4242
df = logmel_models(data_path)
4343

4444
fig, ax = plt.subplots(1, figsize=figsize)
@@ -49,7 +49,7 @@ def plot_models(data_path, figsize=(8,4), max_params=128e3, max_maccs=4.5e6):
4949

5050
df.plot.scatter(x='params', y='macc_s', logx=True, logy=True, ax=ax)
5151
ax.set_xlabel('Model parameters')
52-
ax.set_ylabel('Multiply-Adds / second')
52+
ax.set_ylabel('MACC / second')
5353

5454
# highlight feasible region
5555
feasible_x = max_params
@@ -73,6 +73,8 @@ def add_labels(row):
7373
color='darkslategrey')
7474
df.apply(add_labels, axis=1)
7575

76+
fig.tight_layout()
77+
7678
return fig
7779

7880
urbansound8k_examples = {
134 Bytes
Loading

report/pyincludes/models.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,15 @@
1616
def strformat(fmt, series):
1717
return [fmt.format(i) for i in series]
1818

19-
#df = df.sort_values('maccs_frame', ascending=False)
2019
df = df.sort_values('nickname', ascending=True)
2120

22-
width_multiple = df.nickname.str.startswith('Stride-DS-5x5-')
23-
df = df.loc[width_multiple == False]
21+
#width_multiple = df.nickname.str.startswith('Stride-DS-5x5-')
22+
#df = df.loc[width_multiple == False]
2423

25-
#df = df.loc[[ df.nickname for ]]
2624

2725
conv_shorthand = {
2826
'depthwise_separable': 'DS',
29-
'bottleneck_ds': 'BN-DS',
27+
'bottleneck_ds': 'BTLN-DS',
3028
'effnet': 'Effnet',
3129
'conv': 'standard',
3230
}

report/pyincludes/models.tex

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
\begin{tabular}{lllrrlll}
22
\toprule
3-
Model & Downsample & Convolution & L & F & MACC & RAM & FLASH \\
3+
Model & Downsample & Convolution & L & F & MACC & RAM & FLASH \\
44
\midrule
5-
Baseline & maxpool 3x2 & standard & 3 & 24 & 10185 K & 35 kB & 405 kB \\
6-
Baseline-DS & maxpool 3x2 & DS & 3 & 24 & 1567 K & 55 kB & 96 kB \\
7-
Stride-5x5 & stride 2x2 & standard & 3 & 22 & 2980 K & 55 kB & 372 kB \\
8-
Stride-BN-DS-5x5 & stride 2x2 & BN-DS & 3 & 22 & 445 K & 47 kB & 80 kB \\
9-
Stride-DS-3x3 & stride 2x2 & DS & 4 & 24 & 318 K & 54 kB & 95 kB \\
10-
Stride-DS-5x5 & stride 2x2 & DS & 3 & 24 & 477 K & 54 kB & 180 kB \\
11-
Stride-Effnet-5x5 & stride 2x2 & Effnet & 3 & 22 & 468 K & 47 kB & 125 kB \\
5+
Baseline & maxpool 3x2 & standard & 3 & 24 & 10185 K & 35 kB & 405 kB \\
6+
Baseline-DS & maxpool 3x2 & DS & 3 & 24 & 1567 K & 55 kB & 96 kB \\
7+
Stride & stride 2x2 & standard & 3 & 22 & 2980 K & 55 kB & 372 kB \\
8+
Stride-BTLN-DS & stride 2x2 & BTLN-DS & 3 & 22 & 445 K & 47 kB & 80 kB \\
9+
Stride-DS-12 & stride 2x2 & DS & 3 & 12 & 208 K & 27 kB & 88 kB \\
10+
Stride-DS-16 & stride 2x2 & DS & 3 & 16 & 291 K & 36 kB & 118 kB \\
11+
Stride-DS-20 & stride 2x2 & DS & 3 & 20 & 380 K & 45 kB & 149 kB \\
12+
Stride-DS-24 & stride 2x2 & DS & 3 & 24 & 477 K & 54 kB & 180 kB \\
13+
Stride-DS-3x3 & stride 2x2 & DS & 4 & 24 & 318 K & 54 kB & 95 kB \\
14+
Stride-Effnet & stride 2x2 & Effnet & 3 & 22 & 468 K & 47 kB & 125 kB \\
1215
\bottomrule
1316
\end{tabular}

report/pyincludes/results.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,32 @@
77
df = pandas.read_csv('results/results.csv')
88
print(df)
99

10-
width_variations = df.nickname.str.startswith('Stride-DS-5x5-')
11-
df = df[width_variations != True]
10+
#width_variations = df.nickname.str.startswith('Stride-DS-5x5-')
11+
#df = df[width_variations != True]
12+
df = df.sort_values('nickname', ascending=True)
13+
14+
def accuracies(df, col):
15+
mean = df[col+'_mean'] * 100
16+
std = df[col+'_std'] * 100
17+
18+
fmt = [ "{:.1f}% +-{:.1f}".format(*t) for t in zip(mean, std) ]
19+
return fmt
20+
21+
def cpu_use(df):
22+
usage = (df.utilization * 1000 * 1/df.classifications_per_second).astype(int)
23+
return ["{:d} ms".format(i).ljust(3) for i in usage]
1224

1325
table = pandas.DataFrame({
1426
'Model': df.nickname,
15-
'CPU (%)': (df.utilization * 100).astype(int),
16-
'Accuracy': (df.test_acc_mean * 100).round(1),
17-
'FG Accuracy': (df.foreground_test_acc_mean * 100).round(1),
18-
'BG Accuracy': (df.background_test_acc_mean * 100).round(1),
27+
'CPU use': cpu_use(df),
28+
'Accuracy': accuracies(df, 'test_acc'),
29+
'FG Accuracy': accuracies(df, 'foreground_test_acc'),
30+
'BG Accuracy': accuracies(df, 'background_test_acc'),
1931
}, index=df.index)
2032

21-
out = table.to_latex(header=True, index=False)
33+
34+
out = table.to_latex(header=True, index=False, column_format='lrrrr')
35+
out = out.replace('+-', '$\pm$') # XXX: Latex gets mangled by to_table it seems
2236
print(out)
2337

2438
outpath = sys.argv[1]

report/pyincludes/results.tex

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
\begin{tabular}{lrrrr}
22
\toprule
3-
Model & CPU (\%) & Accuracy & FG Accuracy & BG Accuracy \\
3+
Model & CPU use & Accuracy & FG Accuracy & BG Accuracy \\
44
\midrule
5-
Baseline & 0 & 73.1 & 84.3 & 49.6 \\
6-
Stride-5x5 & 0 & 71.9 & 82.1 & 50.2 \\
7-
Stride-Effnet-5x5 & 0 & 67.1 & 75.5 & 49.5 \\
8-
Stride-DS-5x5 & 0 & 72.5 & 81.3 & 54.0 \\
9-
Stride-DS-3x3 & 0 & 70.1 & 79.4 & 50.6 \\
10-
Stride-BN-DS-5x5 & 0 & 68.6 & 77.7 & 49.3 \\
11-
Baseline-DS & 0 & 72.7 & 84.0 & 48.8 \\
5+
Baseline & 971 ms & 72.3\% $\pm$4.6 & 78.3\% $\pm$7.1 & 60.5\% $\pm$7.7 \\
6+
Baseline-DS & 244 ms & 70.2\% $\pm$4.7 & 76.1\% $\pm$7.5 & 58.6\% $\pm$8.2 \\
7+
Stride & 325 ms & 68.3\% $\pm$5.2 & 74.1\% $\pm$6.6 & 56.6\% $\pm$8.0 \\
8+
Stride-BTLN-DS & 71 ms & 64.8\% $\pm$7.1 & 69.5\% $\pm$8.2 & 55.3\% $\pm$8.9 \\
9+
Stride-DS-12 & 38 ms & 66.0\% $\pm$6.0 & 72.6\% $\pm$6.5 & 53.3\% $\pm$9.1 \\
10+
Stride-DS-16 & 51 ms & 67.5\% $\pm$5.6 & 73.3\% $\pm$7.7 & 56.2\% $\pm$8.3 \\
11+
Stride-DS-20 & 66 ms & 68.4\% $\pm$5.2 & 75.0\% $\pm$7.4 & 55.2\% $\pm$10.0 \\
12+
Stride-DS-24 & 81 ms & 70.9\% $\pm$4.3 & 75.8\% $\pm$6.3 & 61.8\% $\pm$6.8 \\
13+
Stride-DS-3x3 & 59 ms & 67.2\% $\pm$6.5 & 73.0\% $\pm$7.4 & 55.8\% $\pm$9.1 \\
14+
Stride-Effnet & 73 ms & 60.7\% $\pm$6.6 & 66.9\% $\pm$7.9 & 48.7\% $\pm$8.3 \\
1215
\bottomrule
1316
\end{tabular}

0 commit comments

Comments
 (0)