-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDigi_Class.py
40 lines (28 loc) · 867 Bytes
/
Digi_Class.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
import re
import os
from skimage.transform import resize
from PIL import Image
from keras.models import load_model
import base64
import numpy as np
import tensorflow as tf
global model
model = load_model(os.path.join('digi_class.h5'))
graph = tf.get_default_graph()
def convertImage(imgData1):
imgstr = re.search(b'base64,(.*)', imgData1).group(1)
with open('output.png','wb') as output:
output.write(base64.decodebytes(imgstr))
def digit(imgData):
convertImage(imgData)
x= Image.open('output.png').convert('L')
x = np.invert(x)
x = resize(x,(28,28),order=1, mode='constant', cval=0, clip=False, preserve_range=True)
x= x.astype(int)
x = x.reshape(1,28,28,1)
with graph.as_default():
y_pred=model.predict(x)
for i in range(len(y_pred[0])):
if y_pred[0][i]==1:
m=i
return m