未验证 提交 d1b2da28 编写于 作者: littletomatodonkey's avatar littletomatodonkey 提交者: GitHub

fix ocr det (#2035)

* fix ocr det

* fix default thres value

* fix readme
上级 14ad2546
...@@ -58,7 +58,7 @@ ...@@ -58,7 +58,7 @@
``` ```
- 通过命令行方式实现文字识别模型的调用,更多请见 [PaddleHub命令行指令](../../../../docs/docs_ch/tutorial/cmd_usage.rst) - 通过命令行方式实现文字识别模型的调用,更多请见 [PaddleHub命令行指令](../../../../docs/docs_ch/tutorial/cmd_usage.rst)
- ### 2、代码示例 - ### 2、预测代码示例
- ```python - ```python
import paddlehub as hub import paddlehub as hub
......
...@@ -168,8 +168,9 @@ class ChPPOCRv3Det(hub.Module): ...@@ -168,8 +168,9 @@ class ChPPOCRv3Det(hub.Module):
use_gpu=False, use_gpu=False,
output_dir='detection_result', output_dir='detection_result',
visualization=False, visualization=False,
box_thresh=0.5, box_thresh=0.6,
det_db_unclip_ratio=1.5): det_db_unclip_ratio=1.5,
det_db_score_mode="fast"):
""" """
Get the text box in the predicted images. Get the text box in the predicted images.
Args: Args:
...@@ -180,6 +181,7 @@ class ChPPOCRv3Det(hub.Module): ...@@ -180,6 +181,7 @@ class ChPPOCRv3Det(hub.Module):
visualization (bool): Whether to save image or not. visualization (bool): Whether to save image or not.
box_thresh(float): the threshold of the detected text box's confidence 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_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: Returns:
res (list): The result of text detection box and save path of images. res (list): The result of text detection box and save path of images.
""" """
...@@ -206,12 +208,14 @@ class ChPPOCRv3Det(hub.Module): ...@@ -206,12 +208,14 @@ class ChPPOCRv3Det(hub.Module):
assert predicted_data != [], "There is not any image to be predicted. Please check the input data." assert predicted_data != [], "There is not any image to be predicted. Please check the input data."
preprocessor = DBProcessTest(params={'max_side_len': 960}) preprocessor = DBProcessTest(params={'max_side_len': 960})
postprocessor = DBPostProcess(params={ postprocessor = DBPostProcess(
'thresh': 0.3, params={
'box_thresh': 0.6, 'thresh': 0.3,
'max_candidates': 1000, 'box_thresh': 0.6,
'unclip_ratio': det_db_unclip_ratio 'max_candidates': 1000,
}) 'unclip_ratio': det_db_unclip_ratio,
'det_db_score_mode': det_db_score_mode,
})
all_imgs = [] all_imgs = []
all_ratios = [] all_ratios = []
...@@ -288,6 +292,7 @@ class ChPPOCRv3Det(hub.Module): ...@@ -288,6 +292,7 @@ class ChPPOCRv3Det(hub.Module):
use_gpu=args.use_gpu, use_gpu=args.use_gpu,
output_dir=args.output_dir, output_dir=args.output_dir,
det_db_unclip_ratio=args.det_db_unclip_ratio, det_db_unclip_ratio=args.det_db_unclip_ratio,
det_db_score_mode=args.det_db_score_mode,
visualization=args.visualization) visualization=args.visualization)
return results return results
...@@ -311,6 +316,11 @@ class ChPPOCRv3Det(hub.Module): ...@@ -311,6 +316,11 @@ class ChPPOCRv3Det(hub.Module):
type=float, type=float,
default=1.5, default=1.5,
help="unclip ratio for post processing in DB detection.") 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): def add_module_input_arg(self):
""" """
......
...@@ -124,9 +124,9 @@ class DBPostProcess(object): ...@@ -124,9 +124,9 @@ class DBPostProcess(object):
self.box_thresh = params['box_thresh'] self.box_thresh = params['box_thresh']
self.max_candidates = params['max_candidates'] self.max_candidates = params['max_candidates']
self.unclip_ratio = params['unclip_ratio'] self.unclip_ratio = params['unclip_ratio']
self.score_mode = params['det_db_score_mode']
self.min_size = 3 self.min_size = 3
self.dilation_kernel = None self.dilation_kernel = None
self.score_mode = 'fast'
def boxes_from_bitmap(self, pred, _bitmap, dest_width, dest_height): def boxes_from_bitmap(self, pred, _bitmap, dest_width, dest_height):
''' '''
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册