-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpredict_kao.py
65 lines (37 loc) · 1.23 KB
/
predict_kao.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
#from phlatib import Path
from pathlib import Path
import numpy as np
from PIL import Image
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras.models import load_model
from io import BytesIO
def predict_kao(path):
model_path = "./logdir/model_file_kao.hdf5"
#classes = ["maru","omonaga","sankaku","sikaku","tamago"]
classes = ["丸","面長","逆三角","四角","卵"]
# load model
model = load_model(model_path)
image_size=64
X = []
image=path
image=Image.open(image)
#image = Image.open(pil_img)
image = image.convert("RGB")
image = image.resize((image_size, image_size))
data = np.asarray(image)
X.append(data)
X = np.array(X)
#正規化(0-1)
X = X.astype('float32')
X = X / 255.0
result = model.predict([X])[0]
predicted = result.argmax()
#percentage = int(result[predicted] * 100)
#return "{0}({1} %)".format(classes[predicted],percentage)
#return classes[predicted],str(percentage)
#return classes[predicted]
result2= [int(n*100) for n in result]
return result2[0],result2[1],result2[2],result2[3],result2[4],classes[predicted],max(result2)
#print('ok')
#print(predict('./sample_image/yosida.jpg'))