torch.IntTensor([l]), raw=raw)) index += l return texts def label_dict(self): return self.dict def label_constant(self): return self.alphabet if __name__ == '__main__': sys.path.append('../') from model.cnn import CNN img = Image.open('../test/ocr/test.jpg') alphabet = process_alphabet('../weight/ocr/ocr.json') model = CNN(1).cuda() checkpoint = torch.load('../weight/ocr/ocr.pth.tar') model.load_state_dict(checkpoint) res = predict(model, img, alphabet) print(res)
# os.environ["CUDA_VISIBLE_DEVICES"] = "3,2,1" # load image for text image_path = './test/text/1032838434.jpg' img = cv2.imread(image_path) # ndarray # load model textModel = VGG(3).cuda() checkpoint = torch.load(textPath) textModel.load_state_dict(checkpoint) print(textModel) ocrModel = CNN(1).cuda() checkpoint = torch.load(ocrPath) ocrModel.load_state_dict(checkpoint) print(ocrModel) end = time.perf_counter() print('Load Model time is {}'.format(end - start_p)) text = text_ocr(img, textModel, ocrModel) end_p = time.perf_counter() print('OCR processing time is {}'.format(end_p - start_p)) print(text)