-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpredictNum.py
More file actions
39 lines (28 loc) · 808 Bytes
/
Copy pathpredictNum.py
File metadata and controls
39 lines (28 loc) · 808 Bytes
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
#!/usr/bin/env python
# coding: utf-8
import keras
import PIL
import numpy as np
from keras.models import load_model
from keras.preprocessing import image
from PIL import Image
imgName=raw_input("enter name of image : ")
model = load_model('model_keras_mnist.h5')
##testIMG = Image.open('testIMG/'+str(imgName)+'.png').convert('LA')
testIMG = image.load_img(path="testIMG/"+str(imgName)+".png",color_mode="grayscale",target_size=(28,28,1))
print(np.array(testIMG).shape)
testIMG = testIMG.resize([28,28])
#converting to np array for prediction
img = np.array(testIMG)
print(img.shape)
#reshaping to 1D array
img = img.reshape(1,784)
result = model.predict(img)
print(result[0])
result = result[0]
index=0
for i in np.nditer(result):
if(i):
print("Prediction : "+str(index))
break
index += 1