From 274f4bceed31196ebf8524e6174c5ffbab0e2435 Mon Sep 17 00:00:00 2001 From: Steffy-zxf <48793257+Steffy-zxf@users.noreply.github.com> Date: Thu, 6 Aug 2020 09:56:49 +0800 Subject: [PATCH] Fix ocr (#806) --- .../text_recognition/chinese_ocr_db_crnn_mobile/module.py | 4 +++- .../text_recognition/chinese_ocr_db_crnn_server/module.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/hub_module/modules/image/text_recognition/chinese_ocr_db_crnn_mobile/module.py b/hub_module/modules/image/text_recognition/chinese_ocr_db_crnn_mobile/module.py index 9d8f2d49..490bba80 100644 --- a/hub_module/modules/image/text_recognition/chinese_ocr_db_crnn_mobile/module.py +++ b/hub_module/modules/image/text_recognition/chinese_ocr_db_crnn_mobile/module.py @@ -25,7 +25,7 @@ from chinese_ocr_db_crnn_mobile.utils import base64_to_cv2, draw_ocr, get_image_ @moduleinfo( name="chinese_ocr_db_crnn_mobile", - version="1.0.2", + version="1.0.3", summary= "The module can recognize the chinese texts in an image. Firstly, it will detect the text box positions based on the differentiable_binarization_chn module. Then it recognizes the chinese texts. ", author="paddle-dev", @@ -308,6 +308,8 @@ class ChineseOCRDBCRNN(hub.Module): ind = np.argmax(probs, axis=1) blank = probs.shape[1] valid_ind = np.where(ind != (blank - 1))[0] + if len(valid_ind) == 0: + continue score = np.mean(probs[valid_ind, ind[valid_ind]]) rec_res.append([preds_text, score]) diff --git a/hub_module/modules/image/text_recognition/chinese_ocr_db_crnn_server/module.py b/hub_module/modules/image/text_recognition/chinese_ocr_db_crnn_server/module.py index d638763b..2c82cdba 100644 --- a/hub_module/modules/image/text_recognition/chinese_ocr_db_crnn_server/module.py +++ b/hub_module/modules/image/text_recognition/chinese_ocr_db_crnn_server/module.py @@ -25,7 +25,7 @@ from chinese_ocr_db_crnn_server.utils import base64_to_cv2, draw_ocr, get_image_ @moduleinfo( name="chinese_ocr_db_crnn_server", - version="1.0.1", + version="1.0.2", summary= "The module can recognize the chinese texts in an image. Firstly, it will detect the text box positions based on the differentiable_binarization_chn module. Then it recognizes the chinese texts. ", author="paddle-dev", @@ -308,6 +308,8 @@ class ChineseOCRDBCRNNServer(hub.Module): ind = np.argmax(probs, axis=1) blank = probs.shape[1] valid_ind = np.where(ind != (blank - 1))[0] + if len(valid_ind) == 0: + continue score = np.mean(probs[valid_ind, ind[valid_ind]]) rec_res.append([preds_text, score]) -- GitLab