提交 8141d6ea 编写于 作者: 走神的阿圆's avatar 走神的阿圆

update ocr server and mobile to 1.1.1 to fix recognize space bug

上级 b58fa8dc
...@@ -152,3 +152,7 @@ pyclipper ...@@ -152,3 +152,7 @@ pyclipper
* 1.1.0 * 1.1.0
使用超轻量级的三阶段模型(文本框检测-角度分类-文字识别)识别图片文字。 使用超轻量级的三阶段模型(文本框检测-角度分类-文字识别)识别图片文字。
* 1.1.1
支持文本中空格识别。
...@@ -17,7 +17,10 @@ import string ...@@ -17,7 +17,10 @@ import string
class CharacterOps(object): 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): def __init__(self, config):
self.character_type = config['character_type'] self.character_type = config['character_type']
...@@ -26,6 +29,7 @@ class CharacterOps(object): ...@@ -26,6 +29,7 @@ class CharacterOps(object):
if self.character_type == "en": if self.character_type == "en":
self.character_str = "0123456789abcdefghijklmnopqrstuvwxyz" self.character_str = "0123456789abcdefghijklmnopqrstuvwxyz"
dict_character = list(self.character_str) dict_character = list(self.character_str)
# use the custom dictionary
elif self.character_type == "ch": elif self.character_type == "ch":
character_dict_path = config['character_dict_path'] character_dict_path = config['character_dict_path']
add_space = False add_space = False
...@@ -50,10 +54,12 @@ class CharacterOps(object): ...@@ -50,10 +54,12 @@ class CharacterOps(object):
"Nonsupport type of the character: {}".format(self.character_str) "Nonsupport type of the character: {}".format(self.character_str)
self.beg_str = "sos" self.beg_str = "sos"
self.end_str = "eos" self.end_str = "eos"
# add start and end str for attention
if self.loss_type == "attention": if self.loss_type == "attention":
dict_character = [self.beg_str, self.end_str] + dict_character dict_character = [self.beg_str, self.end_str] + dict_character
elif self.loss_type == "srn": elif self.loss_type == "srn":
dict_character = dict_character + [self.beg_str, self.end_str] dict_character = dict_character + [self.beg_str, self.end_str]
# create char dict
self.dict = {} self.dict = {}
for i, char in enumerate(dict_character): for i, char in enumerate(dict_character):
self.dict[char] = i self.dict[char] = i
...@@ -122,6 +128,21 @@ class CharacterOps(object): ...@@ -122,6 +128,21 @@ class CharacterOps(object):
def cal_predicts_accuracy(char_ops, preds, preds_lod, labels, labels_lod, is_remove_duplicate=False): 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 acc_num = 0
img_num = 0 img_num = 0
for ino in range(len(labels_lod) - 1): for ino in range(len(labels_lod) - 1):
......
...@@ -21,7 +21,7 @@ from chinese_ocr_db_crnn_mobile.utils import base64_to_cv2, draw_ocr, get_image_ ...@@ -21,7 +21,7 @@ from chinese_ocr_db_crnn_mobile.utils import base64_to_cv2, draw_ocr, get_image_
@moduleinfo( @moduleinfo(
name="chinese_ocr_db_crnn_mobile", 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 \ 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. ", based on the differentiable_binarization_chn module. Then it classifies the text angle and recognizes the chinese texts. ",
author="paddle-dev", author="paddle-dev",
...@@ -100,7 +100,7 @@ class ChineseOCRDBCRNN(hub.Module): ...@@ -100,7 +100,7 @@ class ChineseOCRDBCRNN(hub.Module):
""" """
if not self._text_detector_module: if not self._text_detector_module:
self._text_detector_module = hub.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 return self._text_detector_module
def read_images(self, paths=[]): def read_images(self, paths=[]):
......
...@@ -147,3 +147,7 @@ pyclipper ...@@ -147,3 +147,7 @@ pyclipper
* 1.1.0 * 1.1.0
使用三阶段模型(文本框检测-角度分类-文字识别)识别图片文字。 使用三阶段模型(文本框检测-角度分类-文字识别)识别图片文字。
* 1.1.1
支持文本中空格识别。
...@@ -17,7 +17,10 @@ import string ...@@ -17,7 +17,10 @@ import string
class CharacterOps(object): 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): def __init__(self, config):
self.character_type = config['character_type'] self.character_type = config['character_type']
...@@ -26,6 +29,7 @@ class CharacterOps(object): ...@@ -26,6 +29,7 @@ class CharacterOps(object):
if self.character_type == "en": if self.character_type == "en":
self.character_str = "0123456789abcdefghijklmnopqrstuvwxyz" self.character_str = "0123456789abcdefghijklmnopqrstuvwxyz"
dict_character = list(self.character_str) dict_character = list(self.character_str)
# use the custom dictionary
elif self.character_type == "ch": elif self.character_type == "ch":
character_dict_path = config['character_dict_path'] character_dict_path = config['character_dict_path']
add_space = False add_space = False
...@@ -50,10 +54,12 @@ class CharacterOps(object): ...@@ -50,10 +54,12 @@ class CharacterOps(object):
"Nonsupport type of the character: {}".format(self.character_str) "Nonsupport type of the character: {}".format(self.character_str)
self.beg_str = "sos" self.beg_str = "sos"
self.end_str = "eos" self.end_str = "eos"
# add start and end str for attention
if self.loss_type == "attention": if self.loss_type == "attention":
dict_character = [self.beg_str, self.end_str] + dict_character dict_character = [self.beg_str, self.end_str] + dict_character
elif self.loss_type == "srn": elif self.loss_type == "srn":
dict_character = dict_character + [self.beg_str, self.end_str] dict_character = dict_character + [self.beg_str, self.end_str]
# create char dict
self.dict = {} self.dict = {}
for i, char in enumerate(dict_character): for i, char in enumerate(dict_character):
self.dict[char] = i self.dict[char] = i
...@@ -122,6 +128,21 @@ class CharacterOps(object): ...@@ -122,6 +128,21 @@ class CharacterOps(object):
def cal_predicts_accuracy(char_ops, preds, preds_lod, labels, labels_lod, is_remove_duplicate=False): 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 acc_num = 0
img_num = 0 img_num = 0
for ino in range(len(labels_lod) - 1): for ino in range(len(labels_lod) - 1):
......
...@@ -25,7 +25,7 @@ from chinese_ocr_db_crnn_server.utils import base64_to_cv2, draw_ocr, get_image_ ...@@ -25,7 +25,7 @@ from chinese_ocr_db_crnn_server.utils import base64_to_cv2, draw_ocr, get_image_
@moduleinfo( @moduleinfo(
name="chinese_ocr_db_crnn_server", name="chinese_ocr_db_crnn_server",
version="1.1.0", version="1.1.1",
summary= 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. ", "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", author="paddle-dev",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册