-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathui2.py
77 lines (64 loc) · 2.03 KB
/
ui2.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
from tkinter import filedialog
from tkinter import messagebox
from PIL import ImageTk, Image
class uifunctions:
def __init__(self, master):
return True
def bootupmodel(self):
reawake=self.model.reawakemodel()
if reawake==False:
messagebox.showinfo("Attention","It looks like you haven't built the model.\n"+"Build it first.")
return False
messagebox.showinfo("Info","Model loaded. Ready to go !")
return True
def selectfile(self):
self.filename = filedialog.askopenfilename()
self.selectedFile_variable.set(self.filename)
self.displayimage()
return True
def selectfolder(self):
self.trainfolderText = filedialog.askdirectory()
self.folderOK=1
self.trainfolder_variable.set(self.trainfolderText)
return True
def displayimage(self):
img2 = Image.open(self.filename)
img2 = img2.resize((140,220), Image.ANTIALIAS)
img2 = ImageTk.PhotoImage(img2)
#self.imagePanel.configure(image=img2)
#self.imagePanel.image=img2
self.imagePanel2.configure(image=img2)
self.imagePanel2.image=img2
return True
def quitwindow(self):
self.source.closedatabase()
self.master.quit()
return True
def scan(self):
if self.filename=="Select an image" or not self.filename:
messagebox.showinfo("Info","You must select an image")
return False
try:
testresultarray=self.model.test(self.filename)
except:
messagebox.showwarning("Alert","Model not ready. Boot up the model first.")
return False
print (testresultarray) #array of probabilities
testresult=max(testresultarray)
accuracy=round(testresult*100,2)
position=0
for value in testresultarray:
if testresult==value:
break
else:
position+=1
position=position+1
return position,accuracy
def buildmodel(self):
self.model.buildModel(self.trainfolderText)
self.tab2Text_variable.set("Model build complete. You can now identify image.")
getresponse=messagebox.askyesno("Info","Model Built Successful.\n"+
"Do you want to update to your previously trained weights ?")
if getresponse==True:
self.model.storemodel()
return True