Diff of /dash/main_2.py [000000] .. [fa8046]

Switch to unified view

a b/dash/main_2.py
1
# - * -coding: utf - 8 - * -
2
import base64
3
import time
4
import dash
5
import dash_core_components as dcc
6
import dash_html_components as html
7
import dash_daq as daq
8
9
10
import pandas as pd
11
import numpy as np
12
import numpy as np
13
14
import cv2
15
16
17
# prepare the data--begin
18
19
cases = pd.read_csv('../data/valid-acl.csv',
20
                    header=None,
21
                    names=['Case', 'Abnormal'],
22
                    dtype={
23
                        'Case': str,
24
                        'Abnormal': np.int64
25
                    }
26
                    )
27
case_list = cases['Case'].tolist()
28
29
30
predictions = pd.read_csv('./val_data.csv')
31
32
33
# prepare the data--end
34
35
36
app = dash.Dash()
37
38
# Boostrap CSS.
39
40
app.css.append_css({
41
    'external_url': "https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
42
})  # noqa: E501
43
44
45
app.layout = html.Div(
46
    [
47
        html.Div(
48
            html.H1(children='Interpretation of MRNet models through Class Activation Maps (CAM)',
49
                    style={
50
                        'text-align': 'center'
51
                    }
52
                    ),
53
        ),
54
55
        html.Div(
56
            [
57
                html.Div(
58
                    [
59
                        html.P('Select an MRI exam:'),
60
                        html.Div([
61
                            dcc.Dropdown(
62
                                id='cases',
63
                                options=[{
64
                                    'label': case,
65
                                    'value': case
66
                                }
67
                                    for case in case_list
68
                                ],
69
                                placeholder="Pick a case",
70
                                clearable=False
71
                            )
72
                        ],
73
                            style={
74
                            'margin-bottom': 20
75
                        }
76
                        ),
77
                    ],
78
                    className='col-3',
79
                    style={
80
                        'margin-top': '10'
81
                    }
82
                ),
83
                html.Div([
84
                    html.Div([
85
                        html.Div([
86
                            html.P('Select true labels :'),
87
                            dcc.RadioItems(
88
                                id="label_radioitems",
89
                                options=[
90
                                    {'label': 'Positive (ACL tear)',
91
                                     'value': 'acl'},
92
                                    {'label': 'Negative (Normal)',
93
                                     'value': 'normal'},
94
                                ],
95
                                value='acl',
96
                                labelStyle={'display': 'inline-block'}
97
                            ),
98
                        ],
99
                            style={'float': 'left', 'width': '45%'}
100
                        ),
101
102
                        html.Div([
103
                            html.P('Select predicted labels :'),
104
                            dcc.RadioItems(
105
                                id="pred_radioitems",
106
                                options=[
107
                                    {'label': 'Positive (ACL tear)',
108
                                     'value': 'acl'},
109
                                    {'label': 'Negative (Normal)',
110
                                     'value': 'normal'},
111
                                ],
112
                                value='acl',
113
                                labelStyle={'display': 'inline-block'}
114
                            ),
115
                        ]
116
                        ),
117
                    ]),
118
                ],
119
                    className='col-6'
120
                ),
121
                html.Div([
122
                    html.Div(id="number_of_cases"),
123
                    html.Span(
124
                        "txt",
125
                        id="label_badge",
126
                        className="badge badge-success badge-large",
127
                        style={'font-size': '15px'}
128
                    ),
129
                ],
130
                    className='col-3'
131
132
                )
133
134
            ],
135
            className="row alert alert-success",
136
        ),
137
138
        html.Div([
139
            html.Div([
140
                html.P(id='summary', style={'font-size': '20px'}),
141
                html.Div([
142
                    html.Div('This probability is a weighted average of the three probabilities of tears over each plane', style={
143
                        'float': 'left', 'font-size': '20px'}),
144
                    html.Div('Slide over the slices of each MRI to inspect highlighted regions of tear as depicted by CAMs', style={
145
                        'float': 'left', 'font-size': '20px'}),
146
                ],
147
                )
148
            ],
149
                className="col-12 alert alert-info"),
150
        ],
151
            className='row'
152
        ),
153
154
        html.Hr(),
155
156
        html.Div(
157
            [
158
                html.Div([
159
                    html.Div([
160
                        dcc.Slider(id='slider_axial', updatemode='drag')
161
                    ],
162
                        style={'margin-right': '5px'}
163
164
                    ),
165
                    html.Hr(),
166
                    html.P(id="score_axial", style={'text-align': 'center'}),
167
                    html.Div([
168
                        html.Div([
169
                            html.Img(
170
                                id="slice_axial",
171
                            ),
172
                        ],
173
                            style={'float': 'left', 'margin-right': '5px'}
174
                        ),
175
                        html.Div([
176
                            html.Img(
177
                                id="cam_axial",
178
                            ),
179
                        ],
180
                        )
181
                    ],
182
183
                    ),
184
                    html.P(id="title_axial", style={'text-align': 'center'})
185
                ],
186
                    className="col-4"
187
                ),
188
                html.Div([
189
                    html.Div([
190
                        dcc.Slider(id='slider_coronal', updatemode='drag')
191
                    ],
192
                        style={'margin-right': '5px'}
193
194
                    ),
195
                    html.Hr(),
196
                    html.P(id="score_coronal", style={'text-align': 'center'}),
197
                    html.Div([
198
                        html.Div([
199
                            html.Img(
200
                                id="slice_coronal",
201
                            ),
202
                        ],
203
                            style={'float': 'left', 'margin-right': '5px'}
204
                        ),
205
                        html.Div([
206
                            html.Img(
207
                                id="cam_coronal",
208
                            ),
209
                        ],
210
                        )
211
                    ],
212
213
                    ),
214
                    html.P(id="title_coronal", style={'text-align': 'center'})
215
                ],
216
                    className="col-4"
217
                ),
218
                html.Div([
219
                    html.Div([
220
                        dcc.Slider(id='slider_sagittal', updatemode='drag')
221
                    ]),
222
                    html.Hr(),
223
                    html.P(id="score_sagittal", style={
224
                           'text-align': 'center'}),
225
                    html.Div([
226
                        html.Div([
227
                            html.Img(
228
                                id="slice_sagittal",
229
                            ),
230
                        ],
231
                            style={'float': 'left', 'margin-right': '5px'}
232
                        ),
233
                        html.Div([
234
                            html.Img(
235
                                id="cam_sagittal",
236
                            ),
237
                        ],
238
                        )
239
                    ],
240
241
                    ),
242
                    html.P(id="title_sagittal", style={'text-align': 'center'})
243
244
245
                ],
246
                    className="col-4"
247
                ),
248
249
            ],
250
            className='row'
251
        )
252
253
254
255
256
257
258
    ],
259
    className='container-fluid',
260
)
261
262
263
if __name__ == '__main__':
264
    app.run_server(debug=True, port=8060)