-
Notifications
You must be signed in to change notification settings - Fork 23
/
predict.py
executable file
·30 lines (27 loc) · 991 Bytes
/
predict.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
# Arda Mavi
import sys
import numpy as np
from get_dataset import get_img
from scipy.misc import imresize
from database_process import get_data
from keras.models import model_from_json
image_size = 64
channel_size = 1
def predict(model, X): # Return: Y String , Y Possibility
Y = model.predict(X)
Y_index = np.argmax(Y, axis=1)
Y_string = get_data('SELECT char FROM "id_char" WHERE id={0}'.format(Y_index[0]))
return Y_string[0][0], Y[0][Y_index][0]
if __name__ == '__main__':
img_dir = sys.argv[1]
img = 1-np.array(get_img(img_dir)).astype('float32')/255.
img = img.reshape(1, image_size, image_size, channel_size)
# Getting model:
model_file = open('Data/Model/model.json', 'r')
model = model_file.read()
model_file.close()
model = model_from_json(model)
# Getting weights
model.load_weights("Data/Model/weights.h5")
Y_string, Y_possibility = predict(model, img)
print('Class:', Y_string, '\nPossibility:', Y_possibility)