test_train_inference_python.md 6.2 KB
Newer Older
M
MissPenguin 已提交
1
# 基础训练预测功能测试
M
MissPenguin 已提交
2

M
MissPenguin 已提交
3
基础训练预测功能测试的主程序为`test_train_inference_python.sh`,可以测试基于Python的模型训练、评估、推理等基本功能,包括裁剪、量化、蒸馏。
M
MissPenguin 已提交
4

M
MissPenguin 已提交
5
## 1. 测试结论汇总
M
MissPenguin 已提交
6

M
MissPenguin 已提交
7
- 训练相关:
M
MissPenguin 已提交
8

M
MissPenguin 已提交
9
| 算法名称 | 模型名称 | 单机单卡 | 单机多卡 | 多机多卡 | 模型压缩(单机多卡) |
M
MissPenguin 已提交
10
|  :----  |   :----  |    :----  |  :----   |  :----   |  :----   |
M
MissPenguin 已提交
11 12
|  DB  | ch_ppocr_mobile_v2.0_det| 正常训练 <br> 混合精度 | 正常训练 <br> 混合精度 | 正常训练 <br> 混合精度 | 正常训练:FPGM裁剪、PACT量化 <br> 离线量化(无需训练) |
|  DB  | ch_ppocr_server_v2.0_det| 正常训练 <br> 混合精度 | 正常训练 <br> 混合精度 | 正常训练 <br> 混合精度 | 正常训练:FPGM裁剪、PACT量化 <br> 离线量化(无需训练) |
M
MissPenguin 已提交
13 14
| CRNN | ch_ppocr_mobile_v2.0_rec| 正常训练 <br> 混合精度 | 正常训练 <br> 混合精度 | 正常训练 <br> 混合精度 | 正常训练:PACT量化 <br> 离线量化(无需训练) |
| CRNN | ch_ppocr_server_v2.0_rec| 正常训练 <br> 混合精度 | 正常训练 <br> 混合精度 | 正常训练 <br> 混合精度 | 正常训练:PACT量化 <br> 离线量化(无需训练) |
L
doc  
LDOUBLEV 已提交
15 16
|PP-OCR| ch_ppocr_mobile_v2.0| 正常训练 <br> 混合精度 | 正常训练 <br> 混合精度 | 正常训练 <br> 混合精度 | - |
|PP-OCR| ch_ppocr_server_v2.0| 正常训练 <br> 混合精度 | 正常训练 <br> 混合精度 | 正常训练 <br> 混合精度 | - |
M
fix  
MissPenguin 已提交
17
|PP-OCRv2| ch_PP-OCRv2 | 正常训练 <br> 混合精度 | 正常训练 <br> 混合精度 | 正常训练 <br> 混合精度 | - |
M
MissPenguin 已提交
18 19 20 21


- 预测相关:基于训练是否使用量化,可以将训练产出的模型可以分为`正常模型``量化模型`,这两类模型对应的预测功能汇总如下,

T
tink2123 已提交
22
| 模型类型 |device | batchsize | tensorrt | mkldnn | cpu多线程 |
M
MissPenguin 已提交
23 24
|  ----   |  ---- |   ----   |  :----:  |   :----:   |  :----:  |
| 正常模型 | GPU | 1/6 | fp32/fp16 | - | - |
M
MissPenguin 已提交
25
| 正常模型 | CPU | 1/6 | - | fp32 | 支持 |
M
MissPenguin 已提交
26 27
| 量化模型 | GPU | 1/6 | int8 | - | - |
| 量化模型 | CPU | 1/6 | - | int8 | 支持 |
M
MissPenguin 已提交
28 29


