-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapp.py
More file actions
102 lines (90 loc) · 3.46 KB
/
app.py
File metadata and controls
102 lines (90 loc) · 3.46 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
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import numpy as np
import torch
from src.models.losses import AVAILABLE_IOU
external_stylesheets = [
"https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap-grid.min.css"]
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
GT = "[(10, 10, 20, 20), (80, 80, 90, 90)]"
PREDICTION = ("[(10, 10, 20, 20), (" +
"index * 10 + (1 - index) * 80, " +
"index * 10 + (1 - index) * 80, " +
"index * 20 + (1 - index) * 90, " +
"index * 20 + (1 - index) * 90" +
")]")
INDEXES = np.arange(-.1, 1.1, 0.1)
def _reload(gt, prediction):
ground_truth = torch.tensor(eval(gt), dtype=torch.float32)
boxes_list = [
torch.tensor(eval(prediction))
for index in INDEXES]
values = {}
for key, value in AVAILABLE_IOU.items():
values[key] = [1 - value(ground_truth, boxes)
for boxes in boxes_list]
return values
VALUES = _reload(GT, PREDICTION)
MARKS = {i if not i.is_integer() else int(i) : f'{i:.1f}' for i in INDEXES}
app.layout = html.Div([
dcc.Input(id="input_gt", type="text", debounce=True, className="col-12",
value=GT),
dcc.Input(id="input_p", type="text", debounce=True, className="col-12",
value=PREDICTION),
html.Div([
html.Div([
dcc.Graph(id='curve', figure={}),
dcc.Slider(id='slider', min=-.1, max=1.1, step=0.1, value=0,
marks=MARKS)
], className="col-6"),
dcc.Graph(id='square', className="col-6", figure={})
], className="d-flex"),
])
def _get_x(box):
return [box[0].item(), box[2].item(), box[2].item(), box[0].item(),
box[0].item()]
def _get_y(box):
return [box[1].item(), box[1].item(), box[3].item(), box[3].item(),
box[1].item()]
@app.callback(
Output(component_id='square', component_property='figure'),
[Input(component_id='slider', component_property='value'),
Input(component_id='input_gt', component_property='value'),
Input(component_id='input_p', component_property='value')]
)
def update_output_div(index, gt, p):
ground_truth = torch.tensor(eval(gt), dtype=torch.float32)
boxes_list = torch.tensor(eval(p))
return {
'data': [
{'x': _get_x(box), 'y': _get_y(box), 'type': 'line', 'name': 'ground truth'}
for box in ground_truth] + [
{'x': _get_x(box), 'y': _get_y(box), 'type': 'line', 'name': 'prediction'}
for box in boxes_list] + [
],
'layout': {'title': 'Boxes'}
}
@app.callback(
Output(component_id='curve', component_property='figure'),
[Input(component_id='slider', component_property='value'),
Input(component_id='input_gt', component_property='value'),
Input(component_id='input_p', component_property='value')]
)
def update_line(i, gt, p):
values = _reload(gt, p)
return {
'data': [
{'x': INDEXES, 'y': value, 'type': 'line', "name": f"{key.title()} IoU"}
for key, value in values.items()
] + [
{'x': [i for _ in range(2500)],
'y': np.arange(0., max([
v for value in values.values() for v in value]), 1e-3),
'type': 'line', "showlegend": False},
],
'layout': {'title': 'Losses'}
}
if __name__ == '__main__':
app.run_server(debug=True)