-
Notifications
You must be signed in to change notification settings - Fork 0
/
prediction.py
49 lines (27 loc) · 1.16 KB
/
prediction.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
41
42
43
44
45
46
47
48
49
import tensorflow as tf
import keras
from tensorflow.keras.callbacks import EarlyStopping, ReduceLROnPlateau,ModelCheckpoint
from sklearn.model_selection import train_test_split
# Global
import numpy as np
import matplotlib.pyplot as plt
import cv2 as cv
from preprocessing import *
label_dictionary = {}
for index, label in np.loadtxt("dataset/kaggleemnist/emnist-balanced-mapping.txt", delimiter=" ", dtype=np.int64):
label_dictionary[index] = chr(label)
mymodel = keras.models.load_model('checkpoint2.model.keras')
def predict(number):
text = []
for i in range(number):
img = cv.imread(f"dataset/captchas/{i+1:05}.gif")
c,_ = cluster(filter1((img)))
captcha = []
for j in range(len(c)):
inputimg = cv.copyMakeBorder(cv.resize(c[j], (24,24)) ,2,2,2,2,cv.BORDER_CONSTANT).T / 255.0
prob = mymodel.predict(inputimg.reshape((1,28,28,1)), verbose=0)
captcha.append(label_dictionary[np.argmax(prob)])
text.append((i+1,f"{''.join(captcha)}"))
del img, c, captcha
return text
predict(1000)