-
Notifications
You must be signed in to change notification settings - Fork 14
/
application_ml
114 lines (82 loc) · 2.84 KB
/
application_ml
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
# -*- coding: utf-8 -*-
"""
Created on Mon Mar 9 00:58:49 2020
@author: R2J
"""
from numpy import *
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing import image
from tkinter import *
from PIL import ImageTk, Image
from tkinter import filedialog
def wrt(st,fname):
file = open(fname,"w+")
file.write(st)
file.close()
def red(fname):
file = open(fname,"r")
f=file.read()
file.close()
return f
def open_img():
try:
x = openfilename()
wrt(x,"upload");print(x);
img =Image.open(x)
except:
x = 'images/error.png'
print(x);
img =Image.open(x)
img = img.resize((325, 200), Image.ANTIALIAS)
img = ImageTk.PhotoImage(img)
panel = Label(root, image = img)
panel.image = img
panel.place(x=455, y=100)
def openfilename():
filename = filedialog.askopenfilename(title ='UPLOAD IMAGE')
return filename
def callback():
cell="\n IMAGE FILE NOT UPLOADED..."
try:
model = load_model('models/malaria.h5')
#model.summary()
test_image=image.load_img(red("upload"),target_size=(50,50,3))
#imgplot = plt.imshow(test_image)
#plt.show()
test_image=image.img_to_array(test_image)
test_image=expand_dims(test_image,axis=0)
result = model.predict(test_image)
cell="PARASITIZED" if result[0][1]==1 else "UNINFECTED"
output.set("\n "+cell+" CELL DETECTED !\n");print(cell)
except Exception as e:
output.set(cell);print(e)
root = Tk()
root.title("MALARIA")
output=StringVar();
root.attributes('-fullscreen',True)
#root.geometry("500x500")
#root['bg'] = 'black'
background = PhotoImage(file = "images/cover_ml.png")
Label(root,image = background).place(x=0, y=0)
#root.resizable(width = True, height = True)
img =Image.open("images/input.png")
img = img.resize((325, 200), Image.ANTIALIAS)
img = ImageTk.PhotoImage(img)
panel = Label(root, image = img)
panel.image = img
panel.place(x=455, y=100)
upload = PhotoImage(file = r"images/upload.png")
Button(root, text = "upload",bd=0,highlightthickness=0,image = upload,
command = open_img).place(x=150, y=150)
Label(root, text="\nOUTPUT\n",
width=25,
font=("Bauhaus 93", 20)).place(x=432, y=335)
Label(root, text="",textvariable = output,
font=("Bauhaus 93", 20)).place(x=432, y=335)
detect = PhotoImage(file = r"images/detect.png")
Button(root, text="detect",bd=0,highlightthickness=0,image = detect,
command = callback).place(x=150,y=340)
close = PhotoImage(file = r"images/home.png")
Button(root, text = "close",image = close,highlightthickness=0,
command = root.destroy).place(x=0,y=0)
root.mainloop()