-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproses.py
More file actions
46 lines (37 loc) · 1.65 KB
/
proses.py
File metadata and controls
46 lines (37 loc) · 1.65 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
from PIL import Image
from keras.applications.mobilenet import preprocess_input
import numpy as np
import keras
from keras.models import load_model
def proses(file):
#model_baru=load_model('myNewModel.h5') This is no longer works
#json_file = open('model.json', 'r') # use this block instead, when creating the model use JSON SAVE as below
#loaded_model_json = json_file.read() # and copy model.json and model.h5 to this folder (instead of myNewModel)
#json_file.close()
#model_baru = model_from_json(loaded_model_json)
# load weights into new model
#model_baru.load_weights("myNewModelFlower.h5")
model_baru=load_model("ModelFlower.h5")
jenis = ['Lilly (Lillium longiflorum Thunb)','Lotus (Nelumbo nucifera)','Orchid (Orchidaceae)','Sunflower (Helianthus annuss L.)','Tulip (Tulipa)']
image = Image.open(file.file)
image = image.convert('RGB')
image = image.resize((224,224))
image = np.asarray(image)
image = np.expand_dims(image,0)
#image = image/255
gambar = keras.applications.mobilenet.preprocess_input(image)
p = model_baru.predict(gambar)
kelas = p.argmax(axis = 1)[0]
label = jenis[kelas]
conf = p[0][kelas]
return conf, label
# from tensorflow.keras.models import Sequential, model_from_json
# model_json = modelKu.to_json()
# with open("model.json", "w") as json_file:
# json_file.write(model_json)
# modelKu.save_weights("model.h5")
# json_file = open('model.json', 'r')
# loaded_model_json = json_file.read()
# json_file.close()
# loaded_model = model_from_json(loaded_model_json)
# loaded_model.load_weights("model.h5")