Exemplo n.º 1
0
 def getNext(self):
     """ Iterator """
     batchRange = range(self.currIdx, self.currIdx + self.batchSize)
     gtTexts = [self.samples[i].gtText for i in batchRange]
     imgs = [preprocessor(self.samples[i].filePath,
                          self.imgSize, binary=True) for i in batchRange]
     self.currIdx += self.batchSize
     return Batch(gtTexts, imgs)
Exemplo n.º 2
0
def infer(model, fnImg):
    """ Recognize text in image provided by file path """
    img = preprocessor(fnImg, model.imgSize, binary=True)
    # Fill all batch elements with same input image
    batch = Batch(None, [img] * Model.batchSize)
    recognized = model.inferBatch(batch)  # recognize text
    # All batch elements hold same result
    print('Recognized:', '"' + recognized[0] + '"')
Exemplo n.º 3
0
def infer(model, paths):
    """ Recognize text in image provided by file path """
    imgs = [
        preprocessor(paths[i], model.imgSize, binary=True)
        for i in range(len(paths))
    ]
    if len(imgs) >= Model.batchSize:
        imgs = imgs[0:Model.batchSize]
    else:  # len(imgs) <= Model.batchSize
        imgs = imgs + ([imgs[0]] * (Model.batchSize - len(imgs)))
    # Fill all batch elements with same input image
    batch = Batch(["blah"] * Model.batchSize, imgs)
    recognized = model.inferBatch(batch)  # recognize text
    # All batch elements hold same result
    for i in range(min(len(paths), len(recognized))):
        print('Recognized:', paths[i], 'as "' + recognized[i] + '"')