-
Notifications
You must be signed in to change notification settings - Fork 5
/
layout.py
565 lines (515 loc) · 17.7 KB
/
layout.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
from .figures import generate_figure2D
from .figures import generate_figure_mel
from .figures import generate_figure_training
from .figures import generate_figure_features
from .figures import generate_figure_metrics
from dcase_models.data.datasets import get_available_datasets
from dcase_models.data.features import get_available_features
from dcase_models.model.models import get_available_models
from dcase_models.util.files import load_json
import numpy as np
import dash_html_components as html
import dash_core_components as dcc
import dash_bootstrap_components as dbc
import dash_audio_components
# params = load_json(
# os.path.join(os.path.dirname(__file__), 'parameters.json'))
params = load_json('parameters.json')
# params_dataset = params["datasets"][args.dataset]
params_features = params["features"]
# params_model = params['models'][args.model]
X_pca = []
Y = []
label_list = []
predictions = []
X_test = []
Y_test = []
X_pca_test = []
file_names_test = []
# Plot 2D graph
figure2D = generate_figure2D(X_pca, Y, label_list, pca_components=[
0, 1], samples_per_class=1000)
plot2D = dcc.Graph(id='plot2D', figure=figure2D,
style={"height": "100%", "width": "100%"})
# Plot mel-spectrogram
X = np.zeros((64, 64))
figure_mel = generate_figure_mel(X)
plot_mel = dcc.Graph(
id="plot_mel",
figure=figure_mel,
style={"width": "90%", "display": "inline-block", 'float': 'left'}
)
# Audio controls
audio_player = dash_audio_components.DashAudioComponents(
id='audio-player', src="", autoPlay=False, controls=True
)
# Component selector for PCA
options_pca = [{'label': 'Component '+str(j+1), 'value': j} for j in range(4)]
x_select = dcc.Dropdown(id='x_select', options=options_pca,
value=0, style={'width': '100%'})
y_select = dcc.Dropdown(id='y_select', options=options_pca,
value=1, style={'width': '100%'})
output_select = dcc.Dropdown(id='output_select', options=[],
value=1, style={'width': '100%'})
# Slider to select number of instances
slider_samples = html.Div(
dcc.Slider(
id='samples_per_class', min=1, max=500,
step=1, value=10, vertical=False),
style={'width': '100%'}
)
# Plot Figure training
figure_training = generate_figure_training([], [], [])
plot_training_acc = dcc.Graph(id="plot_training",
figure=figure_training)
# Inputs for features parameters
# Sequence time and hop time inputs
sequence_time_input = dbc.FormGroup(
[
dbc.Label("sequence time (s)", html_for="example-email-row", width=2),
dbc.Col(
dbc.Input(type="number", id="sequence_time",
placeholder="sequence_time",
value=params_features['sequence_time']),
width=4
),
dbc.Label("sequence hop time", html_for="example-email-row", width=2),
dbc.Col(
dbc.Input(type="number", id="sequence_hop_time",
placeholder="sequence_hop_time",
value=params_features['sequence_hop_time']),
width=4
),
],
row=True,
)
# Audio win and hop size inputs
audio_win_input = dbc.FormGroup(
[
dbc.Label("audio window", html_for="example-email-row", width=2),
dbc.Col(dbc.Input(type="number", id="audio_win",
placeholder="audio_win",
value=params_features['audio_win']), width=4,),
dbc.Label("audio hop", html_for="example-email-row", width=2),
dbc.Col(dbc.Input(type="number", id="audio_hop",
placeholder="audio_hop",
value=params_features['audio_hop']), width=4,),
],
row=True,
)
# FFT number of samples and sampling rate inputs
sr_input = dbc.FormGroup(
[
# dbc.Label("N FFT", html_for="example-email-row", width=2),
# dbc.Col(dbc.Input(type="number", id="n_fft", placeholder="n_fft",
# value=params_features['n_fft']), width=4,),
dbc.Label("sampling rate", html_for="example-email-row", width=2),
dbc.Col(dbc.Input(type="number", id="sr", placeholder="sr",
value=params_features['sr']), width=4,),
],
row=True,
)
# Features selector
features_classes = get_available_features()
options_features = [{'label': name, 'value': value}
for value, name in enumerate(features_classes.keys())]
feature_selector = dbc.FormGroup(
[
dbc.Label("Feature", html_for="dropdown", width=2),
dbc.Col(dcc.Dropdown(id="feature_name",
options=options_features), width=10),
],
row=True,
)
# Specific parameters of features selected
specific_parameters = dbc.Textarea(
id='specific_parameters', className="mb-3",
placeholder="Specific features parameters"
)
# Button to start feature extraction
btn_extract_features = dbc.Button(
"Extract Features", id="extract_features",
color="primary", className="mr-1", disabled=False
)
# Feedback message of feature extraction
msg_features = dbc.Alert(
"Messages about feature extractor",
id="msg_features",
is_open=False,
duration=4000,
)
# Dataset parameters
# Dataset selector
datasets_classes = get_available_datasets()
options_datasets = [{'label': name, 'value': value}
for value, name in enumerate(datasets_classes.keys())]
dataset_selector = dbc.FormGroup(
[
dbc.Label("Dataset", html_for="dropdown", width=2),
dbc.Col(dcc.Dropdown(id="dataset_name",
options=options_datasets), width=10),
],
row=True,
)
# Dataset path input
dataset_path_input = dbc.FormGroup(
[
dbc.Label("Dataset path", html_for="example-email-row", width=2),
dbc.Col(dbc.Input(type="text", id="dataset_path",
placeholder="dataset_path"), width=10,),
],
row=True,
)
# Dataset audio and feature folder inputs
dataset_folders_input = dbc.FormGroup(
[
dbc.Label("Audio folder", html_for="example-email-row", width=2),
dbc.Col(dbc.Input(type="text", id="audio_folder",
placeholder="audio_folder"), width=4,),
dbc.Label("Features folder", html_for="example-email-row", width=2),
dbc.Col(dbc.Input(type="text", id="features_folder",
placeholder="features_folder"), width=4,),
],
row=True,
)
# Model parameters
# Model selector
models_classes = get_available_models()
options_models = [{'label': name, 'value': value}
for value, name in enumerate(models_classes.keys())]
model_selector = dbc.FormGroup(
[
dbc.Label("Model", html_for="dropdown", width=2),
dbc.Col(
dcc.Dropdown(id="model_name", options=options_models),
width=10
),
],
row=True,
)
# Normalizer selector
options_normalizer = [{'label': 'MinMax', 'value': 'minmax'},
{'label': 'Standard', 'value': 'standard'}]
normalizer_selector = dbc.FormGroup(
[
dbc.Label("Normalizer", html_for="dropdown", width=2),
dbc.Col(dcc.Dropdown(id="normalizer",
options=options_normalizer,
value='minmax'),
width=10),
],
row=True,
)
# Specific parameters of selected model
model_parameters = dbc.Textarea(
id='model_parameters', className="mb-3", placeholder="Model parameters")
# Model path input
model_path = dbc.FormGroup(
[
dbc.Label("Model path", html_for="dropdown", width=2),
dbc.Col(dbc.Input(type="text", id="model_path",
placeholder="model_path"), width=10,),
],
row=True,
)
# Message for feedback (model)
alert = dbc.Alert(
"Hello! I am an auto-dismissing alert!",
id="alert-auto",
is_open=False,
duration=4000,
)
# Checklist for pipeline
check_pipeline = dbc.FormGroup(
[
dbc.Label("Pipeline"),
dbc.Checklist(
options=[
{"label": "Dataset downloaded",
"value": 'dataset', "disabled": True},
{"label": "Features extracted",
"value": 'features', "disabled": True},
{"label": "Model created", "value": 'model', "disabled": True},
],
value=[],
id="check_pipeline",
),
]
)
# Define Tab Model (1)
tab_model = html.Div([
alert,
msg_features,
dbc.Row([
dbc.Col([
dbc.Card([
dbc.CardHeader("Features Parameters"),
dbc.CardBody([
dbc.Form([feature_selector, sequence_time_input,
audio_win_input, sr_input,
specific_parameters, btn_extract_features])
]
),
]),
dbc.Card([
dbc.CardHeader("Dataset Parameters"),
dbc.CardBody([
dbc.Form([dataset_selector, dataset_path_input,
dataset_folders_input])
]
),
]),
],
width=6
),
dbc.Col(
dbc.Card([
dbc.CardHeader("Model parameters"),
dbc.CardBody([
dbc.Form([model_selector, normalizer_selector,
model_parameters, model_path, check_pipeline]),
dbc.Button("Create Model", id="create_model",
color="primary", className="mr-1"),
dbc.Button("Load Model", id="load_model",
color="primary", className="mr-1"),
dbc.Button("Summary Model", id="summary_model",
color="primary", className="mr-1",
disabled=True)
]
),
]), width=6
),
]),
dbc.Modal(
[
dbc.ModalHeader("Model Summary"),
dbc.ModalBody("This is the content of the modal", id='modal_body'),
dbc.ModalFooter(
dbc.Button("Close", id="close_modal", className="ml-auto")
),
],
id="modal",
),
html.Div("", id='status_features', style={'display': 'none'}),
html.Div("", id='end_features_extraction', style={'display': 'none'})
])
# Options of folds, empty to start
options_folds = []
fold_selector = dbc.FormGroup(
[
dbc.Label("Fold", html_for="dropdown", width=2),
dbc.Col(dcc.Dropdown(id="fold_name", options=options_folds), width=10),
],
row=True,
)
# Number of epochs and early stopping inputs
epochs_input = dbc.FormGroup(
[
dbc.Label("Number of epochs", html_for="example-email-row", width=2),
dbc.Col(dbc.Input(type="number", id="epochs", placeholder="epochs",
value=params['train']['epochs']), width=4,),
dbc.Label("Early stopping", html_for="example-email-row", width=2),
dbc.Col(dbc.Input(type="number", id="early_stopping",
placeholder="early_stopping",
value=params['train']['early_stopping']), width=4,),
],
row=True,
)
# Optimizer and learning rate inputs
options_optimizers = [{'value': 0, 'label': 'SGD'},
{'value': 1, 'label': 'RMSprop'},
{'value': 2, 'label': 'Adam'},
{'value': 3, 'label': 'Adadelta'},
{'value': 4, 'label': 'Adagrad'},
{'value': 5, 'label': 'Adamax'},
{'value': 6, 'label': 'Nadam'},
{'value': 7, 'label': 'Ftrl'}]
optimizer_input = dbc.FormGroup(
[
dbc.Label("Optimizer", html_for="example-email-row", width=2),
dbc.Col(dcc.Dropdown(id="optimizer",
options=options_optimizers, value=2), width=4,),
dbc.Label("Learning rate", html_for="example-email-row", width=2),
dbc.Col(dbc.Input(type="number", id="learning_rate",
placeholder="learning_rate",
value=params['train']['learning_rate']), width=4,),
],
row=True,
)
# Batch size and considered improvement inputs
batch_size_input = dbc.FormGroup(
[
dbc.Label("Batch Size", html_for="example-email-row", width=2),
dbc.Col(dbc.Input(type="text", id="batch_size",
placeholder="batch_size",
value=params['train']['batch_size']), width=4,),
dbc.Label("Considered Improvement",
html_for="example-email-row", width=2),
dbc.Col(dbc.Input(type="number", id="considered_improvement",
placeholder="considered_improvement",
value=params['train']['considered_improvement']),
width=4
),
],
row=True,
)
# Feedback messages for training process
alert_train = dbc.Alert(
"Hello! I am an auto-dismissing alert!",
id="alert_train",
is_open=False,
duration=4000,
)
alert_train2 = dbc.Alert(
"Hello! I am an auto-dismissing alert!",
id="alert_train2",
is_open=False,
duration=4000,
)
# Define Tab Train (2)
tab_train = html.Div([
alert_train,
alert_train2,
dbc.Row(
[
dbc.Col(html.Div([plot_training_acc]), width=6),
dbc.Col([
dbc.Card([
# dbc.CardHeader("Train model"),
dbc.CardBody([
dbc.Form([fold_selector, epochs_input,
optimizer_input, batch_size_input]),
dbc.Button("Train Model", id="train_model",
color="primary", className="mr-1"),
]
),
])
], width=6
),
],
justify="start"
),
dcc.Interval(
id='interval-component',
interval=5*1000, # in milliseconds
disabled=False,
n_intervals=0
),
html.Div("", id='status', style={'display': 'none'}),
html.Div("", id='end_training', style={'display': 'none'})
])
# run_visualization = html.Div([dbc.Button("Run", id="run_visualization",
# color="primary", className="mr-1")])
# Define Tab Visualization (3)
tab_visualization = html.Div([
dbc.Row(
[
dbc.Col(html.Div([plot2D]), width=8),
dbc.Col(
[
dbc.Row([plot_mel], align='center'),
dbc.Row([audio_player], align='center'),
# dbc.Row([run_visualization], align='center')
], width=3),
]
),
dbc.Row(
[
dbc.Col(html.Div([slider_samples]), width=7, align="center"),
],
justify="start"
),
dbc.Row(
[
dbc.Col(html.Div([x_select]), width=2, align="center"),
dbc.Col(html.Div([y_select]), width=2, align="center"),
dbc.Col(html.Div([output_select]), width=2, align="center"),
dbc.Col(html.Div([" "]), width=7, align="center"),
],
justify="around"
),
])
figure_metrics = generate_figure_metrics([], [])
plot_metrics = dcc.Graph(
id="figure_metrics",
figure=figure_metrics,
style={"width": "90%", "display": "inline-block", 'float': 'left'}
)
button_eval = html.Div([
dbc.Button("Evaluate", id="run_evaluation",
className="ml-auto", color="primary")
])
tab_evaluation = html.Div([
dbc.Row(
[
dbc.Col(html.Div([button_eval]), width=2),
dbc.Col(html.Div([""], id='results'), width=2),
]
),
dbc.Row(
[
dbc.Col(html.Div([plot_metrics]), width=10)
]
)
])
# tab_evaluation = html.Div([""], id='results')
X_feat = np.zeros((10, 128, 64))
Y_t = np.zeros((10, 10))
label_list = []*10
figure_features = generate_figure_features(X_feat, Y_t, label_list)
plot_features = dcc.Graph(id='plot_features', figure=figure_features,
style={"height": "100%", "width": "100%"})
# Audio controls
audio_player_demo = dash_audio_components.DashAudioComponents(
id='audio-player-demo', src="", autoPlay=False, controls=True
)
btn_run_demo = dbc.Button("Get new predictions", id="btn_run_demo",
className="ml-auto", color="primary")
upload_file = dcc.Upload([
'Drag and Drop or ',
html.A('Select a File')
], style={
'width': '100%',
'height': '60px',
'lineHeight': '60px',
'borderWidth': '1px',
'borderStyle': 'dashed',
'borderRadius': '5px',
'textAlign': 'center'
}, id='upload-data')
# Define Tab Demo (4)
tab_demo = html.Div([
dbc.Row(
[
dbc.Col(html.Div([upload_file]), width=5),
dbc.Col(html.Div([""], id='demo_output'), width=5),
]
),
dbc.Row(
[
dbc.Col(html.Div([btn_run_demo]), width=2),
dbc.Col(html.Div([audio_player_demo]), width=3),
dbc.Col(html.Div("", id='demo_file_label'), width=3)
]
),
dbc.Row(
[
dbc.Col(html.Div([plot_features]), width=12),
]
),
])
# Define Tabs
tabs = dbc.Tabs(
[
dbc.Tab(tab_model, label="Model definition", tab_id='tab_model'),
dbc.Tab(tab_train, label="Model training", tab_id='tab_train'),
dbc.Tab(tab_visualization, label="Data visualization",
tab_id='tab_visualization'),
dbc.Tab(tab_evaluation, label="Model evaluation",
tab_id='tab_evaluation'),
dbc.Tab(tab_demo, label="Prediction visualization",
tab_id='tab_demo'),
], id='tabs'
)
# Define layout
layout = html.Div([tabs])