-
Notifications
You must be signed in to change notification settings - Fork 2
/
predict_PC.py
52 lines (35 loc) · 1.15 KB
/
predict_PC.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
#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_PC(image):
model_path = "./logdir/model_file_PC.hdf5"
classes = ['夏','秋','春','冬']
# load model
model = load_model(model_path)
image_size=64
X = []
image=Image.open(image)
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 classes[predicted],str(percentage)
#return classes[predicted]
#夏冬春秋に並び変える
result2=[result[0],result[3],result[2],result[1]]
result3= [int(n*100) for n in result2]
return result3[0],result3[1],result3[2],result3[3],classes[predicted],max(result3)
#print('ok')
#print(predict('./python/datasetmaker/mendata/うどん/images.jpg'))