-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadDigit.py
34 lines (30 loc) · 967 Bytes
/
readDigit.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
from keras.models import Sequential
from keras.layers import Dense
from keras.layers import Dropout
from keras.layers import Flatten
from keras.layers.convolutional import Conv2D
from keras.layers.convolutional import MaxPooling2D
from keras import backend as K
K.set_image_dim_ordering('th')
from keras import optimizers
from keras import metrics
from keras.datasets import mnist
from keras.utils import np_utils
import numpy as np
from matplotlib import pyplot
from keras.models import load_model
from keras.models import save_model
np.random.seed(7)
def baseNet():
model=Sequential()
model.load_weights('weights.h5')
model.compile(loss='categorical_crossentropy',optimizer='adam',metrics=['accuracy'])
return model
def readSudoku(sud):
net=baseNet()
result=np.empty(81)
tarr=sud.reshape(81,1,28,28)
predictions=net.predict_on_batch(tarr)
for i in range(81):
result[i]=np.argmax(predictions[i])
return result