PaddleOCR/test_tipc/docs/test_train_inference_python.md

6.2 KiB
Raw Blame History

基础训练预测功能测试

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

1. 测试结论汇总

  • 训练相关:
算法名称 模型名称 单机单卡 单机多卡 多机多卡 模型压缩(单机多卡)
DB ch_ppocr_mobile_v2.0_det 正常训练
混合精度
正常训练
混合精度
正常训练
混合精度
正常训练FPGM裁剪、PACT量化
离线量化(无需训练)
DB ch_ppocr_server_v2.0_det 正常训练
混合精度
正常训练
混合精度
正常训练
混合精度
正常训练FPGM裁剪、PACT量化
离线量化(无需训练)
CRNN ch_ppocr_mobile_v2.0_rec 正常训练
混合精度
正常训练
混合精度
正常训练
混合精度
正常训练PACT量化
离线量化(无需训练)
CRNN ch_ppocr_server_v2.0_rec 正常训练
混合精度
正常训练
混合精度
正常训练
混合精度
正常训练PACT量化
离线量化(无需训练)
PP-OCR ch_ppocr_mobile_v2.0 正常训练
混合精度
正常训练
混合精度
正常训练
混合精度
-
PP-OCR ch_ppocr_server_v2.0 正常训练
混合精度
正常训练
混合精度
正常训练
混合精度
-
PP-OCRv2 ch_PP-OCRv2 正常训练
混合精度
正常训练
混合精度
正常训练
混合精度
-
  • 预测相关:基于训练是否使用量化,可以将训练产出的模型可以分为正常模型量化模型,这两类模型对应的预测功能汇总如下,
模型类型 device batchsize tensorrt mkldnn cpu多线程
正常模型 GPU 1/6 fp32/fp16 - -
正常模型 CPU 1/6 - fp32 支持
量化模型 GPU 1/6 int8 - -
量化模型 CPU 1/6 - int8 支持

2. 测试流程

2.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.2 功能测试

先运行prepare.sh准备数据和模型,然后运行test_train_inference_python.sh进行测试,最终在test_tipc/output目录下生成python_infer_*.log格式的日志文件。

test_train_inference_python.sh包含5种运行模式每种模式的运行数据不同分别用于测试速度和精度分别是

  • 模式1lite_train_infer使用少量数据训练用于快速验证训练到预测的走通流程不验证精度和速度
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'
  • 模式2whole_infer使用少量数据训练一定量数据预测用于验证训练后的模型执行预测预测速度是否合理
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'
  • 模式3infer不训练全量数据预测走通开源模型评估、动转静检查inference model预测时间和精度;
bash test_tipc/prepare.sh ./test_tipc/configs/ppocr_det_mobile_params.txt 'infer'
# 用法1:
bash test_tipc/test_train_inference_python.sh ./test_tipc/configs/ppocr_det_mobile_params.txt 'infer'
# 用法2: 指定GPU卡预测第三个传入参数为GPU卡号
bash test_tipc/test_train_inference_python.sh ./test_tipc/configs/ppocr_det_mobile_params.txt 'infer' '1'
  • 模式4whole_train_inferCE 全量数据训练,全量数据预测,验证模型训练精度,预测精度,预测速度;
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'
  • 模式5klquant_infer测试离线量化
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'

2.3 精度测试

使用compare_results.py脚本比较模型预测的结果是否符合预期主要步骤包括

  • 提取日志中的预测坐标;
  • 从本地文件中提取保存好的坐标结果;
  • 比较上述两个结果是否符合精度预期,误差大于设置阈值时会报错。

使用方式

运行命令:

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

参数介绍:

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

运行结果

正常运行效果如下图:

出现不一致结果时的运行输出:

3. 更多教程

本文档为功能测试用,更丰富的训练预测使用教程请参考:
模型训练
基于Python预测引擎推理