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 74efcf2a6c4307e924909a6e8b1a1687a0094134..db284a72f721142bb95cd904db4659856aea6fb1 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 ad6b01baca5d47a8d7762027262b9f2e0c4b46da..ece6764c4ef8703f235b5723d825a1bee0de40d9 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 a0704f86480a6831c9eaeec5c5ea57ba7251355a..8f71ae2818f06a05b433788c46c12c234da99359 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 ac20c01ce05ce0ac4a7f3c12f3a9e95b189d94a7..fc78f1ed97b5da7142f4fe66fe82501348ec9100 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 ad6b01baca5d47a8d7762027262b9f2e0c4b46da..ece6764c4ef8703f235b5723d825a1bee0de40d9 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 4a9e5a299189c614981e7431b8f1e47d6de49a55..0b1b0c2f4f022dc5710f3eae364c6c6adc54fa15 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",