diff --git a/deploy/hubserving/ocr_cls/module.py b/deploy/hubserving/ocr_cls/module.py index 1b91580ca37027e512a73138270d051497af5b89..803d5ac27e74d04177b21b5886675ac0b5f31698 100644 --- a/deploy/hubserving/ocr_cls/module.py +++ b/deploy/hubserving/ocr_cls/module.py @@ -6,6 +6,7 @@ from __future__ import print_function import os import sys sys.path.insert(0, ".") +import copy from paddlehub.common.logger import logger from paddlehub.module.module import moduleinfo, runnable, serving @@ -14,6 +15,7 @@ import paddlehub as hub from tools.infer.utility import base64_to_cv2 from tools.infer.predict_cls import TextClassifier +from tools.infer.utility import parse_args @moduleinfo( @@ -28,8 +30,7 @@ class OCRCls(hub.Module): """ initialize with the necessary elements """ - from ocr_cls.params import read_params - cfg = read_params() + cfg = self.merge_configs() cfg.use_gpu = use_gpu if use_gpu: @@ -48,6 +49,21 @@ class OCRCls(hub.Module): self.text_classifier = TextClassifier(cfg) + def merge_configs(self, ): + # deafult cfg + backup_argv = copy.deepcopy(sys.argv) + sys.argv = sys.argv[:1] + cfg = parse_args() + + from ocr_det.params import read_params + update_cfg_map = vars(read_params()) + + for key in update_cfg_map: + cfg.__setattr__(key, update_cfg_map[key]) + + sys.argv = copy.deepcopy(backup_argv) + return cfg + def read_images(self, paths=[]): images = [] for img_path in paths: diff --git a/deploy/hubserving/ocr_det/module.py b/deploy/hubserving/ocr_det/module.py index 5f7bd6c473884b80fbe4d24088808444633f100d..595f4cea9c74664dd1578735f062dbe4bac74a55 100644 --- a/deploy/hubserving/ocr_det/module.py +++ b/deploy/hubserving/ocr_det/module.py @@ -7,6 +7,8 @@ import os import sys sys.path.insert(0, ".") +import copy + from paddlehub.common.logger import logger from paddlehub.module.module import moduleinfo, runnable, serving import cv2 @@ -15,6 +17,7 @@ import paddlehub as hub from tools.infer.utility import base64_to_cv2 from tools.infer.predict_det import TextDetector +from tools.infer.utility import parse_args @moduleinfo( @@ -29,8 +32,7 @@ class OCRDet(hub.Module): """ initialize with the necessary elements """ - from ocr_det.params import read_params - cfg = read_params() + cfg = self.merge_configs() cfg.use_gpu = use_gpu if use_gpu: @@ -49,6 +51,21 @@ class OCRDet(hub.Module): self.text_detector = TextDetector(cfg) + def merge_configs(self, ): + # deafult cfg + backup_argv = copy.deepcopy(sys.argv) + sys.argv = sys.argv[:1] + cfg = parse_args() + + from ocr_det.params import read_params + update_cfg_map = vars(read_params()) + + for key in update_cfg_map: + cfg.__setattr__(key, update_cfg_map[key]) + + sys.argv = copy.deepcopy(backup_argv) + return cfg + def read_images(self, paths=[]): images = [] for img_path in paths: diff --git a/deploy/hubserving/ocr_det/params.py b/deploy/hubserving/ocr_det/params.py index 7be88e9bc6673fadfce19a281de4ba4d2b235fd2..bc75cc404e43e0a6e9242c2684d615b4575e5d8f 100755 --- a/deploy/hubserving/ocr_det/params.py +++ b/deploy/hubserving/ocr_det/params.py @@ -22,6 +22,7 @@ def read_params(): cfg.det_db_box_thresh = 0.5 cfg.det_db_unclip_ratio = 1.6 cfg.use_dilation = False + cfg.det_db_score_mode = "fast" # #EAST parmas # cfg.det_east_score_thresh = 0.8 diff --git a/deploy/hubserving/ocr_rec/module.py b/deploy/hubserving/ocr_rec/module.py index 41a42104a81b736eeca346737d2dcefe3d728ef8..70998241dcd2ed04ae94dd3eb33d5d18244652d6 100644 --- a/deploy/hubserving/ocr_rec/module.py +++ b/deploy/hubserving/ocr_rec/module.py @@ -6,6 +6,7 @@ from __future__ import print_function import os import sys sys.path.insert(0, ".") +import copy from paddlehub.common.logger import logger from paddlehub.module.module import moduleinfo, runnable, serving @@ -14,6 +15,7 @@ import paddlehub as hub from tools.infer.utility import base64_to_cv2 from tools.infer.predict_rec import TextRecognizer +from tools.infer.utility import parse_args @moduleinfo( @@ -28,8 +30,7 @@ class OCRRec(hub.Module): """ initialize with the necessary elements """ - from ocr_rec.params import read_params - cfg = read_params() + cfg = self.merge_configs() cfg.use_gpu = use_gpu if use_gpu: @@ -48,6 +49,21 @@ class OCRRec(hub.Module): self.text_recognizer = TextRecognizer(cfg) + def merge_configs(self, ): + # deafult cfg + backup_argv = copy.deepcopy(sys.argv) + sys.argv = sys.argv[:1] + cfg = parse_args() + + from ocr_det.params import read_params + update_cfg_map = vars(read_params()) + + for key in update_cfg_map: + cfg.__setattr__(key, update_cfg_map[key]) + + sys.argv = copy.deepcopy(backup_argv) + return cfg + def read_images(self, paths=[]): images = [] for img_path in paths: diff --git a/deploy/hubserving/ocr_system/module.py b/deploy/hubserving/ocr_system/module.py index 7f3617330bc87ac77a150af9e40dc125d3bfd7de..7a65db09cecac6b49804bf260f3e738177dd3cbf 100644 --- a/deploy/hubserving/ocr_system/module.py +++ b/deploy/hubserving/ocr_system/module.py @@ -6,6 +6,7 @@ from __future__ import print_function import os import sys sys.path.insert(0, ".") +import copy import time @@ -17,6 +18,7 @@ import paddlehub as hub from tools.infer.utility import base64_to_cv2 from tools.infer.predict_system import TextSystem +from tools.infer.utility import parse_args @moduleinfo( @@ -31,8 +33,7 @@ class OCRSystem(hub.Module): """ initialize with the necessary elements """ - from ocr_system.params import read_params - cfg = read_params() + cfg = self.merge_configs() cfg.use_gpu = use_gpu if use_gpu: @@ -51,6 +52,21 @@ class OCRSystem(hub.Module): self.text_sys = TextSystem(cfg) + def merge_configs(self, ): + # deafult cfg + backup_argv = copy.deepcopy(sys.argv) + sys.argv = sys.argv[:1] + cfg = parse_args() + + from ocr_det.params import read_params + update_cfg_map = vars(read_params()) + + for key in update_cfg_map: + cfg.__setattr__(key, update_cfg_map[key]) + + sys.argv = copy.deepcopy(backup_argv) + return cfg + def read_images(self, paths=[]): images = [] for img_path in paths: diff --git a/deploy/hubserving/ocr_system/params.py b/deploy/hubserving/ocr_system/params.py index bd56dc2e8fc05309e27227d25975dc784a17c2cf..bee53bfd346e6d4d91738a2e06a0b4dab8e2b0de 100755 --- a/deploy/hubserving/ocr_system/params.py +++ b/deploy/hubserving/ocr_system/params.py @@ -22,6 +22,7 @@ def read_params(): cfg.det_db_box_thresh = 0.5 cfg.det_db_unclip_ratio = 1.6 cfg.use_dilation = False + cfg.det_db_score_mode = "fast" #EAST parmas cfg.det_east_score_thresh = 0.8