-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Expand file tree
/
Copy pathdemo_utils.py
More file actions
109 lines (94 loc) · 3.65 KB
/
demo_utils.py
File metadata and controls
109 lines (94 loc) · 3.65 KB
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
from dash import Dash, html, dcc, Input, Output, State, callback, callback_context
import pandas as pd
import pathlib
# get relative data folder
PATH = pathlib.Path(__file__).parent
DATA_PATH = PATH.joinpath("data").resolve()
def demo_explanation(demo_mode):
if demo_mode:
# Markdown files
with open(PATH.joinpath("demo.md"), "r") as file:
demo_md = file.read()
return html.Div(
html.Div([dcc.Markdown(demo_md, className="markdown")]),
style={"margin": "10px"},
)
def demo_callbacks(app, demo_mode):
if demo_mode:
@app.server.before_first_request
def load_demo_run_logs():
global data_dict, demo_md
names = [
"step",
"train accuracy",
"val accuracy",
"train cross entropy",
"val cross entropy",
]
data_dict = {
"softmax": {
"cifar": pd.read_csv(
DATA_PATH.joinpath("cifar_softmax_run_log.csv"), names=names
),
"mnist": pd.read_csv(
DATA_PATH.joinpath("mnist_softmax_run_log.csv"), names=names
),
"fashion": pd.read_csv(
DATA_PATH.joinpath("fashion_softmax_run_log.csv"), names=names
),
},
"cnn": {
"cifar": pd.read_csv(
DATA_PATH.joinpath("cifar_cnn_run_log.csv"), names=names
),
"mnist": pd.read_csv(
DATA_PATH.joinpath("mnist_cnn_run_log.csv"), names=names
),
"fashion": pd.read_csv(
DATA_PATH.joinpath("fashion_cnn_run_log.csv"), names=names
),
},
}
@app.callback(
Output("storage-simulated-run", "data"),
[Input("interval-simulated-step", "n_intervals")],
[
State("dropdown-demo-dataset", "value"),
State("dropdown-simulation-model", "value"),
],
)
def simulate_run(n_intervals, demo_dataset, simulation_model):
if simulation_model and demo_dataset and n_intervals > 0:
step = n_intervals * 5
run_logs = data_dict[simulation_model][demo_dataset]
run_below_steps = run_logs[run_logs["step"] <= step]
json = run_below_steps.to_json(orient="split")
return json
@app.callback(
Output("interval-simulated-step", "n_intervals"),
[
Input("dropdown-demo-dataset", "value"),
Input("dropdown-simulation-model", "value"),
],
)
def reset_interval_simulated_step(*_):
return 0
@app.callback(
Output("run-log-storage", "data"),
[Input("interval-log-update", "n_intervals")],
[State("storage-simulated-run", "data")],
)
def get_run_log(_, simulated_run):
if simulate_run:
return simulated_run
@app.callback(
Output("div-total-step-count", "children"),
[Input("dropdown-demo-dataset", "value")],
)
def total_step_count(dataset_name):
if dataset_name is not None:
dataset = data_dict["softmax"][dataset_name]
return html.H6(
f"Total Steps: {dataset['step'].iloc[-1]}",
style={"margin-top": "3px", "float": "right"},
)