-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpredictWord.py
More file actions
33 lines (25 loc) · 872 Bytes
/
predictWord.py
File metadata and controls
33 lines (25 loc) · 872 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
from Model import Model, DecoderType
from processFunctions import preprocessImageForPrediction
import numpy as np
class Batch:
def __init__(self, gtTexts, imgs):
self.imgs = np.stack(imgs, axis=0)
self.gtTexts = gtTexts
class FilePaths:
fnCharList = 'model/charList.txt'
fnCorpus = 'data/corpus.txt'
def infer(model, image):
img = preprocessImageForPrediction(image, Model.imgSize)
batch = Batch(None, [img])
recognized = model.inferBatch(batch, True)[0]
return recognized
def getModel(decoder_type):
if decoder_type == 'word_beam':
decoderType = DecoderType.WordBeamSearch
else:
decoderType = DecoderType.BestPath
model = Model(open(FilePaths.fnCharList).read(), decoderType,
mustRestore=True)
return model
def predictWord(image, model):
return infer(model, image)