M
MissPenguin 已提交
30 31
## 2. 测试流程
### 2.1 安装依赖
M
MissPenguin 已提交
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
- 安装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 ../
    ```


M
MissPenguin 已提交
48
### 2.2 功能测试
M
MissPenguin 已提交
49
先运行`prepare.sh`准备数据和模型,然后运行`test_train_inference_python.sh`进行测试,最终在```test_tipc/output```目录下生成`python_infer_*.log`格式的日志文件。
M
MissPenguin 已提交
50 51


M
MissPenguin 已提交
52
`test_train_inference_python.sh`包含5种运行模式,每种模式的运行数据不同,分别用于测试速度和精度,分别是:
M
MissPenguin 已提交
53 54 55

- 模式1:lite_train_infer,使用少量数据训练,用于快速验证训练到预测的走通流程,不验证精度和速度;
```shell
M
MissPenguin 已提交
56 57
bash test_tipc/prepare.sh ./test_tipc/configs/ppocr_det_mobile_params.txt 'lite_train_infer'
bash test_tipc/test_train_inference_python.sh ./test_tipc/configs/ppocr_det_mobile_params.txt 'lite_train_infer'
M
MissPenguin 已提交
58 59 60 61
```  

- 模式2:whole_infer,使用少量数据训练,一定量数据预测,用于验证训练后的模型执行预测,预测速度是否合理;
```shell
M
MissPenguin 已提交
62 63
bash test_tipc/prepare.sh ./test_tipc/configs/ppocr_det_mobile_params.txt 'whole_infer'
bash test_tipc/test_train_inference_python.sh ./test_tipc/configs/ppocr_det_mobile_params.txt 'whole_infer'
M
MissPenguin 已提交
64 65
```  

M
MissPenguin 已提交
66
- 模式3:infer,不训练,全量数据预测,走通开源模型评估、动转静,检查inference model预测时间和精度;
M
MissPenguin 已提交
67
```shell
M
MissPenguin 已提交
68
bash test_tipc/prepare.sh ./test_tipc/configs/ppocr_det_mobile_params.txt 'infer'
M
MissPenguin 已提交
69
# 用法1:
M
MissPenguin 已提交
70
bash test_tipc/test_train_inference_python.sh ./test_tipc/configs/ppocr_det_mobile_params.txt 'infer'
M
MissPenguin 已提交
71
# 用法2: 指定GPU卡预测,第三个传入参数为GPU卡号
M
MissPenguin 已提交
72
bash test_tipc/test_train_inference_python.sh ./test_tipc/configs/ppocr_det_mobile_params.txt 'infer' '1'
M
MissPenguin 已提交
73 74
```  

M
MissPenguin 已提交
75
- 模式4:whole_train_infer,CE: 全量数据训练,全量数据预测,验证模型训练精度,预测精度,预测速度;
M
MissPenguin 已提交
76
```shell
M
MissPenguin 已提交
77 78
bash test_tipc/prepare.sh ./test_tipc/configs/ppocr_det_mobile_params.txt 'whole_train_infer'
bash test_tipc/test_train_inference_python.sh ./test_tipc/configs/ppocr_det_mobile_params.txt 'whole_train_infer'
M
MissPenguin 已提交
79 80
```  

M
MissPenguin 已提交
81
- 模式5:klquant_infer,测试离线量化;
M
fix doc  
MissPenguin 已提交
82
```shell
M
MissPenguin 已提交
83 84
bash test_tipc/prepare.sh ./test_tipc/configs/ppocr_det_mobile_params.txt 'klquant_infer'
bash test_tipc/test_train_inference_python.sh test_tipc/configs/ppocr_det_mobile_params.txt  'klquant_infer'
M
fix doc  
MissPenguin 已提交
85 86
```

M
MissPenguin 已提交
87

M
MissPenguin 已提交
88
### 2.3 精度测试
M
MissPenguin 已提交
89 90 91 92 93 94

使用compare_results.py脚本比较模型预测的结果是否符合预期,主要步骤包括:
- 提取日志中的预测坐标;
- 从本地文件中提取保存好的坐标结果;
- 比较上述两个结果是否符合精度预期,误差大于设置阈值时会报错。

M
MissPenguin 已提交
95
#### 使用方式
M
MissPenguin 已提交
96 97
运行命令:
```shell
M
MissPenguin 已提交
98
python3.7 test_tipc/compare_results.py --gt_file=./test_tipc/results/python_*.txt  --log_file=./test_tipc/output/python_*.log --atol=1e-3 --rtol=1e-3
M
MissPenguin 已提交
99 100 101
```

参数介绍:  
M
MissPenguin 已提交
102 103
- gt_file: 指向事先保存好的预测结果路径,支持*.txt 结尾,会自动索引*.txt格式的文件,文件默认保存在test_tipc/result/ 文件夹下
- log_file: 指向运行test_tipc/test_train_inference_python.sh 脚本的infer模式保存的预测日志,预测日志中打印的有预测结果,比如:文本框,预测文本,类别等等,同样支持python_infer_*.log格式传入
M
MissPenguin 已提交
104 105 106
- atol: 设置的绝对误差
- rtol: 设置的相对误差

M
MissPenguin 已提交
107
#### 运行结果
M
MissPenguin 已提交
108 109 110 111 112 113

正常运行效果如下图:
<img src="compare_right.png" width="1000">

出现不一致结果时的运行输出:
<img src="compare_wrong.png" width="1000">
M
MissPenguin 已提交
114

M
MissPenguin 已提交
115 116

## 3. 更多教程
M
MissPenguin 已提交
117 118 119
本文档为功能测试用,更丰富的训练预测使用教程请参考:  
[模型训练](https://github.com/PaddlePaddle/PaddleOCR/blob/dygraph/doc/doc_ch/training.md)  
[基于Python预测引擎推理](https://github.com/PaddlePaddle/PaddleOCR/blob/dygraph/doc/doc_ch/inference.md)