-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui.py
231 lines (196 loc) · 7.74 KB
/
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
import tkinter as tk
from test import produce_cam
from test import evaluate_model
import argparse
#Input Modes
MODES = ['OBTAIN CAMS', 'TEST MODELS']
#List all model files
#List all model names
BASE_FILES = ['DenseNet201', 'EfficientNetB7', 'InceptionResNetV2', 'ResNet50V2', 'ResNet152V2', 'NASNetLarge', 'Xception', 'InceptionV3', 'DenseNet121', 'EfficientNetB0', 'NASNetMobile', 'MobileNetV2', 'EnsembleModel']
PROPOSED_FILES = ['KD-ComMoN', 'ComMoN']
MODEL_FILES = PROPOSED_FILES + BASE_FILES
FONT = 'Helvetica 10 underline'
class ChooseInput:
def __init__(self, root):
self.root = root
self.root.title("PSR Choose Input")
#Select Mode
self.l1 = tk.Label(master=root, text="Use Case", fg="blue", font=FONT)
self.l1.grid(row=0, column =0, pady = 4)
self.droptext1 = tk.StringVar()
self.droptext1.set("OBTAIN CAMS")
self.drop1 = tk.OptionMenu(root , self.droptext1 , *MODES, command=self.validate1)
self.drop1.grid(row=1, column =0, pady = 1, padx = 5)
#Select Model
self.l2 = tk.Label(master=root, text="Select Model", fg="blue", font=FONT)
self.l2.grid(row=0, column =1, pady = 4)
self.droptext2 = tk.StringVar()
self.droptext2.set("KD-ComMoN")
self.drop2 = tk.OptionMenu(root , self.droptext2 , *MODEL_FILES, command=self.validate3)
self.drop2.grid(row=1, column =1, padx = 5)
#Select Cams
self.l3 = tk.Label(master=root, text="Select CAMs", fg="blue", font=FONT)
self.l3.grid(row=3, column =0, pady = 5, columnspan = 2)
self.check1 = tk.BooleanVar()
self.check2 = tk.BooleanVar()
self.check3 = tk.BooleanVar()
self.check4 = tk.BooleanVar()
self.check5 = tk.BooleanVar()
self.check6 = tk.BooleanVar()
self.cb1 = tk.Checkbutton(root, text = "Grad-Cam",
variable = self.check1,
onvalue = True,
offvalue = False,
height = 2,
width = 10,
command=self.validate2)
self.cb2 = tk.Checkbutton(root, text = "Grad-Cam++",
variable = self.check2,
onvalue = True,
offvalue = False,
height = 2,
width = 10,
command=self.validate2)
self.cb3 = tk.Checkbutton(root, text = "F-ScoreCam",
variable = self.check3,
onvalue = True,
offvalue = False,
height = 2,
width = 10,
command=self.validate2)
self.cb4 = tk.Checkbutton(root, text = "ScoreCam",
variable = self.check4,
onvalue = True,
offvalue = False,
height = 2,
width = 10,
command=self.validate2)
self.cb5 = tk.Checkbutton(root, text = "CAMERAS",
variable = self.check5,
onvalue = True,
offvalue = False,
height = 2,
width = 10,
command=self.validate2)
self.cb6 = tk.Checkbutton(root, text = "Guided BP",
variable = self.check6,
onvalue = True,
offvalue = False,
height = 2,
width = 10,
command=self.validate2)
self.cb1.grid(row=4, column =0)
self.cb2.grid(row=4, column =1)
self.cb3.grid(row=5, column =0)
self.cb4.grid(row=5, column =1)
self.cb5.grid(row=6, column =0)
self.cb6.grid(row=6, column =1)
#Choose Images
self.b1 = tk.Button(master=root, text="SELECT IMAGES", command=self.add_input_path)
self.b1.grid(row=7, column =0, pady = 2, columnspan = 2)
self.labletext = tk.StringVar()
self.labletext.set("0 Selected")
self.l4 = tk.Label(master=root, textvariable=self.labletext, fg="green")
self.l4.grid(row=8, column =0, pady = 2, columnspan = 2)
#Start button
self.b2 = tk.Button(master=root, text="START",command=self.start)
self.b2.grid(row=9, column =0, pady = 10, columnspan = 2)
self.b2.config(state= 'disabled')
self.input_files = []
def add_input_path(self):
#Openfile
input_path = tk.filedialog.askopenfilenames(title="Select an Image File", initialdir ='./', filetypes=[("image", ".jpeg"), ("image", ".png"), ("image", ".jpg")])
self.input_files.extend(input_path)
self.labletext.set(str(len(self.input_files)) + " Selected")
#Enable START button if atleast one input selected
if len(self.input_files) > 0 and self.is_selected:
self.b2.config( state= 'normal')
def validate1(self, ele):
is_eval = False
state = 'normal'
if self.droptext1.get() == 'TEST MODELS':
is_eval = True
state = 'disabled'
if not is_eval:
self.b1.config( state= 'normal')
self.b2.config(state='disabled')
else:
self.b1.config( state= 'disabled')
self.b2.config(state='normal')
#Uncheck all checkboxes
self.check1.set(False)
self.check2.set(False)
self.check3.set(False)
self.check4.set(False)
self.check5.set(False)
self.check6.set(False)
#Enable all checkboxes
self.cb1.config(state=state)
self.cb2.config(state=state)
self.cb3.config(state=state)
self.cb4.config(state=state)
self.cb5.config(state=state)
self.cb6.config(state=state)
def validate2(self):
self.is_selected = self.check1.get() or self.check2.get() or self.check3.get() or self.check4.get() or self.check5.get() or self.check6.get()
def validate3(self, ele):
#Disable Checkbox in case of Ensenble model
if self.droptext2.get() == 'EnsembleModel' or self.droptext1.get() == 'TEST MODELS':
self.cb1.config( state= 'disabled')
self.cb2.config( state= 'disabled')
self.cb3.config( state= 'disabled')
self.cb4.config( state= 'disabled')
self.cb5.config( state= 'disabled')
self.cb6.config( state= 'disabled')
else:
self.cb1.config( state= 'normal')
self.cb2.config( state= 'normal')
self.cb3.config( state= 'normal')
self.cb4.config( state= 'normal')
self.cb5.config( state= 'normal')
self.cb6.config( state= 'normal')
def close(self):
#Close GUI
self.root.destroy()
def start(self):
self.close()
arg_parser = argparse.ArgumentParser(description='Calculate Inference Time', epilog='')
arg_parser.add_argument("-g", "--enable_gpu", help="Enable GPU", action="store_true", default=False)
args = arg_parser.parse_args()
enable_gpu = args.enable_gpu
#Get arguments
input_files = self.input_files
mode = self.droptext1.get()
model_name = self.droptext2.get()
is_gradcam = self.check1.get()
is_gradcamplus = self.check2.get()
is_f_scorecam = self.check3.get()
is_scorecam = self.check4.get()
is_camerascam = self.check5.get()
is_guidedbp = self.check6.get()
cams = {'Grad-Cam': is_gradcam,
'Grad-Cam++': is_gradcamplus,
'Faster ScoreCam': is_f_scorecam,
'ScoreCam': is_scorecam,
'CAMERAS-Cam':is_camerascam,
'Guided BP':is_guidedbp}
if mode != 'TEST MODELS':
print("-----------------------------------------------")
print("[INFO] Input Summary")
print(" 1.Model Name: ", model_name)
print(" 2.CAMs Selected:", [k for k in cams.keys() if cams[k]])
print(" 3.Images Selected:", [f.split('/')[-1] for f in input_files])
print("------------------------------------------------")
produce_cam(model_name, is_gradcam, is_gradcamplus, is_f_scorecam,
is_scorecam, is_camerascam, is_guidedbp, input_files, enable_gpu)
else:
evaluate_model(model_name, enable_gpu)
if __name__ == "__main__":
print("[INFO] Opening GUI")
#Initialize GUI
root = tk.Tk()
root.resizable(False, False)
root.geometry("")
my_gui = ChooseInput(root)
root.mainloop()
print("[INFO] Closing GUI")