mirror of
https://github.com/PaddlePaddle/PaddleOCR.git
synced 2025-12-28 07:28:55 +00:00
commit
aac8c69386
BIN
tests/docs/compare_right.png
Normal file
BIN
tests/docs/compare_right.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 33 KiB |
BIN
tests/docs/compare_wrong.png
Normal file
BIN
tests/docs/compare_wrong.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 64 KiB |
BIN
tests/docs/guide.png
Normal file
BIN
tests/docs/guide.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 138 KiB |
BIN
tests/docs/test.png
Normal file
BIN
tests/docs/test.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 72 KiB |
56
tests/docs/test_cpp.md
Normal file
56
tests/docs/test_cpp.md
Normal file
@ -0,0 +1,56 @@
|
||||
# C++预测功能测试
|
||||
|
||||
C++预测功能测试的主程序为`test_cpp.sh`,可以测试基于C++预测库的模型推理功能。
|
||||
|
||||
## 测试结论汇总
|
||||
|
||||
| 算法名称 | 模型名称 |device | batchsize | mkldnn | cpu多线程 | tensorrt | 离线量化 |
|
||||
| ---- | ---- | ---- | ---- | ---- | ---- | ----| --- |
|
||||
| DB |ch_ppocr_mobile_v2.0_det| CPU/GPU | 1/6 | 支持 | 支持 | fp32/fp16/int8 | 支持 |
|
||||
| DB |ch_ppocr_server_v2.0_det| CPU/GPU | 1/6 | 支持 | 支持 | fp32/fp16/int8 | 支持 |
|
||||
| CRNN |ch_ppocr_mobile_v2.0_rec| CPU/GPU | 1/6 | 支持 | 支持 | fp32/fp16/int8 | 支持 |
|
||||
| CRNN |ch_ppocr_server_v2.0_rec| CPU/GPU | 1/6 | 支持 | 支持 | fp32/fp16/int8 | 支持 |
|
||||
|PP-OCR|ch_ppocr_server_v2.0 | CPU/GPU | 1/6 | 支持 | 支持 | fp32/fp16/int8 | 支持 |
|
||||
|PP-OCR|ch_ppocr_server_v2.0 | CPU/GPU | 1/6 | 支持 | 支持 | fp32/fp16/int8 | 支持 |
|
||||
|
||||
|
||||
|
||||
## 1. 功能测试
|
||||
先运行`prepare.sh`准备数据和模型,然后运行`test_cpp.sh`进行测试,最终在```tests/output```目录下生成`cpp_infer_*.log`后缀的日志文件。
|
||||
|
||||
```shell
|
||||
bash tests/prepare.sh ./tests/configs/ppocr_det_mobile_params.txt
|
||||
|
||||
# 用法1:
|
||||
bash tests/test_cpp.sh ./tests/configs/ppocr_det_mobile_params.txt
|
||||
# 用法2: 指定GPU卡预测,第三个传入参数为GPU卡号
|
||||
bash tests/test_cpp.sh ./tests/configs/ppocr_det_mobile_params.txt '1'
|
||||
```
|
||||
|
||||
|
||||
## 2. 精度测试
|
||||
|
||||
使用compare_results.py脚本比较模型预测的结果是否符合预期,主要步骤包括:
|
||||
- 提取日志中的预测坐标;
|
||||
- 从本地文件中提取保存好的坐标结果;
|
||||
- 比较上述两个结果是否符合精度预期,误差大于设置阈值时会报错。
|
||||
|
||||
### 使用方式
|
||||
运行命令:
|
||||
```shell
|
||||
python3.7 tests/compare_results.py --gt_file=./tests/results/*.txt --log_file=./tests/output/infer_*.log --atol=1e-3 --rtol=1e-3
|
||||
```
|
||||
|
||||
参数介绍:
|
||||
- gt_file: 指向事先保存好的预测结果路径,支持*.txt 结尾,会自动索引*.txt格式的文件,文件默认保存在tests/result/ 文件夹下
|
||||
- log_file: 指向运行tests/test.sh 脚本的infer模式保存的预测日志,预测日志中打印的有预测结果,比如:文本框,预测文本,类别等等,同样支持infer_*.log格式传入
|
||||
- atol: 设置的绝对误差
|
||||
- rtol: 设置的相对误差
|
||||
|
||||
### 运行结果
|
||||
|
||||
正常运行效果如下图:
|
||||
<img src="compare_right.png" width="1000">
|
||||
|
||||
出现不一致结果时的运行输出:
|
||||
<img src="compare_wrong.png" width="1000">
|
||||
107
tests/docs/test_python.md
Normal file
107
tests/docs/test_python.md
Normal file
@ -0,0 +1,107 @@
|
||||
# Python功能测试
|
||||
|
||||
Python功能测试的主程序为`test_python.sh`,可以测试基于Python的模型训练、评估、推理等基本功能,包括裁剪、量化、蒸馏。
|
||||
|
||||
## 测试结论汇总
|
||||
|
||||
- 训练相关:
|
||||
|
||||
| 算法名称 | 模型名称 | 单机单卡 | 单机多卡 | 多机多卡 | 模型压缩(单机多卡) |
|
||||
| :---- | :---- | :---- | :---- | :---- | :---- |
|
||||
| DB | ch_ppocr_mobile_v2.0_det| 正常训练 <br> 混合精度 | 正常训练 <br> 混合精度 | 正常训练 <br> 混合精度 | 正常训练:FPGM裁剪、PACT量化 |
|
||||
| DB | ch_ppocr_server_v2.0_det| 正常训练 <br> 混合精度 | 正常训练 <br> 混合精度 | 正常训练 <br> 混合精度 | 正常训练:FPGM裁剪、PACT量化 |
|
||||
| CRNN | ch_ppocr_mobile_v2.0_rec| 正常训练 <br> 混合精度 | 正常训练 <br> 混合精度 | 正常训练 <br> 混合精度 | 正常训练:FPGM裁剪、PACT量化 |
|
||||
| CRNN | ch_ppocr_server_v2.0_rec| 正常训练 <br> 混合精度 | 正常训练 <br> 混合精度 | 正常训练 <br> 混合精度 | 正常训练:FPGM裁剪、PACT量化 |
|
||||
|PP-OCR| ch_ppocr_mobile_v2.0| 正常训练 <br> 混合精度 | 正常训练 <br> 混合精度 | 正常训练 <br> 混合精度 | 正常训练:FPGM裁剪、PACT量化 |
|
||||
|PP-OCR| ch_ppocr_server_v2.0| 正常训练 <br> 混合精度 | 正常训练 <br> 混合精度 | 正常训练 <br> 混合精度 | 正常训练:FPGM裁剪、PACT量化 |
|
||||
|
||||
|
||||
- 预测相关:
|
||||
|
||||
| 算法名称 | 模型名称 |device | batchsize | mkldnn | cpu多线程 | tensorrt | 离线量化 |
|
||||
| ---- | ---- | ---- | ---- | ---- | ---- | ----| --- |
|
||||
| DB |ch_ppocr_mobile_v2.0_det| CPU/GPU | 1/6 | 支持 | 支持 | fp32/fp16/int8 | 支持 |
|
||||
| DB |ch_ppocr_server_v2.0_det| CPU/GPU | 1/6 | 支持 | 支持 | fp32/fp16/int8 | 支持 |
|
||||
| CRNN |ch_ppocr_mobile_v2.0_rec| CPU/GPU | 1/6 | 支持 | 支持 | fp32/fp16/int8 | 支持 |
|
||||
| CRNN |ch_ppocr_server_v2.0_rec| CPU/GPU | 1/6 | 支持 | 支持 | fp32/fp16/int8 | 支持 |
|
||||
|PP-OCR|ch_ppocr_server_v2.0 | CPU/GPU | 1/6 | 支持 | 支持 | fp32/fp16/int8 | 支持 |
|
||||
|PP-OCR|ch_ppocr_server_v2.0 | CPU/GPU | 1/6 | 支持 | 支持 | fp32/fp16/int8 | 支持 |
|
||||
|
||||
|
||||
|
||||
## 1. 安装依赖
|
||||
- 安装PaddlePaddle >= 2.0
|
||||
- 安装PaddleOCR依赖
|
||||
```
|
||||
pip3 install -r ../requirements.txt
|
||||
```
|
||||
- 安装autolog(规范化日志输出工具)
|
||||
```
|
||||
git clone https://github.com/LDOUBLEV/AutoLog
|
||||
cd AutoLog
|
||||
pip3 install -r requirements.txt
|
||||
python3 setup.py bdist_wheel
|
||||
pip3 install ./dist/auto_log-1.0.0-py3-none-any.whl
|
||||
cd ../
|
||||
```
|
||||
|
||||
|
||||
## 2. 功能测试
|
||||
先运行`prepare.sh`准备数据和模型,然后运行`test_python.sh`进行测试,最终在```tests/output```目录下生成`infer_*.log`格式的日志文件。
|
||||
|
||||
test_python.sh包含四种运行模式,每种模式的运行数据不同,分别用于测试速度和精度,分别是:
|
||||
|
||||
- 模式1:lite_train_infer,使用少量数据训练,用于快速验证训练到预测的走通流程,不验证精度和速度;
|
||||
```shell
|
||||
bash tests/prepare.sh ./tests/configs/ppocr_det_mobile_params.txt 'lite_train_infer'
|
||||
bash tests/test_python.sh ./tests/configs/ppocr_det_mobile_params.txt 'lite_train_infer'
|
||||
```
|
||||
|
||||
- 模式2:whole_infer,使用少量数据训练,一定量数据预测,用于验证训练后的模型执行预测,预测速度是否合理;
|
||||
```shell
|
||||
bash tests/prepare.sh ./tests/configs/ppocr_det_mobile_params.txt 'whole_infer'
|
||||
bash tests/test_python.sh ./tests/configs/ppocr_det_mobile_params.txt 'whole_infer'
|
||||
```
|
||||
|
||||
- 模式3:infer 不训练,全量数据预测,走通开源模型评估、动转静,检查inference model预测时间和精度;
|
||||
```shell
|
||||
bash tests/prepare.sh ./tests/configs/ppocr_det_mobile_params.txt 'infer'
|
||||
# 用法1:
|
||||
bash tests/test_python.sh ./tests/configs/ppocr_det_mobile_params.txt 'infer'
|
||||
# 用法2: 指定GPU卡预测,第三个传入参数为GPU卡号
|
||||
bash tests/test_python.sh ./tests/configs/ppocr_det_mobile_params.txt 'infer' '1'
|
||||
```
|
||||
|
||||
- 模式4:whole_train_infer , CE: 全量数据训练,全量数据预测,验证模型训练精度,预测精度,预测速度;
|
||||
```shell
|
||||
bash tests/prepare.sh ./tests/configs/ppocr_det_mobile_params.txt 'whole_train_infer'
|
||||
bash tests/test.sh ./tests/configs/ppocr_det_mobile_params.txt 'whole_train_infer'
|
||||
```
|
||||
|
||||
|
||||
## 3. 精度测试
|
||||
|
||||
使用compare_results.py脚本比较模型预测的结果是否符合预期,主要步骤包括:
|
||||
- 提取日志中的预测坐标;
|
||||
- 从本地文件中提取保存好的坐标结果;
|
||||
- 比较上述两个结果是否符合精度预期,误差大于设置阈值时会报错。
|
||||
|
||||
### 使用方式
|
||||
运行命令:
|
||||
```shell
|
||||
python3.7 tests/compare_results.py --gt_file=./tests/results/*.txt --log_file=./tests/output/infer_*.log --atol=1e-3 --rtol=1e-3
|
||||
```
|
||||
|
||||
参数介绍:
|
||||
- gt_file: 指向事先保存好的预测结果路径,支持*.txt 结尾,会自动索引*.txt格式的文件,文件默认保存在tests/result/ 文件夹下
|
||||
- log_file: 指向运行tests/test.sh 脚本的infer模式保存的预测日志,预测日志中打印的有预测结果,比如:文本框,预测文本,类别等等,同样支持infer_*.log格式传入
|
||||
- atol: 设置的绝对误差
|
||||
- rtol: 设置的相对误差
|
||||
|
||||
### 运行结果
|
||||
|
||||
正常运行效果如下图:
|
||||
<img src="compare_right.png" width="1000">
|
||||
|
||||
出现不一致结果时的运行输出:
|
||||
<img src="compare_wrong.png" width="1000">
|
||||
143
tests/readme.md
143
tests/readme.md
@ -1,72 +1,93 @@
|
||||
|
||||
# 从训练到推理部署工具链测试方法介绍
|
||||
# 推理部署导航
|
||||
|
||||
test.sh和params.txt文件配合使用,完成OCR轻量检测和识别模型从训练到预测的流程测试。
|
||||
飞桨除了基本的模型训练和预测,还提供了支持多端多平台的高性能推理部署工具。本文档提供了PaddleOCR中所有模型的推理部署导航,方便用户查阅每种模型的推理部署打通情况,并可以进行一键测试。
|
||||
|
||||
# 安装依赖
|
||||
- 安装PaddlePaddle >= 2.0
|
||||
- 安装PaddleOCR依赖
|
||||
```
|
||||
pip3 install -r ../requirements.txt
|
||||
```
|
||||
- 安装autolog
|
||||
```
|
||||
git clone https://github.com/LDOUBLEV/AutoLog
|
||||
cd AutoLog
|
||||
pip3 install -r requirements.txt
|
||||
python3 setup.py bdist_wheel
|
||||
pip3 install ./dist/auto_log-1.0.0-py3-none-any.whl
|
||||
cd ../
|
||||
```
|
||||
<div align="center">
|
||||
<img src="docs/guide.png" width="1000">
|
||||
</div>
|
||||
|
||||
# 目录介绍
|
||||
打通情况汇总如下,已填写的部分表示可以使用本工具进行一键测试,未填写的表示正在支持中。
|
||||
|
||||
```bash
|
||||
| 算法论文 | 模型名称 | 模型类型 | python训练预测 | 其他 |
|
||||
| :--- | :--- | :---- | :-------- | :---- |
|
||||
| DB |ch_ppocr_mobile_v2.0_det | 检测 | 支持 | Paddle Inference: C++预测 <br> Paddle Serving: Python, C++ <br> Paddle-Lite: Python, C++ / ARM CPU |
|
||||
| DB |ch_ppocr_server_v2.0_det | 检测 | 支持 | Paddle Inference: C++预测 <br> Paddle Serving: Python, C++ <br> Paddle-Lite: Python, C++ / ARM CPU |
|
||||
| DB |ch_PP-OCRv2_det | 检测 |
|
||||
| CRNN |ch_ppocr_mobile_v2.0_rec | 识别 | 支持 | Paddle Inference: C++预测 <br> Paddle Serving: Python, C++ <br> Paddle-Lite: Python, C++ / ARM CPU |
|
||||
| CRNN |ch_ppocr_server_v2.0_rec | 识别 | 支持 | Paddle Inference: C++预测 <br> Paddle Serving: Python, C++ <br> Paddle-Lite: Python, C++ / ARM CPU |
|
||||
| CRNN |ch_PP-OCRv2_rec | 识别 |
|
||||
| DB |det_mv3_db_v2.0 | 检测 |
|
||||
| DB |det_r50_vd_db_v2.0 | 检测 |
|
||||
| EAST |det_mv3_east_v2.0 | 检测 |
|
||||
| EAST |det_r50_vd_east_v2.0 | 检测 |
|
||||
| PSENet |det_mv3_pse_v2.0 | 检测 |
|
||||
| PSENet |det_r50_vd_pse_v2.0 | 检测 |
|
||||
| SAST |det_r50_vd_sast_totaltext_v2.0 | 检测 |
|
||||
| Rosetta|rec_mv3_none_none_ctc_v2.0 | 识别 |
|
||||
| Rosetta|rec_r34_vd_none_none_ctc_v2.0 | 识别 |
|
||||
| CRNN |rec_mv3_none_bilstm_ctc_v2.0 | 识别 |
|
||||
| CRNN |rec_r34_vd_none_bilstm_ctc_v2.0| 识别 |
|
||||
| StarNet|rec_mv3_tps_bilstm_ctc_v2.0 | 识别 |
|
||||
| StarNet|rec_r34_vd_tps_bilstm_ctc_v2.0 | 识别 |
|
||||
| RARE |rec_mv3_tps_bilstm_att_v2.0 | 识别 |
|
||||
| RARE |rec_r34_vd_tps_bilstm_att_v2.0 | 识别 |
|
||||
| SRN |rec_r50fpn_vd_none_srn | 识别 |
|
||||
| NRTR |rec_mtb_nrtr | 识别 |
|
||||
| SAR |rec_r31_sar | 识别 |
|
||||
| PGNet |rec_r34_vd_none_none_ctc_v2.0 | 端到端|
|
||||
|
||||
|
||||
|
||||
## 一键测试工具使用
|
||||
### 目录介绍
|
||||
|
||||
```shell
|
||||
tests/
|
||||
├── ocr_det_params.txt # 测试OCR检测模型的参数配置文件
|
||||
├── ocr_rec_params.txt # 测试OCR识别模型的参数配置文件
|
||||
├── ocr_ppocr_mobile_params.txt # 测试OCR检测+识别模型串联的参数配置文件
|
||||
└── prepare.sh # 完成test.sh运行所需要的数据和模型下载
|
||||
└── test.sh # 测试主程序
|
||||
├── configs/ # 配置文件目录
|
||||
├── det_mv3_db.yml # 测试mobile版ppocr检测模型训练的yml文件
|
||||
├── det_r50_vd_db.yml # 测试server版ppocr检测模型训练的yml文件
|
||||
├── rec_icdar15_r34_train.yml # 测试server版ppocr识别模型训练的yml文件
|
||||
├── ppocr_sys_mobile_params.txt # 测试mobile版ppocr检测+识别模型串联的参数配置文件
|
||||
├── ppocr_det_mobile_params.txt # 测试mobile版ppocr检测模型的参数配置文件
|
||||
├── ppocr_rec_mobile_params.txt # 测试mobile版ppocr识别模型的参数配置文件
|
||||
├── ppocr_sys_server_params.txt # 测试server版ppocr检测+识别模型串联的参数配置文件
|
||||
├── ppocr_det_server_params.txt # 测试server版ppocr检测模型的参数配置文件
|
||||
├── ppocr_rec_server_params.txt # 测试server版ppocr识别模型的参数配置文件
|
||||
├── ...
|
||||
├── results/ # 预先保存的预测结果,用于和实际预测结果进行精读比对
|
||||
├── ppocr_det_mobile_results_fp32.txt # 预存的mobile版ppocr检测模型fp32精度的结果
|
||||
├── ppocr_det_mobile_results_fp16.txt # 预存的mobile版ppocr检测模型fp16精度的结果
|
||||
├── ppocr_det_mobile_results_fp32_cpp.txt # 预存的mobile版ppocr检测模型c++预测的fp32精度的结果
|
||||
├── ppocr_det_mobile_results_fp16_cpp.txt # 预存的mobile版ppocr检测模型c++预测的fp16精度的结果
|
||||
├── ...
|
||||
├── prepare.sh # 完成test_*.sh运行所需要的数据和模型下载
|
||||
├── test_python.sh # 测试python训练预测的主程序
|
||||
├── test_cpp.sh # 测试c++预测的主程序
|
||||
├── test_serving.sh # 测试serving部署预测的主程序
|
||||
├── test_lite.sh # 测试lite部署预测的主程序
|
||||
├── compare_results.py # 用于对比log中的预测结果与results中的预存结果精度误差是否在限定范围内
|
||||
└── readme.md # 使用文档
|
||||
```
|
||||
|
||||
# 使用方法
|
||||
### 测试流程
|
||||
使用本工具,可以测试不同功能的支持情况,以及预测结果是否对齐,测试流程如下:
|
||||
<div align="center">
|
||||
<img src="docs/test.png" width="800">
|
||||
</div>
|
||||
|
||||
test.sh包含四种运行模式,每种模式的运行数据不同,分别用于测试速度和精度,分别是:
|
||||
1. 运行prepare.sh准备测试所需数据和模型;
|
||||
2. 运行要测试的功能对应的测试脚本`test_*.sh`,产出log,由log可以看到不同配置是否运行成功;
|
||||
3. 用`compare_results.py`对比log中的预测结果和预存在results目录下的结果,判断预测精度是否符合预期(在误差范围内)。
|
||||
|
||||
- 模式1:lite_train_infer,使用少量数据训练,用于快速验证训练到预测的走通流程,不验证精度和速度;
|
||||
```shell
|
||||
bash tests/prepare.sh ./tests/ocr_det_params.txt 'lite_train_infer'
|
||||
bash tests/test.sh ./tests/ocr_det_params.txt 'lite_train_infer'
|
||||
```
|
||||
|
||||
- 模式2:whole_infer,使用少量数据训练,一定量数据预测,用于验证训练后的模型执行预测,预测速度是否合理;
|
||||
```shell
|
||||
bash tests/prepare.sh ./tests/ocr_det_params.txt 'whole_infer'
|
||||
bash tests/test.sh ./tests/ocr_det_params.txt 'whole_infer'
|
||||
```
|
||||
|
||||
- 模式3:infer 不训练,全量数据预测,走通开源模型评估、动转静,检查inference model预测时间和精度;
|
||||
```shell
|
||||
bash tests/prepare.sh ./tests/ocr_det_params.txt 'infer'
|
||||
# 用法1:
|
||||
bash tests/test.sh ./tests/ocr_det_params.txt 'infer'
|
||||
# 用法2: 指定GPU卡预测,第三个传入参数为GPU卡号
|
||||
bash tests/test.sh ./tests/ocr_det_params.txt 'infer' '1'
|
||||
```
|
||||
|
||||
- 模式4:whole_train_infer , CE: 全量数据训练,全量数据预测,验证模型训练精度,预测精度,预测速度;
|
||||
```shell
|
||||
bash tests/prepare.sh ./tests/ocr_det_params.txt 'whole_train_infer'
|
||||
bash tests/test.sh ./tests/ocr_det_params.txt 'whole_train_infer'
|
||||
```
|
||||
|
||||
- 模式5:cpp_infer , CE: 验证inference model的c++预测是否走通;
|
||||
```shell
|
||||
bash tests/prepare.sh ./tests/ocr_det_params.txt 'cpp_infer'
|
||||
bash tests/test.sh ./tests/ocr_det_params.txt 'cpp_infer'
|
||||
```
|
||||
|
||||
# 日志输出
|
||||
最终在```tests/output```目录下生成.log后缀的日志文件
|
||||
其中,有4个测试主程序,功能如下:
|
||||
- `test_python.sh`:测试基于Python的模型训练、评估、推理等基本功能,包括裁剪、量化、蒸馏。
|
||||
- `test_cpp.sh`:测试基于C++的模型推理。
|
||||
- `test_serving.sh`:测试基于Paddle Serving的服务化部署功能。
|
||||
- `test_lite.sh`:测试基于Paddle-Lite的端侧预测部署功能。
|
||||
|
||||
各功能测试中涉及GPU/CPU、mkldnn、Tensorrt等多种参数配置,点击相应链接了解更多细节和使用教程:
|
||||
[test_python使用](docs/test_python.md)
|
||||
[test_cpp使用](docs/test_cpp.md)
|
||||
[test_serving使用](docs/test_serving.md)
|
||||
[test_lite使用](docs/test_lite.md)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user