Skip to content

Commit

Permalink
add rec introduction, update pdserving
Browse files Browse the repository at this point in the history
  • Loading branch information
tink2123 committed Apr 28, 2022
1 parent 2b6c887 commit 39ee81b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 18 deletions.
30 changes: 18 additions & 12 deletions deploy/pdserving/README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,21 @@ PaddleOCR提供2种服务部署方式:

# 基于PaddleServing的服务部署

本文档将介绍如何使用[PaddleServing](https://github.com/PaddlePaddle/Serving/blob/develop/README_CN.md)工具部署PP-OCR动态图模型的pipeline在线服务。
本文档将介绍如何使用[PaddleServing](https://github.com/PaddlePaddle/Serving/blob/develop/README_CN.md) 工具部署PP-OCR动态图模型的pipeline在线服务。

相比较于hubserving部署,PaddleServing具备以下优点:
- 支持客户端和服务端之间高并发和高效通信
- 支持 工业级的服务能力 例如模型管理,在线加载,在线A/B测试等
- 支持 多种编程语言 开发客户端,例如C++, Python和Java

PaddleServing 支持多种语言部署,本例中提供了python pipeline 和 C++ 两种部署方式,两者的对比如下:

| 语言 | 速度 | 二次开发 | 是否需要编译 |
|-----|-----|---------|------------|
| C++ | 很快 | 略有难度 | 单模型预测无需编译,多模型串联需要编译 |
| python | 一般 | 容易 | 单模型/多模型 均无需编译|


更多有关PaddleServing服务化部署框架介绍和使用教程参考[文档](https://github.com/PaddlePaddle/Serving/blob/develop/README_CN.md)

AIStudio演示案例可参考 [基于PaddleServing的OCR服务化部署实战](https://aistudio.baidu.com/aistudio/projectdetail/3630726)
Expand All @@ -34,6 +42,13 @@ AIStudio演示案例可参考 [基于PaddleServing的OCR服务化部署实战](h

- 准备PaddleOCR的运行环境[链接](../../doc/doc_ch/installation.md)

```
git clone https://github.com/PaddlePaddle/PaddleOCR
# 进入到工作目录
cd PaddleOCR/deploy/pdserving/
```

- 准备PaddleServing的运行环境,步骤如下

```bash
Expand Down Expand Up @@ -105,13 +120,8 @@ python3 -m paddle_serving_client.convert --dirname ./ch_PP-OCRv2_rec_infer/ \
<a name="部署"></a>
## Paddle Serving pipeline部署

1. 下载PaddleOCR代码,若已下载可跳过此步骤
```
git clone https://github.com/PaddlePaddle/PaddleOCR
1. 确认工作目录下文件结构:

# 进入到工作目录
cd PaddleOCR/deploy/pdserving/
```
pdserver目录包含启动pipeline服务和发送预测请求的代码,包括:
```
__init__.py
Expand Down Expand Up @@ -196,16 +206,12 @@ python3 -m paddle_serving_client.convert --dirname ./ch_PP-OCRv2_rec_infer/ \

C++ 服务部署在环境搭建和数据准备阶段与 python 相同,区别在于启动服务和客户端发送请求时不同。

| 语言 | 速度 | 二次开发 | 是否需要编译 |
|-----|-----|---------|------------|
| C++ | 很快 | 略有难度 | 单模型预测无需编译,多模型串联需要编译 |
| python | 一般 | 容易 | 单模型/多模型 均无需编译|

1. 准备 Serving 环境

为了提高预测性能,C++ 服务同样提供了多模型串联服务。与python pipeline服务不同,多模型串联的过程中需要将模型前后处理代码写在服务端,因此需要在本地重新编译生成serving。

首先需要下载Serving代码库, 把OCR文本检测预处理相关代码替换到Serving库中

```
git clone https://github.com/PaddlePaddle/Serving
Expand Down
33 changes: 27 additions & 6 deletions doc/doc_ch/ppocr_introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,27 @@ PP-OCRv2在PP-OCR的基础上,进一步在5个方面重点优化,检测模
#### PP-OCRv3


PP-OCRv3识别从网络结构、训练策略、数据增强三个方向做了进一步优化:
- 网络结构上:使用[SVTR](todo:add_link)中的 Transformer block 替换LSTM,提升模型精度和预测速度;
- 训练策略上:参考 [GTC](https://arxiv.org/pdf/2002.01276.pdf) 策略,使用注意力机制模块指导CTC训练,定位和识别字符,提升不规则文本的识别精度;设计方向分类前序任务,获取更优预训练模型,加速模型收敛过程,提升精度。
- 数据增强上:使用[RecConAug](todo:add_link)数据增广方法,随机结合图片,提升训练数据的上下文信息丰富度,增强模型鲁棒性。

基于上述策略,PP-OCRv3识别模型相比上一版本,速度加速30%,精度进一步提升4.5%。 具体消融实验:

| id | 策略 | 模型大小 | 精度 | CPU+mkldnn 预测耗时 |
|-----|-----|--------|----|------------|
| 01 | PP-OCRv2 | 8M | 69.3% | 26ms |
| 02 | SVTR_tiny | 19M | 80.1% | - |
| 03 | LCNet_SVTR_G6 | 8.2M | 76% | - |
| 04 | LCNet_SVTR_G1 | - | - | - |
| 05 | PP-OCRv3 | 12M | 71.9% | 19ms |
| 06 | + GTC | 12M | 75.8% | 19ms |
| 07 | + RecConAug | 12M | 76.3% | 19ms |
| 08 | + SSL pretrain | 12M | 76.9% | 19ms |
| 09 | + UDML | 12M | 78.4% | 19ms |
| 10 | + unlabeled data | 12M | 79.4% | 19ms |


<a name="2"></a>
## 2. 特性

Expand Down Expand Up @@ -68,13 +89,13 @@ PP-OCRv2在PP-OCR的基础上,进一步在5个方面重点优化,检测模
<img src="../imgs_results/ch_ppocr_mobile_v2.0/00056221.jpg" width="800">
<img src="../imgs_results/ch_ppocr_mobile_v2.0/rotate_00052204.jpg" width="800">
</div>

</details>


<details open>
<summary>PP-OCRv2 英文模型</summary>

<div align="center">
<img src="../imgs_results/ch_ppocr_mobile_v2.0/img_12.jpg" width="800">
</div>
Expand All @@ -84,15 +105,15 @@ PP-OCRv2在PP-OCR的基础上,进一步在5个方面重点优化,检测模

<details open>
<summary>PP-OCRv2 其他语言模型</summary>

<div align="center">
<img src="../imgs_results/french_0.jpg" width="800">
<img src="../imgs_results/korean.jpg" width="800">
</div>

</details>


<a name="5"></a>
## 5. 使用教程

Expand All @@ -119,4 +140,4 @@ PP-OCR中英文模型列表如下:
| 中英文超轻量PP-OCR mobile模型(9.4M) | ch_ppocr_mobile_v2.0_xx | 移动端&服务器端 | [推理模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_det_infer.tar) / [预训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_det_train.tar) | [推理模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_cls_infer.tar) / [预训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_cls_train.tar) | [推理模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_rec_infer.tar) / [预训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_rec_pre.tar) |
| 中英文通用PP-OCR server模型(143.4M) | ch_ppocr_server_v2.0_xx | 服务器端 | [推理模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_server_v2.0_det_infer.tar) / [预训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_server_v2.0_det_train.tar) | [推理模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_cls_infer.tar) / [预训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_cls_train.tar) | [推理模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_server_v2.0_rec_infer.tar) / [预训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_server_v2.0_rec_pre.tar) |

更多模型下载(包括英文数字模型、多语言模型、Paddle-Lite模型等),可以参考[PP-OCR 系列模型下载](./models_list.md)
更多模型下载(包括英文数字模型、多语言模型、Paddle-Lite模型等),可以参考[PP-OCR 系列模型下载](./models_list.md)

0 comments on commit 39ee81b

Please sign in to comment.