-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathpredictor.py
37 lines (28 loc) · 1.16 KB
/
predictor.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
# -*- coding: utf-8 -*-
"""
Created on Mon Apr 8 19:15:12 2019
@author: Quassarian Viper
"""
import numpy as np
from keras.models import model_from_json
from keras.models import load_model
def prediction(img):
# load json and create model
json_file = open('cnn2\cnn2.json', 'r')
loaded_model_json = json_file.read()
json_file.close()
loaded_model = model_from_json(loaded_model_json)
# load weights into new model
loaded_model.load_weights("cnn2\cnn2.h5")
#print("Loaded model from disk")
loaded_model.save('cnn.hdf5')
loaded_model=load_model('cnn.hdf5')
characters = '०,१,२,३,४,५,६,७,८,९,क,ख,ग,घ,ङ,च,छ,ज,झ,ञ,ट,ठ,ड,ढ,ण,त,थ,द,ध,न,प,फ,ब,भ,म,य,र,ल,व,श,ष,स,ह,क्ष,त्र,ज्ञ'
characters = characters.split(',')
x = np.asarray(img, dtype = np.float32).reshape(1, 32, 32, 1) / 255
output = loaded_model.predict(x)
output = output.reshape(46)
predicted = np.argmax(output)
devanagari_label = characters[predicted]
success = output[predicted] * 100
return devanagari_label, success