-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathEsgeta_GUI.py
340 lines (308 loc) · 15.2 KB
/
Esgeta_GUI.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
import json
import PySimpleGUI as sg
disp = True
def HeaderParams(path):
sg.theme('Default1')
sg.SetOptions(text_justification='right')
with open(path) as jsonFile:
jsonObject = json.load(jsonFile)
jsonFile.close()
parameters = []
for k in jsonObject:
if k != "methods" and k != "explain_methods":
parameters.append(k)
parms = [[sg.Text('model_nature', size=(15, 1)),
sg.Drop(values=('Segmentation', 'Classification'), default_value=jsonObject['model_nature'],
auto_size_text=True),
sg.Text('model_name', size=(15, 1)),
sg.Drop(values=('Vessel_seg_UNET', 'Vessel_seg_UNET'), default_value=jsonObject['model_name'],
auto_size_text=True), ],
[sg.Text('is_3d', size=(15, 1)),
sg.Drop(values=('true', 'false'), default_value=str(jsonObject['is_3d']), auto_size_text=True),
sg.Text('isDepthFirst', size=(15, 1)),
sg.Drop(values=('true', 'false'), default_value=str(jsonObject['isDepthFirst']), auto_size_text=True), ],
[sg.Text('batch_dim_present', size=(15, 1)),
sg.Drop(values=('true', 'false'), default_value=str(jsonObject['batch_dim_present']),
auto_size_text=True),
sg.Text('default', size=(15, 1)),
sg.Drop(values=('true', 'false'), default_value=str(jsonObject['default']), auto_size_text=True), ],
[sg.Text('dataset', size=(15, 1)),
sg.Drop(values=('IXI_MRA', 'dataset_2'), default_value=jsonObject['dataset'], auto_size_text=True),
sg.Text('test_run', size=(15, 1)),
sg.Drop(values=('final_test', 'test'), default_value=jsonObject['test_run'], auto_size_text=True), ],
[sg.Text('resize', size=(15, 1)), sg.In(default_text=jsonObject['resize'], size=(8, 1)),
sg.Text('centre_crop', size=(15, 1)), sg.In(default_text=jsonObject['centre_crop'], size=(8, 1)), ],
[sg.Text('mean_vec', size=(15, 1)), sg.In(default_text=str(jsonObject['mean_vec']), size=(8, 1)),
sg.Text('std_vec', size=(15, 1)), sg.In(default_text=str(jsonObject['std_vec']), size=(8, 1)), ],
[sg.Text('patch_overlap', size=(15, 1)), sg.In(default_text=str(jsonObject['patch_overlap']), size=(8, 1)),
sg.Text('_comment', size=(15, 1)), sg.In(default_text=str(jsonObject['_comment']), size=(8, 1)), ],
[sg.Text('patch_size', size=(15, 1)), sg.In(default_text=str(jsonObject['patch_size']), size=(8, 1)),
sg.Text('log_level', size=(15, 1)), sg.In(default_text=str(jsonObject['log_level']), size=(8, 1)), ],
[sg.Text('output_path', size=(15, 1)), sg.In(default_text=str(jsonObject['output_path']), size=(8, 1)),
sg.Text('amp_enbled', size=(15, 1)),
sg.Drop(values=('true', 'false'), default_value=str(jsonObject['amp_enbled']), auto_size_text=True), ],
[sg.Text('share_gpu_threads', size=(15, 1)),
sg.In(default_text=str(jsonObject['share_gpu_threads']), size=(8, 1)),
sg.Text('timeout_enabled', size=(15, 1)),
sg.Drop(values=('true', 'false'), default_value=str(jsonObject['timeout_enabled']),
auto_size_text=True), ],
]
layout = [[sg.Frame('Parameters', parms, title_color='black', font='Any 12')],
[sg.Submit(size=(15, 1), button_text="Select Methods"), sg.Cancel(size=(15, 1))]]
window = sg.Window('Torch Esgeta', font=("Helvetica", 12)).Layout(layout)
button, values = window.Read()
sg.SetOptions(text_justification='left')
if disp:
print(button, values)
param_dict = dict(zip(parameters, values.values()))
param_dict.update({"methods": "0"})
return param_dict, jsonObject
def MethodsSelector():
sg.theme('Default1')
sg.SetOptions(text_justification='right')
l = 30
feature_based = [
[
sg.Checkbox('Shapley Value Sampling [captum]', size=(l, 1)),
sg.Checkbox('Feature Ablation [captum]', size=(l, 1)),
sg.Checkbox('Occlusion [captum]', size=(l, 1)),
sg.Checkbox('Score cam [CNN Vis]', size=(l, 1)),
],
]
gradient_based = [
[
sg.Checkbox('Guided Backprop [CNN Vis]', size=(l, 1)),
sg.Checkbox('Guided Backprop [captum]', size=(l, 1)),
sg.Checkbox('Guided Backprop [torchray]', size=(l, 1)),
sg.Checkbox('Saliency [captum]', size=(l, 1)),
],
[
sg.Checkbox('Input x gradient [captum]', size=(l, 1)),
sg.Checkbox('Integrated Grad [CNN Vis]', size=(l, 1)),
sg.Checkbox('Deconvolution [captum]', size=(l, 1)),
sg.Checkbox('Deconvolution [torchray]', size=(l, 1)),
],
[
sg.Checkbox('Grad times image [CNN Vis]', size=(l, 1)),
sg.Checkbox('Deep Lift [captum]', size=(l, 1)),
sg.Checkbox('Deep Lift Shap [captum]', size=(l, 1)),
sg.Checkbox('Integrated Gradients [captum]', size=(l, 1)),
],
[
sg.Checkbox('Gradient Shap [captum]', size=(l, 1)),
sg.Checkbox('Guided Grad Cam [captum]', size=(l, 1)),
sg.Checkbox('Guided Grad Cam [CNN Vis]', size=(l, 1)),
sg.Checkbox('Vanilla Backprop [CNN Vis]', size=(l, 1)),
],
[
sg.Checkbox('Layer Visualization [CNN Vis]', size=(l, 1)),
]
]
Interpretability_Model_Attribution = [
[sg.Frame('Feature Based', feature_based, font='Any 12', title_color='black')],
[sg.Frame('Gradient Based', gradient_based, font='Any 12', title_color='black')]
]
Interpretability_Layer_Attribution = [
[
sg.Checkbox('Layer Conductance [captum]', size=(l, 1)),
sg.Checkbox('Layer Activation [captum]', size=(l, 1)),
sg.Checkbox('Internal Influence [captum]', size=(l, 1)),
sg.Checkbox('Layer Grad Shap [captum]', size=(l, 1)),
],
[
sg.Checkbox('Layer DeepLift [captum]', size=(l, 1)),
sg.Checkbox('Layer Activation GBP[CNN Vis]', size=(l, 1)),
sg.Checkbox('Layer GradCam [captum]', size=(l, 1)),
sg.Checkbox('Grad Cam [CNN Vis]', size=(l, 1)),
],
[
sg.Checkbox('LayerGradientXActivation [captum]', size=(l, 1)),
sg.Checkbox('Grad Cam [torchray]', size=(l, 1)),
sg.Checkbox('Gradient [torchray]', size=(l, 1)),
sg.Checkbox('Contrast Excitation Backprop [torchray]', size=(l, 1)),
],
[
sg.Checkbox('Contrast Excitation Backprop [torchray]', size=(l, 1)),
sg.Checkbox('Linear Approx [torchray]', size=(l, 1)),
]
]
Explainability = [
[
sg.Checkbox('Render Visualization [lucent]', size=(l, 1)),
sg.Checkbox('Segmentation [lime]', size=(l, 1)),
sg.Checkbox('DeepDream [CNN Vis]', size=(l, 1)),
],
]
layout = [
[sg.Frame('Interpretability : Model Attribution', Interpretability_Model_Attribution, font='Any 12', title_color='black',)],
[sg.Frame('Interpretability : Layer Attribution', Interpretability_Layer_Attribution, font='Any 12', title_color='black')],
[sg.Frame('Explainability', Explainability, font='Any 12', title_color='black')],
[sg.Submit(size=(20, 1), button_text="Update Fields"), sg.Cancel(size=(20, 1))]
]
window = sg.Window('Torch Esgeta - Methods selector', font=("Helvetica", 12), resizable=True,
auto_size_text=True, auto_size_buttons=True).Layout(layout)
button, values = window.Read()
sg.SetOptions(text_justification='left')
if disp:
print(button, values)
methods = [
'ShapleyValueSampling_captum',
'Feature_Ablation_captum',
'Occlusion_captum',
'score_cam_CNN Visualization',
'guided_backprop_CNN Visualization',
'Guided_Backprop_captum',
'Guidedbackprop_torchray',
'Saliency_captum',
'input_x_gradient_captum',
'integrated_grad_CNN Visualization',
'Deconvolution_captum',
'Deconv_torchray',
'grad_times_image_CNN Visualization',
'Deep_Lift_captum',
'deep_lift_shap_captum',
'Integrated_Gradients_captum',
'gradient_shap_captum',
'Guided_Grad_Cam_captum',
'guided_grad_cam_CNN Visualization',
'vanilla_backprop_CNN Visualization',
'layer_visualization_CNN Visualization',
'layer_conductance_captum',
'Layer_Activation_captum',
'internal_influence_captum',
'layer_grad_shap_captum',
'LayerDeepLift_captum',
'layer_activation_guided_backprop_CNN Visualization',
'LayerGradCam_captum',
'grad_cam_CNN Visualization',
'LayerGradientXActivation_captum',
'Gradcam_torchray',
'Gradient_torchray',
'contrast_excitation_backprop_torchray',
'contrast_excitation_backprop_torchray',
'Linearapprox_torchray',
'lucent_render_vis_lucent',
'segmentation_lime',
'DeepDream_CNN Visualization'
]
method_names = []
for i in values:
if values[i]:
method_names.append(methods[i])
print(method_names)
return method_names
def loadParams(method_name, library_name, path):
with open(path) as jsonFile:
jsonObject = json.load(jsonFile)
jsonFile.close()
methods = jsonObject["methods"]
parameters = ""
for k in range(len(methods)):
if method_name.lower() in methods[k]["method_name"].lower() and methods[k]["library"] == library_name:
parameters = methods[k]
break
parms = [[sg.Text('inpt_transform_req', size=(15, 1)),
sg.Drop(values=('true', 'false'), default_value=str(parameters['inpt_transform_req']),
auto_size_text=True),
sg.Text('visualize_method', size=(15, 1)),
sg.Drop(values=('heat_map', 'heat_map'), default_value=parameters['visualize_method'],
auto_size_text=True), ],
[sg.Text('sign', size=(15, 1)),
sg.Drop(values=('positive', 'negative'), default_value=str(parameters['sign']), auto_size_text=True),
sg.Text('show_colorbar', size=(15, 1)),
sg.Drop(values=('true', 'false'), default_value=str(parameters['show_colorbar']), auto_size_text=True), ],
[sg.Text('device_id', size=(15, 1)), sg.In(default_text=parameters['device_id'], size=(8, 1)),
sg.Text('share_gpu', size=(15, 1)),
sg.Drop(values=('true', 'false'), default_value=str(parameters['share_gpu']), auto_size_text=True), ],
[sg.Text('patch_required', size=(15, 1)),
sg.Drop(values=('true', 'false'), default_value=str(parameters['patch_required']), auto_size_text=True),
sg.Text('use', size=(15, 1)),
sg.Drop(values=('true', 'false'), default_value=str(parameters['use']), auto_size_text=True), ],
[sg.Text('uncertainity_metrics', size=(15, 1)),
sg.Drop(values=('true', 'false'), default_value=str(parameters['uncertainity_metrics']),
auto_size_text=True),
sg.Text('uncertainity_cascading', size=(15, 1)),
sg.In(default_text=parameters['uncertainity_cascading'], size=(8, 1)), ],
[sg.Text('uncertainity', size=(15, 1)),
sg.Drop(values=('true', 'false'), default_value=str(parameters['uncertainity']), auto_size_text=True),
sg.Text('keywords', size=(15, 1)), sg.In(default_text=str(parameters['keywords']), size=(8, 1)), ]]
text = 'Parameteres for - ' + str(method_name)
layout = [[sg.Frame(text, parms, title_color='black', font='Any 12')],
[sg.Submit(size=(15, 1), button_text="Generate JSON"), sg.Submit(size=(20, 1), button_text="Next"),
sg.Cancel(size=(15, 1))]]
window = sg.Window(str(method_name), font=("Helvetica", 12)).Layout(layout)
button, values = window.Read()
if disp:
print("#######################################################################################\n")
print(button)
sg.SetOptions(text_justification='left')
flag = 0
if button == "Generate JSON":
if disp:
print("inside JSON Creator")
print(parameters)
flag = 1
return parameters, flag
else:
# print(button, values)
parameters['inpt_transform_req'] = values[0]
parameters['visualize_method'] = values[1]
parameters['sign'] = values[2]
parameters['show_colorbar'] = values[3]
parameters['device_id'] = values[4]
parameters['share_gpu'] = values[5]
parameters['patch_required'] = values[6]
parameters['use'] = values[7]
parameters['uncertainity_metrics'] = values[8]
parameters['uncertainity_cascading'] = values[9]
parameters['uncertainity'] = values[10]
parameters['keywords'] = values[11]
# print(parameters)
for k in range(len(methods)):
if method_name.lower() in methods[k]["method_name"].lower() and methods[k]["library"] == library_name:
if disp:
print("Before Update:", methods[k])
methods[k] = parameters
if disp:
print("After Update:", methods[k])
break
if disp:
print(methods)
return parameters, flag, methods
def main(JsonFilePath):
param_dict, jsonObject = HeaderParams(JsonFilePath)
if disp:
print("########################### V1 - START ###########################")
print(jsonObject)
print("########################### V1 - END ###########################")
print("\n\n")
print("########################### V2 - START ###########################")
values = MethodsSelector()
method = []
library = []
for i in range(len(values)):
library_name = values[i].split("_")[-1]
library.append(library_name)
library_name = "_" + library_name
method_name = values[i].replace(library_name, "")
method.append(method_name)
if disp:
print("########################### V2 - END ###########################")
print("\n\n")
print("########################### V3 - START ###########################")
for i in range(len(values)):
if i == 0:
path = "Base.json"
else:
path = "Output.json"
a, flag, jsonFile = loadParams(method[i], library[i], path)
if flag:
break
param_dict["methods"] = jsonFile
with open('Output.json', 'w') as f:
json.dump(param_dict, f, indent=5)
if disp:
print("########################### V3 - END ###########################")
if __name__ == "__main__":
jsonFilePath = "TorchEsegeta_cfg_Misc_Seg_3d.json"
main(jsonFilePath)