-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclassifier.py
More file actions
67 lines (53 loc) · 1.45 KB
/
classifier.py
File metadata and controls
67 lines (53 loc) · 1.45 KB
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
from taipy.gui import Gui
from tensorflow.keras import models
from PIL import Image
import numpy as np
class_names = {
0: 'airplane',
1: 'automobile',
2: 'bird',
3: 'cat',
4: 'deer',
5: 'dog',
6: 'frog',
7: 'horse',
8: 'ship',
9: 'truck',
}
model = models.load_model('model.keras')
def predict_image(model, path_to_img):
img = Image.open(path_to_img)
img = img.convert('RGB')
img = img.resize((32,32))
#Normalise images
data = np.asarray(img)
data = data / 255
probs = model.predict(np.array([data])[:1]) # Trick neural network to proccess a single image
top_prob = probs.max()
top_pred = class_names[np.argmax(probs)]
return top_prob, top_pred
content =''
logo_path = 'logo.png'
img_path= 'placeholder_image.png'
prob = 0
pred = ''
index = '''
<|text-center|
<|{logo_path}|image|width=25vw|>
<|{content}|file_selector|extensions=.png|>
select an image from your file system
<|{pred}|>
<|{img_path}|image|>
<|{prob}|indicator|value={prob}|min=0|max=100|width=25vw|>
>
'''
def on_change(state, var_name,var_val):
if var_name == 'content':
top_prob, top_pred = predict_image(model, var_val)
state.prob = round(top_prob * 100)
state.pred = 'This is a ' + top_pred
state.img_path = var_val
#print(var_name, var_val) DEBUG
app = Gui(page=index)
if __name__ == '__main__':
app.run(use_reloader= True) #Argument so we dont have rerun app from terminal