From d1b2da280c3443bea32539812d997f87a4072cdf Mon Sep 17 00:00:00 2001 From: littletomatodonkey Date: Thu, 22 Sep 2022 14:30:36 +0800 Subject: [PATCH] fix ocr det (#2035) * fix ocr det * fix default thres value * fix readme --- .../ch_pp-ocrv3_det/README.md | 2 +- .../ch_pp-ocrv3_det/module.py | 26 +++++++++++++------ .../ch_pp-ocrv3_det/processor.py | 2 +- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/modules/image/text_recognition/ch_pp-ocrv3_det/README.md b/modules/image/text_recognition/ch_pp-ocrv3_det/README.md index d1bf63bf..495d5358 100755 --- a/modules/image/text_recognition/ch_pp-ocrv3_det/README.md +++ b/modules/image/text_recognition/ch_pp-ocrv3_det/README.md @@ -58,7 +58,7 @@ ``` - 通过命令行方式实现文字识别模型的调用,更多请见 [PaddleHub命令行指令](../../../../docs/docs_ch/tutorial/cmd_usage.rst) -- ### 2、代码示例 +- ### 2、预测代码示例 - ```python import paddlehub as hub diff --git a/modules/image/text_recognition/ch_pp-ocrv3_det/module.py b/modules/image/text_recognition/ch_pp-ocrv3_det/module.py index 52d50a60..331f2daf 100644 --- a/modules/image/text_recognition/ch_pp-ocrv3_det/module.py +++ b/modules/image/text_recognition/ch_pp-ocrv3_det/module.py @@ -168,8 +168,9 @@ class ChPPOCRv3Det(hub.Module): use_gpu=False, output_dir='detection_result', visualization=False, - box_thresh=0.5, - det_db_unclip_ratio=1.5): + box_thresh=0.6, + det_db_unclip_ratio=1.5, + det_db_score_mode="fast"): """ Get the text box in the predicted images. Args: @@ -180,6 +181,7 @@ class ChPPOCRv3Det(hub.Module): visualization (bool): Whether to save image or not. box_thresh(float): the threshold of the detected text box's confidence det_db_unclip_ratio(float): unclip ratio for post processing in DB detection. + det_db_score_mode(str): method to calc the final det score, one of fast(using box) and slow(using poly). Returns: res (list): The result of text detection box and save path of images. """ @@ -206,12 +208,14 @@ class ChPPOCRv3Det(hub.Module): assert predicted_data != [], "There is not any image to be predicted. Please check the input data." preprocessor = DBProcessTest(params={'max_side_len': 960}) - postprocessor = DBPostProcess(params={ - 'thresh': 0.3, - 'box_thresh': 0.6, - 'max_candidates': 1000, - 'unclip_ratio': det_db_unclip_ratio - }) + postprocessor = DBPostProcess( + params={ + 'thresh': 0.3, + 'box_thresh': 0.6, + 'max_candidates': 1000, + 'unclip_ratio': det_db_unclip_ratio, + 'det_db_score_mode': det_db_score_mode, + }) all_imgs = [] all_ratios = [] @@ -288,6 +292,7 @@ class ChPPOCRv3Det(hub.Module): use_gpu=args.use_gpu, output_dir=args.output_dir, det_db_unclip_ratio=args.det_db_unclip_ratio, + det_db_score_mode=args.det_db_score_mode, visualization=args.visualization) return results @@ -311,6 +316,11 @@ class ChPPOCRv3Det(hub.Module): type=float, default=1.5, help="unclip ratio for post processing in DB detection.") + self.arg_config_group.add_argument( + '--det_db_score_mode', + type=str, + default="str", + help="method to calc the final det score, one of fast(using box) and slow(using poly).") def add_module_input_arg(self): """ diff --git a/modules/image/text_recognition/ch_pp-ocrv3_det/processor.py b/modules/image/text_recognition/ch_pp-ocrv3_det/processor.py index 46a3b263..7854e7f0 100644 --- a/modules/image/text_recognition/ch_pp-ocrv3_det/processor.py +++ b/modules/image/text_recognition/ch_pp-ocrv3_det/processor.py @@ -124,9 +124,9 @@ class DBPostProcess(object): self.box_thresh = params['box_thresh'] self.max_candidates = params['max_candidates'] self.unclip_ratio = params['unclip_ratio'] + self.score_mode = params['det_db_score_mode'] self.min_size = 3 self.dilation_kernel = None - self.score_mode = 'fast' def boxes_from_bitmap(self, pred, _bitmap, dest_width, dest_height): ''' -- GitLab