PaddleOCR/PTDN/docs/test_inference_cpp.md

61 lines
2.5 KiB
Markdown
Raw Normal View History

2021-10-14 18:18:07 +08:00
# C++预测功能测试
2021-10-19 11:41:05 +08:00
C++预测功能测试的主程序为`test_inference_cpp.sh`可以测试基于C++预测库的模型推理功能。
2021-10-14 18:18:07 +08:00
2021-10-18 20:45:52 +08:00
## 1. 测试结论汇总
2021-10-14 18:18:07 +08:00
2021-10-18 20:45:52 +08:00
基于训练是否使用量化,进行本测试的模型可以分为`正常模型`和`量化模型`这两类模型对应的C++预测功能汇总如下:
2021-10-14 18:18:07 +08:00
2021-10-18 20:45:52 +08:00
| 模型类型 |device | batchsize | tensorrt | mkldnn | cpu多线程 |
| ---- | ---- | ---- | :----: | :----: | :----: |
| 正常模型 | GPU | 1/6 | fp32/fp16 | - | - |
| 正常模型 | CPU | 1/6 | - | fp32 | 支持 |
| 量化模型 | GPU | 1/6 | int8 | - | - |
2021-10-19 11:17:13 +08:00
| 量化模型 | CPU | 1/6 | - | int8 | 支持 |
2021-10-14 18:18:07 +08:00
2021-10-18 20:45:52 +08:00
## 2. 测试流程
### 2.1 功能测试
2021-10-19 11:41:05 +08:00
先运行`prepare.sh`准备数据和模型,然后运行`test_inference_cpp.sh`进行测试,最终在```tests/output```目录下生成`cpp_infer_*.log`后缀的日志文件。
2021-10-14 18:18:07 +08:00
```shell
2021-10-18 19:34:12 +08:00
bash tests/prepare.sh ./tests/configs/ppocr_det_mobile_params.txt "cpp_infer"
2021-10-14 18:18:07 +08:00
# 用法1:
2021-10-19 11:41:05 +08:00
bash tests/test_inference_cpp.sh ./tests/configs/ppocr_det_mobile_params.txt
2021-10-14 18:18:07 +08:00
# 用法2: 指定GPU卡预测第三个传入参数为GPU卡号
2021-10-19 11:41:05 +08:00
bash tests/test_inference_cpp.sh ./tests/configs/ppocr_det_mobile_params.txt '1'
2021-10-14 18:18:07 +08:00
```
2021-10-18 20:45:52 +08:00
### 2.2 精度测试
2021-10-14 18:18:07 +08:00
使用compare_results.py脚本比较模型预测的结果是否符合预期主要步骤包括
- 提取日志中的预测坐标;
- 从本地文件中提取保存好的坐标结果;
- 比较上述两个结果是否符合精度预期,误差大于设置阈值时会报错。
2021-10-18 20:45:52 +08:00
#### 使用方式
2021-10-14 18:18:07 +08:00
运行命令:
```shell
2021-10-15 17:00:43 +08:00
python3.7 tests/compare_results.py --gt_file=./tests/results/cpp_*.txt --log_file=./tests/output/cpp_*.log --atol=1e-3 --rtol=1e-3
2021-10-14 18:18:07 +08:00
```
参数介绍:
- gt_file 指向事先保存好的预测结果路径,支持*.txt 结尾,会自动索引*.txt格式的文件文件默认保存在tests/result/ 文件夹下
- log_file: 指向运行tests/test.sh 脚本的infer模式保存的预测日志预测日志中打印的有预测结果比如文本框预测文本类别等等同样支持infer_*.log格式传入
- atol: 设置的绝对误差
- rtol: 设置的相对误差
2021-10-18 20:45:52 +08:00
#### 运行结果
2021-10-14 18:18:07 +08:00
正常运行效果如下图:
2021-10-18 19:34:12 +08:00
<img src="compare_cpp_right.png" width="1000">
2021-10-14 18:18:07 +08:00
出现不一致结果时的运行输出:
2021-10-18 19:34:12 +08:00
<img src="compare_cpp_wrong.png" width="1000">
2021-10-18 20:45:52 +08:00
## 3. 更多教程
2021-10-18 19:34:12 +08:00
本文档为功能测试用更详细的c++预测使用教程请参考:[服务器端C++预测](https://github.com/PaddlePaddle/PaddleOCR/tree/dygraph/deploy/cpp_infer)