From c01e526fc8964c6cab089a28a5b143be97e8a355 Mon Sep 17 00:00:00 2001 From: tink2123 Date: Thu, 10 Mar 2022 05:31:45 +0000 Subject: [PATCH] fix tipc serving doc --- deploy/pdserving/README.md | 12 +++---- deploy/pdserving/README_CN.md | 14 ++++---- deploy/pdserving/config.yml | 4 +-- deploy/pdserving/web_service_det.py | 53 ++++++++++++++++++++++++++++- deploy/pdserving/web_service_rec.py | 4 ++- test_tipc/docs/test_serving.md | 4 +-- 6 files changed, 72 insertions(+), 19 deletions(-) diff --git a/deploy/pdserving/README.md b/deploy/pdserving/README.md index ecdd23ad..07b01928 100644 --- a/deploy/pdserving/README.md +++ b/deploy/pdserving/README.md @@ -78,27 +78,27 @@ Then, you can use installed paddle_serving_client tool to convert inference mode python3 -m paddle_serving_client.convert --dirname ./ch_PP-OCRv2_det_infer/ \ --model_filename inference.pdmodel \ --params_filename inference.pdiparams \ - --serving_server ./ppocrv2_det_serving/ \ - --serving_client ./ppocrv2_det_client/ + --serving_server ./ppocr_det_mobile_2.0_serving/ \ + --serving_client ./ppocr_det_mobile_2.0_client/ # Recognition model conversion python3 -m paddle_serving_client.convert --dirname ./ch_PP-OCRv2_rec_infer/ \ --model_filename inference.pdmodel \ --params_filename inference.pdiparams \ - --serving_server ./ppocrv2_rec_serving/ \ - --serving_client ./ppocrv2_rec_client/ + --serving_server ./ppocr_rec_mobile_2.0_serving/ \ + --serving_client ./ppocr_rec_mobile_2.0_client/ ``` After the detection model is converted, there will be additional folders of `ppocr_det_mobile_2.0_serving` and `ppocr_det_mobile_2.0_client` in the current folder, with the following format: ``` -|- ppocrv2_det_serving/ +|- ppocr_det_mobile_2.0_serving/ |- __model__ |- __params__ |- serving_server_conf.prototxt |- serving_server_conf.stream.prototxt -|- ppocrv2_det_client +|- ppocr_det_mobile_2.0_client |- serving_client_conf.prototxt |- serving_client_conf.stream.prototxt diff --git a/deploy/pdserving/README_CN.md b/deploy/pdserving/README_CN.md index d50aff48..ee83b73b 100644 --- a/deploy/pdserving/README_CN.md +++ b/deploy/pdserving/README_CN.md @@ -75,26 +75,26 @@ wget https://paddleocr.bj.bcebos.com/PP-OCRv2/chinese/ch_PP-OCRv2_rec_infer.tar python3 -m paddle_serving_client.convert --dirname ./ch_PP-OCRv2_det_infer/ \ --model_filename inference.pdmodel \ --params_filename inference.pdiparams \ - --serving_server ./ppocrv2_det_serving/ \ - --serving_client ./ppocrv2_det_client/ + --serving_server ./ppocr_det_mobile_2.0_serving/ \ + --serving_client ./ppocr_det_mobile_2.0_client/ # 转换识别模型 python3 -m paddle_serving_client.convert --dirname ./ch_PP-OCRv2_rec_infer/ \ --model_filename inference.pdmodel \ --params_filename inference.pdiparams \ - --serving_server ./ppocrv2_rec_serving/ \ - --serving_client ./ppocrv2_rec_client/ + --serving_server ./ppocr_rec_mobile_2.0_serving/ \ + --serving_client ./ppocr_rec_mobile_2.0_client/ ``` -检测模型转换完成后,会在当前文件夹多出`ppocrv2_det_serving` 和`ppocrv2_det_client`的文件夹,具备如下格式: +检测模型转换完成后,会在当前文件夹多出`ppocr_det_mobile_2.0_serving` 和`ppocr_det_mobile_2.0_client`的文件夹,具备如下格式: ``` -|- ppocrv2_det_serving/ +|- ppocr_det_mobile_2.0_serving/ |- __model__ |- __params__ |- serving_server_conf.prototxt |- serving_server_conf.stream.prototxt -|- ppocrv2_det_client +|- ppocr_det_mobile_2.0_client |- serving_client_conf.prototxt |- serving_client_conf.stream.prototxt diff --git a/deploy/pdserving/config.yml b/deploy/pdserving/config.yml index f3b0f7ec..2aae922d 100644 --- a/deploy/pdserving/config.yml +++ b/deploy/pdserving/config.yml @@ -34,7 +34,7 @@ op: client_type: local_predictor #det模型路径 - model_config: ./ppocrv2_det_serving + model_config: ./ppocr_det_mobile_2.0_serving #Fetch结果列表,以client_config中fetch_var的alias_name为准 fetch_list: ["save_infer_model/scale_0.tmp_1"] @@ -60,7 +60,7 @@ op: client_type: local_predictor #rec模型路径 - model_config: ./ppocrv2_rec_serving + model_config: ./ppocr_rec_mobile_2.0_serving #Fetch结果列表,以client_config中fetch_var的alias_name为准 fetch_list: ["save_infer_model/scale_0.tmp_1"] diff --git a/deploy/pdserving/web_service_det.py b/deploy/pdserving/web_service_det.py index ee393884..38814ea8 100644 --- a/deploy/pdserving/web_service_det.py +++ b/deploy/pdserving/web_service_det.py @@ -23,8 +23,58 @@ from paddle_serving_app.reader import Sequential, ResizeByFactor from paddle_serving_app.reader import Div, Normalize, Transpose from paddle_serving_app.reader import DBPostProcess, FilterBoxes, GetRotateCropImage, SortedBoxes +import yaml +from argparse import ArgumentParser,RawDescriptionHelpFormatter + _LOGGER = logging.getLogger() +class ArgsParser(ArgumentParser): + def __init__(self): + super(ArgsParser, self).__init__( + formatter_class=RawDescriptionHelpFormatter) + self.add_argument("-c", "--config", help="configuration file to use") + self.add_argument( + "-o", "--opt", nargs='+', help="set configuration options") + + def parse_args(self, argv=None): + args = super(ArgsParser, self).parse_args(argv) + assert args.config is not None, \ + "Please specify --config=configure_file_path." + args.conf_dict = self._parse_opt(args.opt, args.config) + return args + + def _parse_helper(self, v): + if v.isnumeric(): + if "." in v: + v = float(v) + else: + v = int(v) + elif v == "True" or v == "False": + v = (v == "True") + return v + + def _parse_opt(self, opts, conf_path): + f = open(conf_path) + config = yaml.load(f, Loader=yaml.Loader) + if not opts: + return config + for s in opts: + s = s.strip() + k, v = s.split('=') + v = self._parse_helper(v) + print(k,v, type(v)) + cur = config + parent = cur + for kk in k.split("."): + if kk not in cur: + cur[kk] = {} + parent = cur + cur = cur[kk] + else: + parent = cur + cur = cur[kk] + parent[k.split(".")[-1]] = v + return config class DetOp(Op): def init_op(self): @@ -73,5 +123,6 @@ class OcrService(WebService): uci_service = OcrService(name="ocr") -uci_service.prepare_pipeline_config("config.yml") +FLAGS = ArgsParser().parse_args() +uci_service.prepare_pipeline_config(yml_dict=FLAGS.conf_dict) uci_service.run_service() diff --git a/deploy/pdserving/web_service_rec.py b/deploy/pdserving/web_service_rec.py index f5cd8bf0..842728ed 100644 --- a/deploy/pdserving/web_service_rec.py +++ b/deploy/pdserving/web_service_rec.py @@ -21,6 +21,7 @@ import base64 from ocr_reader import OCRReader, DetResizeForTest from paddle_serving_app.reader import Sequential, ResizeByFactor from paddle_serving_app.reader import Div, Normalize, Transpose +from web_service_det import ArgsParser _LOGGER = logging.getLogger() @@ -82,5 +83,6 @@ class OcrService(WebService): uci_service = OcrService(name="ocr") -uci_service.prepare_pipeline_config("config.yml") +FLAGS = ArgsParser().parse_args() +uci_service.prepare_pipeline_config(yml_dict=FLAGS.conf_dict) uci_service.run_service() diff --git a/test_tipc/docs/test_serving.md b/test_tipc/docs/test_serving.md index 1eded6f5..8600eff3 100644 --- a/test_tipc/docs/test_serving.md +++ b/test_tipc/docs/test_serving.md @@ -20,10 +20,10 @@ PaddleServing预测功能测试的主程序为`test_serving.sh`,可以测试 先运行`prepare.sh`准备数据和模型,然后运行`test_serving.sh`进行测试,最终在```test_tipc/output```目录下生成`serving_infer_*.log`后缀的日志文件。 ```shell -bash test_tipc/prepare.sh ./test_tipc/configs/ppocr_det_mobile/model_linux_gpu_normal_normal_serving_python_linux_gpu_cpu.txt "serving_infer" +bash test_tipc/prepare.sh ./test_tipc/configs/ch_ppocr_mobile_v2.0_det/model_linux_gpu_normal_normal_serving_python_linux_gpu_cpu.txt "serving_infer" # 用法: -bash test_tipc/test_serving.sh ./test_tipc/configs/ppocr_det_mobile/model_linux_gpu_normal_normal_serving_python_linux_gpu_cpu.txt +bash test_tipc/test_serving.sh ./test_tipc/configs/ch_ppocr_mobile_v2.0_det/model_linux_gpu_normal_normal_serving_python_linux_gpu_cpu.txt ``` #### 运行结果 -- GitLab