From 13c0ceaf31aab1a672c9dd8e4907d56291f89257 Mon Sep 17 00:00:00 2001 From: ShenYuhan Date: Fri, 11 Dec 2020 19:24:16 +0800 Subject: [PATCH] update ocr server and mobile to 1.1.1 to fix recognize space bug --- .../chinese_ocr_db_crnn_mobile/README.md | 4 ++++ .../chinese_ocr_db_crnn_mobile/character.py | 23 ++++++++++++++++++- .../chinese_ocr_db_crnn_mobile/module.py | 4 ++-- .../chinese_ocr_db_crnn_server/README.md | 4 ++++ .../chinese_ocr_db_crnn_server/character.py | 23 ++++++++++++++++++- .../chinese_ocr_db_crnn_server/module.py | 2 +- 6 files changed, 55 insertions(+), 5 deletions(-) diff --git a/modules/image/text_recognition/chinese_ocr_db_crnn_mobile/README.md b/modules/image/text_recognition/chinese_ocr_db_crnn_mobile/README.md index 74efcf2a..db284a72 100644 --- a/modules/image/text_recognition/chinese_ocr_db_crnn_mobile/README.md +++ b/modules/image/text_recognition/chinese_ocr_db_crnn_mobile/README.md @@ -152,3 +152,7 @@ pyclipper * 1.1.0 使用超轻量级的三阶段模型(文本框检测-角度分类-文字识别)识别图片文字。 + +* 1.1.1 + + 支持文本中空格识别。 diff --git a/modules/image/text_recognition/chinese_ocr_db_crnn_mobile/character.py b/modules/image/text_recognition/chinese_ocr_db_crnn_mobile/character.py index ad6b01ba..ece6764c 100644 --- a/modules/image/text_recognition/chinese_ocr_db_crnn_mobile/character.py +++ b/modules/image/text_recognition/chinese_ocr_db_crnn_mobile/character.py @@ -17,7 +17,10 @@ import string class CharacterOps(object): - """ Convert between text-label and text-index """ + """ Convert between text-label and text-index + Args: + config: config from yaml file + """ def __init__(self, config): self.character_type = config['character_type'] @@ -26,6 +29,7 @@ class CharacterOps(object): if self.character_type == "en": self.character_str = "0123456789abcdefghijklmnopqrstuvwxyz" dict_character = list(self.character_str) + # use the custom dictionary elif self.character_type == "ch": character_dict_path = config['character_dict_path'] add_space = False @@ -50,10 +54,12 @@ class CharacterOps(object): "Nonsupport type of the character: {}".format(self.character_str) self.beg_str = "sos" self.end_str = "eos" + # add start and end str for attention if self.loss_type == "attention": dict_character = [self.beg_str, self.end_str] + dict_character elif self.loss_type == "srn": dict_character = dict_character + [self.beg_str, self.end_str] + # create char dict self.dict = {} for i, char in enumerate(dict_character): self.dict[char] = i @@ -122,6 +128,21 @@ class CharacterOps(object): def cal_predicts_accuracy(char_ops, preds, preds_lod, labels, labels_lod, is_remove_duplicate=False): + """ + Calculate prediction accuracy + Args: + char_ops: CharacterOps + preds: preds result,text index + preds_lod: lod tensor of preds + labels: label of input image, text index + labels_lod: lod tensor of label + is_remove_duplicate: Whether to remove duplicate characters, + The default is False + Return: + acc: The accuracy of test set + acc_num: The correct number of samples predicted + img_num: The total sample number of the test set + """ acc_num = 0 img_num = 0 for ino in range(len(labels_lod) - 1): diff --git a/modules/image/text_recognition/chinese_ocr_db_crnn_mobile/module.py b/modules/image/text_recognition/chinese_ocr_db_crnn_mobile/module.py index a0704f86..8f71ae28 100644 --- a/modules/image/text_recognition/chinese_ocr_db_crnn_mobile/module.py +++ b/modules/image/text_recognition/chinese_ocr_db_crnn_mobile/module.py @@ -21,7 +21,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.1.0", + version="1.1.1", 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 classifies the text angle and recognizes the chinese texts. ", author="paddle-dev", @@ -100,7 +100,7 @@ class ChineseOCRDBCRNN(hub.Module): """ if not self._text_detector_module: self._text_detector_module = hub.Module( - name='chinese_text_detection_db_mobile', enable_mkldnn=self.enable_mkldnn, version='1.0.3') + name='chinese_text_detection_db_mobile', enable_mkldnn=self.enable_mkldnn, version='1.0.4') return self._text_detector_module def read_images(self, paths=[]): diff --git a/modules/image/text_recognition/chinese_ocr_db_crnn_server/README.md b/modules/image/text_recognition/chinese_ocr_db_crnn_server/README.md index ac20c01c..fc78f1ed 100644 --- a/modules/image/text_recognition/chinese_ocr_db_crnn_server/README.md +++ b/modules/image/text_recognition/chinese_ocr_db_crnn_server/README.md @@ -147,3 +147,7 @@ pyclipper * 1.1.0 使用三阶段模型(文本框检测-角度分类-文字识别)识别图片文字。 + +* 1.1.1 + + 支持文本中空格识别。 diff --git a/modules/image/text_recognition/chinese_ocr_db_crnn_server/character.py b/modules/image/text_recognition/chinese_ocr_db_crnn_server/character.py index ad6b01ba..ece6764c 100644 --- a/modules/image/text_recognition/chinese_ocr_db_crnn_server/character.py +++ b/modules/image/text_recognition/chinese_ocr_db_crnn_server/character.py @@ -17,7 +17,10 @@ import string class CharacterOps(object): - """ Convert between text-label and text-index """ + """ Convert between text-label and text-index + Args: + config: config from yaml file + """ def __init__(self, config): self.character_type = config['character_type'] @@ -26,6 +29,7 @@ class CharacterOps(object): if self.character_type == "en": self.character_str = "0123456789abcdefghijklmnopqrstuvwxyz" dict_character = list(self.character_str) + # use the custom dictionary elif self.character_type == "ch": character_dict_path = config['character_dict_path'] add_space = False @@ -50,10 +54,12 @@ class CharacterOps(object): "Nonsupport type of the character: {}".format(self.character_str) self.beg_str = "sos" self.end_str = "eos" + # add start and end str for attention if self.loss_type == "attention": dict_character = [self.beg_str, self.end_str] + dict_character elif self.loss_type == "srn": dict_character = dict_character + [self.beg_str, self.end_str] + # create char dict self.dict = {} for i, char in enumerate(dict_character): self.dict[char] = i @@ -122,6 +128,21 @@ class CharacterOps(object): def cal_predicts_accuracy(char_ops, preds, preds_lod, labels, labels_lod, is_remove_duplicate=False): + """ + Calculate prediction accuracy + Args: + char_ops: CharacterOps + preds: preds result,text index + preds_lod: lod tensor of preds + labels: label of input image, text index + labels_lod: lod tensor of label + is_remove_duplicate: Whether to remove duplicate characters, + The default is False + Return: + acc: The accuracy of test set + acc_num: The correct number of samples predicted + img_num: The total sample number of the test set + """ acc_num = 0 img_num = 0 for ino in range(len(labels_lod) - 1): diff --git a/modules/image/text_recognition/chinese_ocr_db_crnn_server/module.py b/modules/image/text_recognition/chinese_ocr_db_crnn_server/module.py index 4a9e5a29..0b1b0c2f 100644 --- a/modules/image/text_recognition/chinese_ocr_db_crnn_server/module.py +++ b/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.1.0", + version="1.1.1", 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", -- GitLab