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.
PaddleOCR provides two service deployment methods:
- Based on **PaddleHub Serving**: Code path is "`./deploy/hubserving`". Please refer to the [tutorial](../../deploy/hubserving/readme_en.md)
- Based on **PaddleServing**: Code path is "`./deploy/pdserving`". Please follow this tutorial.
Compared with hubserving deployment, PaddleServing supports high concurrency and efficient communication between the client and the server.
# Service deployment based on PaddleServing
The introduction and tutorial of Paddle Serving service deployment framework reference [document](https://aistudio.baidu.com/aistudio/projectdetail/1550674).
This document will introduce how to use the [PaddleServing](https://github.com/PaddlePaddle/Serving/blob/develop/README.md) to deploy the PPOCR dynamic graph model as a pipeline online service.
## Contents
Some Key Features of Paddle Serving:
- Environmental preparation
- Integrate with Paddle training pipeline seamlessly, most paddle models can be deployed with one line command.
- Model conversion
- Industrial serving features supported, such as models management, online loading, online A/B testing etc.
- Paddle Serving pipeline deployment
- Highly concurrent and efficient communication between clients and servers supported.
- FAQ
## Environmental preparation
Need to prepare PaddleOCR operating environment and Paddle Serving operating environment.
The introduction and tutorial of Paddle Serving service deployment framework reference [document](https://github.com/PaddlePaddle/Serving/blob/develop/README.md).
2. Prepare the operating environment of PaddleServing, the steps are as follows
**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).
**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).
<aname="model-conversion"></a>
## Model conversion
## 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.
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)
Firstly, download the [inference model](https://github.com/PaddlePaddle/PaddleOCR#pp-ocr-20-series-model-listupdate-on-dec-15) of PPOCR
```
```
# Download and unzip the OCR text detection model
# 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
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
# 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
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
```
Then, you can use installed paddle_serving_client tool to convert inference model to server model.
The pdserver directory contains the code to start the pipeline service and send prediction requests, including:
The pdserver directory contains the code to start the pipeline service and send prediction requests, including:
```
```
__init__.py
__init__.py
config.yml # Start the service configuration file
config.yml # Start the service configuration file
ocr_reader.py # OCR model pre-processing and post-processing code implementation
ocr_reader.py # OCR model pre-processing and post-processing code implementation
pipeline_http_client.py # Script to send pipeline prediction request
pipeline_http_client.py # Script to send pipeline prediction request
web_service.py # Start the script of the pipeline server
web_service.py # Start the script of the pipeline server
```
```
2. Run the following command to start the service.
2. Run the following command to start the service.
```
```
# Start the service and save the running log in log.txt
# Start the service and save the running log in log.txt
python3 web_service.py &>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
After the service is successfully started, a log similar to the following will be printed in log.txt
![](./imgs/start_server.png)
![](./imgs/start_server.png)
3. Send service request
3. Send service request
```
```
python3 pipeline_http_client.py
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:
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)
![](./imgs/results.png)
<aname="faq"></a>
## FAQ
## FAQ
** Q1**: No result return after sending the request
** 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:
** 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: