From 4cdc823761725c46e6aa682634615552914c2b42 Mon Sep 17 00:00:00 2001 From: LDOUBLEV Date: Tue, 23 Mar 2021 15:04:55 +0800 Subject: [PATCH] add en readme --- deploy/pdserver/README.md | 133 ++++++++++++++++++ deploy/{ => pdserver}/README_CN.md | 0 deploy/{ => pdserver}/__init__.py | 0 deploy/{ => pdserver}/config.yml | 0 .../{ => pdserver}/imgs/cpp_infer_pred_12.png | Bin deploy/{ => pdserver}/imgs/demo.png | Bin deploy/{ => pdserver}/imgs/results.png | Bin deploy/{ => pdserver}/imgs/start_server.png | Bin deploy/{ => pdserver}/ocr_reader.py | 0 deploy/{ => pdserver}/pipeline_http_client.py | 0 deploy/pdserver/pipeline_rpc_client.py | 42 ++++++ deploy/{ => pdserver}/web_service.py | 0 12 files changed, 175 insertions(+) create mode 100644 deploy/pdserver/README.md rename deploy/{ => pdserver}/README_CN.md (100%) rename deploy/{ => pdserver}/__init__.py (100%) rename deploy/{ => pdserver}/config.yml (100%) rename deploy/{ => pdserver}/imgs/cpp_infer_pred_12.png (100%) rename deploy/{ => pdserver}/imgs/demo.png (100%) rename deploy/{ => pdserver}/imgs/results.png (100%) rename deploy/{ => pdserver}/imgs/start_server.png (100%) rename deploy/{ => pdserver}/ocr_reader.py (100%) rename deploy/{ => pdserver}/pipeline_http_client.py (100%) create mode 100644 deploy/pdserver/pipeline_rpc_client.py rename deploy/{ => pdserver}/web_service.py (100%) diff --git a/deploy/pdserver/README.md b/deploy/pdserver/README.md new file mode 100644 index 00000000..80a14fc1 --- /dev/null +++ b/deploy/pdserver/README.md @@ -0,0 +1,133 @@ +# OCR Pipeline WebService + +(English|[简体中文](./README_CN.md)) + +This document will introduce how to use the [PaddleServing](https://github.com/PaddlePaddle/Serving/blob/develop/README_CN.md) to deploy the PPOCR dynamic graph model as a pipeline online service. + +**note**: Paddle Serving service deployment framework introduction and tutorial reference [document](https://aistudio.baidu.com/aistudio/projectdetail/1550674). + + +## Contents +- Environmental preparation +- Model conversion +- Paddle Serving pipeline deployment +- FAQ + +## Environmental preparation + +Need to prepare PaddleOCR operating environment and Paddle Serving operating environment. + +1. Prepare PaddleOCR operating environment reference [link](../../doc/doc_ch/installation.md) + +2. Prepare the operating environment of PaddleServing, the steps are as follows + +Install serving, used to start the service +``` +pip3 install paddle-serving-server==0.5.0 # for CPU +pip3 install paddle-serving-server-gpu==0.5.0 # for GPU +# Other GPU environments need to confirm the environment and then choose to execute the following commands +pip3 install paddle-serving-server-gpu==0.5.0.post9 # GPU with CUDA9.0 +pip3 install paddle-serving-server-gpu==0.5.0.post10 # GPU with CUDA10.0 +pip3 install paddle-serving-server-gpu==0.5.0.post101 # GPU with CUDA10.1 + TensorRT6 +pip3 install paddle-serving-server-gpu==0.5.0.post11 # GPU with CUDA10.1 + TensorRT7 +``` + +2. Install the client to send requests to the service +``` +pip3 install paddle-serving-client==0.5.0 # for CPU + +pip3 install paddle-serving-client-gpu==0.5.0 # for GPU +``` + +3. Install serving-app +``` +pip3 install paddle-serving-app==0.3.0 +``` + +**note:** If you want to install the latest version of PaddleServing, refer to [link](https://github.com/PaddlePaddle/Serving/blob/develop/doc/LATEST_PACKAGES.md). + + +## Model conversion +When using PaddleServing for service deployment, you need to convert the saved inference model into a serving model that is easy to deploy. + +First, download the [inference model] of PPOCR(https://github.com/PaddlePaddle/PaddleOCR#pp-ocr-20-series-model-listupdate-on-dec-15) +``` +# Download and unzip the OCR text detection model +wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_server_v2.0_det_infer.tar && tar xf ch_ppocr_server_v2.0_det_infer.tar +# Download and unzip the OCR text recognition model +wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_server_v2.0_rec_infer.tar && tar xf ch_ppocr_server_v2.0_rec_infer.tar + +# Conversion detection model +python3 -m paddle_serving_client.convert --dirname ./ch_ppocr_server_v2.0_det_infer/ \ + --model_filename inference.pdmodel \ + --params_filename inference.pdiparams \ + --serving_server ./ppocr_det_server_2.0_serving/ \ + --serving_client ./ppocr_det_server_2.0_client/ + +# Conversion recognition model +python3 -m paddle_serving_client.convert --dirname ./ch_ppocr_server_v2.0_rec_infer/ \ + --model_filename inference.pdmodel \ + --params_filename inference.pdiparams \ + --serving_server ./ppocr_rec_server_2.0_serving/ \ + --serving_client ./ppocr_rec_server_2.0_client/ + +``` + +After the detection model is converted, there will be additional folders of `ppocr_det_server_2.0_serving` and `ppocr_det_server_2.0_client` in the current folder, with the following format: +``` +|- ppocr_det_server_2.0_serving/ + |- __model__ + |- __params__ + |- serving_server_conf.prototxt + |- serving_server_conf.stream.prototxt + +|- ppocr_det_server_2.0_client + |- serving_client_conf.prototxt + |- serving_client_conf.stream.prototxt + +``` +The recognition model is the same. + +## Paddle Serving pipeline deployment + +1. Download the PaddleOCR code, if you have already downloaded it, you can skip this step. +``` +git clone https://github.com/PaddlePaddle/PaddleOCR + +# Enter the working directory +cd PaddleOCR/deploy/pdserver/ +``` + +The pdserver directory contains the code to start the pipeline service and send prediction requests, including: +``` +__init__.py +config.yml # Start the service configuration file +ocr_reader.py # OCR model pre-processing and post-processing code implementation +pipeline_http_client.py # Script to send pipeline prediction request +web_service.py # Start the script of the pipeline server +``` + +2. Run the following command to start the service. +``` +# Start the service and save the running log in log.txt +python3 web_service.py &>log.txt & +``` +After the service is successfully started, a log similar to the following will be printed in log.txt +![](./imgs/start_server.png) + + +3. Send service request +``` +python3 pipeline_http_client.py +``` +After successfully running, the predicted result of the model will be printed in the cmd window. An example of the result is: +![](./imgs/results.png) + + +## FAQ +** Q1**: No result return after sending the request +** A1**: Do not set the proxy when starting the service and sending the request. You can close the proxy before starting the service and before sending the request. The command to close the proxy is: +``` +unset https_proxy +unset http_proxy +``` diff --git a/deploy/README_CN.md b/deploy/pdserver/README_CN.md similarity index 100% rename from deploy/README_CN.md rename to deploy/pdserver/README_CN.md diff --git a/deploy/__init__.py b/deploy/pdserver/__init__.py similarity index 100% rename from deploy/__init__.py rename to deploy/pdserver/__init__.py diff --git a/deploy/config.yml b/deploy/pdserver/config.yml similarity index 100% rename from deploy/config.yml rename to deploy/pdserver/config.yml diff --git a/deploy/imgs/cpp_infer_pred_12.png b/deploy/pdserver/imgs/cpp_infer_pred_12.png similarity index 100% rename from deploy/imgs/cpp_infer_pred_12.png rename to deploy/pdserver/imgs/cpp_infer_pred_12.png diff --git a/deploy/imgs/demo.png b/deploy/pdserver/imgs/demo.png similarity index 100% rename from deploy/imgs/demo.png rename to deploy/pdserver/imgs/demo.png diff --git a/deploy/imgs/results.png b/deploy/pdserver/imgs/results.png similarity index 100% rename from deploy/imgs/results.png rename to deploy/pdserver/imgs/results.png diff --git a/deploy/imgs/start_server.png b/deploy/pdserver/imgs/start_server.png similarity index 100% rename from deploy/imgs/start_server.png rename to deploy/pdserver/imgs/start_server.png diff --git a/deploy/ocr_reader.py b/deploy/pdserver/ocr_reader.py similarity index 100% rename from deploy/ocr_reader.py rename to deploy/pdserver/ocr_reader.py diff --git a/deploy/pipeline_http_client.py b/deploy/pdserver/pipeline_http_client.py similarity index 100% rename from deploy/pipeline_http_client.py rename to deploy/pdserver/pipeline_http_client.py diff --git a/deploy/pdserver/pipeline_rpc_client.py b/deploy/pdserver/pipeline_rpc_client.py new file mode 100644 index 00000000..7471f7ed --- /dev/null +++ b/deploy/pdserver/pipeline_rpc_client.py @@ -0,0 +1,42 @@ +# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +try: + from paddle_serving_server_gpu.pipeline import PipelineClient +except ImportError: + from paddle_serving_server.pipeline import PipelineClient +import numpy as np +import requests +import json +import cv2 +import base64 +import os + +client = PipelineClient() +client.connect(['127.0.0.1:18090']) + + +def cv2_to_base64(image): + return base64.b64encode(image).decode('utf8') + + +test_img_dir = "imgs/" +for img_file in os.listdir(test_img_dir): + with open(os.path.join(test_img_dir, img_file), 'rb') as file: + image_data = file.read() + image = cv2_to_base64(image_data) + +for i in range(1): + ret = client.predict(feed_dict={"image": image}, fetch=["res"]) + print(ret) + #print(ret) diff --git a/deploy/web_service.py b/deploy/pdserver/web_service.py similarity index 100% rename from deploy/web_service.py rename to deploy/pdserver/web_service.py -- GitLab