diff --git "a/docs/tipc_test/\345\274\200\345\217\221\346\226\207\346\241\243/imgs/autolog_example.png" "b/docs/tipc_test/\345\274\200\345\217\221\346\226\207\346\241\243/imgs/autolog_example.png" new file mode 100644 index 0000000000000000000000000000000000000000..17bab7315da994360a752d1faceddbddb6f40a63 Binary files /dev/null and "b/docs/tipc_test/\345\274\200\345\217\221\346\226\207\346\241\243/imgs/autolog_example.png" differ diff --git "a/docs/tipc_test/\345\274\200\345\217\221\346\226\207\346\241\243/imgs/autolog_results.png" "b/docs/tipc_test/\345\274\200\345\217\221\346\226\207\346\241\243/imgs/autolog_results.png" new file mode 100644 index 0000000000000000000000000000000000000000..aa8bfdf8880bfb09d14bfd774e5c2441b736ec13 Binary files /dev/null and "b/docs/tipc_test/\345\274\200\345\217\221\346\226\207\346\241\243/imgs/autolog_results.png" differ diff --git "a/docs/tipc_test/\345\274\200\345\217\221\346\226\207\346\241\243/imgs/autolog_time.png" "b/docs/tipc_test/\345\274\200\345\217\221\346\226\207\346\241\243/imgs/autolog_time.png" new file mode 100644 index 0000000000000000000000000000000000000000..9e7d75115905969597abe498f7fba8030d314e5d Binary files /dev/null and "b/docs/tipc_test/\345\274\200\345\217\221\346\226\207\346\241\243/imgs/autolog_time.png" differ diff --git "a/docs/tipc_test/\345\274\200\345\217\221\346\226\207\346\241\243/imgs/mac_train_params.png" "b/docs/tipc_test/\345\274\200\345\217\221\346\226\207\346\241\243/imgs/mac_train_params.png" new file mode 100644 index 0000000000000000000000000000000000000000..7342850b697f785c7a1b08cc4f66a0bc14b2a2c2 Binary files /dev/null and "b/docs/tipc_test/\345\274\200\345\217\221\346\226\207\346\241\243/imgs/mac_train_params.png" differ diff --git "a/docs/tipc_test/\345\274\200\345\217\221\346\226\207\346\241\243/imgs/pipline.png" "b/docs/tipc_test/\345\274\200\345\217\221\346\226\207\346\241\243/imgs/pipline.png" new file mode 100644 index 0000000000000000000000000000000000000000..dd227a3d21ace8bde3db96380685707306474eac Binary files /dev/null and "b/docs/tipc_test/\345\274\200\345\217\221\346\226\207\346\241\243/imgs/pipline.png" differ diff --git "a/docs/tipc_test/\345\274\200\345\217\221\346\226\207\346\241\243/imgs/tipc_log_list.png" "b/docs/tipc_test/\345\274\200\345\217\221\346\226\207\346\241\243/imgs/tipc_log_list.png" new file mode 100644 index 0000000000000000000000000000000000000000..054bd342caae3c131bafbd85dc74d6e3e11416b4 Binary files /dev/null and "b/docs/tipc_test/\345\274\200\345\217\221\346\226\207\346\241\243/imgs/tipc_log_list.png" differ diff --git "a/docs/tipc_test/\345\274\200\345\217\221\346\226\207\346\241\243/imgs/tipc_log_results.png" "b/docs/tipc_test/\345\274\200\345\217\221\346\226\207\346\241\243/imgs/tipc_log_results.png" new file mode 100644 index 0000000000000000000000000000000000000000..cf4d5c3b053f7bcb36db5764ebb3046f1df08a14 Binary files /dev/null and "b/docs/tipc_test/\345\274\200\345\217\221\346\226\207\346\241\243/imgs/tipc_log_results.png" differ diff --git "a/docs/tipc_test/\345\274\200\345\217\221\346\226\207\346\241\243/imgs/train_infer_params.png" "b/docs/tipc_test/\345\274\200\345\217\221\346\226\207\346\241\243/imgs/train_infer_params.png" new file mode 100644 index 0000000000000000000000000000000000000000..e4a85aba428406932cb69f043d38a9f18428b9fe Binary files /dev/null and "b/docs/tipc_test/\345\274\200\345\217\221\346\226\207\346\241\243/imgs/train_infer_params.png" differ diff --git "a/docs/tipc_test/\345\274\200\345\217\221\346\226\207\346\241\243/imgs/train_infer_params1.png" "b/docs/tipc_test/\345\274\200\345\217\221\346\226\207\346\241\243/imgs/train_infer_params1.png" new file mode 100644 index 0000000000000000000000000000000000000000..5084358d1d1bdfc29277b816f141381c0e702144 Binary files /dev/null and "b/docs/tipc_test/\345\274\200\345\217\221\346\226\207\346\241\243/imgs/train_infer_params1.png" differ diff --git "a/docs/tipc_test/\345\274\200\345\217\221\346\226\207\346\241\243/imgs/train_infer_params2.png" "b/docs/tipc_test/\345\274\200\345\217\221\346\226\207\346\241\243/imgs/train_infer_params2.png" new file mode 100644 index 0000000000000000000000000000000000000000..22c208dcb05b83301f46bc7dcd46ff8b27e9d5f5 Binary files /dev/null and "b/docs/tipc_test/\345\274\200\345\217\221\346\226\207\346\241\243/imgs/train_infer_params2.png" differ diff --git "a/docs/tipc_test/\345\274\200\345\217\221\346\226\207\346\241\243/imgs/train_infer_params3.png" "b/docs/tipc_test/\345\274\200\345\217\221\346\226\207\346\241\243/imgs/train_infer_params3.png" new file mode 100644 index 0000000000000000000000000000000000000000..95e88c36cdef2bf3180ca0fed715f7013206162d Binary files /dev/null and "b/docs/tipc_test/\345\274\200\345\217\221\346\226\207\346\241\243/imgs/train_infer_params3.png" differ diff --git "a/docs/tipc_test/\345\274\200\345\217\221\346\226\207\346\241\243/imgs/train_infer_params_infer.png" "b/docs/tipc_test/\345\274\200\345\217\221\346\226\207\346\241\243/imgs/train_infer_params_infer.png" new file mode 100644 index 0000000000000000000000000000000000000000..88807c00a8e68bcbf715c6a5012dc848c2b417ae Binary files /dev/null and "b/docs/tipc_test/\345\274\200\345\217\221\346\226\207\346\241\243/imgs/train_infer_params_infer.png" differ diff --git "a/docs/tipc_test/\345\274\200\345\217\221\346\226\207\346\241\243/imgs/train_infer_params_train.png" "b/docs/tipc_test/\345\274\200\345\217\221\346\226\207\346\241\243/imgs/train_infer_params_train.png" new file mode 100644 index 0000000000000000000000000000000000000000..b97dd15c0e2b6905c15c4c9d1b527327ddf07661 Binary files /dev/null and "b/docs/tipc_test/\345\274\200\345\217\221\346\226\207\346\241\243/imgs/train_infer_params_train.png" differ diff --git "a/docs/tipc_test/\345\274\200\345\217\221\346\226\207\346\241\243/imgs/train_infer_params_train_run.png" "b/docs/tipc_test/\345\274\200\345\217\221\346\226\207\346\241\243/imgs/train_infer_params_train_run.png" new file mode 100644 index 0000000000000000000000000000000000000000..e6a3c5c1b6f5d8de07453ded18db8ba5ff6f62f9 Binary files /dev/null and "b/docs/tipc_test/\345\274\200\345\217\221\346\226\207\346\241\243/imgs/train_infer_params_train_run.png" differ diff --git "a/docs/tipc_test/\345\274\200\345\217\221\346\226\207\346\241\243/python\345\237\272\347\241\200\350\256\255\347\273\203\351\242\204\346\265\213\345\274\200\345\217\221\346\226\207\346\241\243.md" "b/docs/tipc_test/\345\274\200\345\217\221\346\226\207\346\241\243/python\345\237\272\347\241\200\350\256\255\347\273\203\351\242\204\346\265\213\345\274\200\345\217\221\346\226\207\346\241\243.md" new file mode 100644 index 0000000000000000000000000000000000000000..a8a4b090f1aad447569f815f8365909c587e575d --- /dev/null +++ "b/docs/tipc_test/\345\274\200\345\217\221\346\226\207\346\241\243/python\345\237\272\347\241\200\350\256\255\347\273\203\351\242\204\346\265\213\345\274\200\345\217\221\346\226\207\346\241\243.md" @@ -0,0 +1,669 @@ +# 基础链条测试接入规范 + +# 目录 +- 总览 + - 1.背景 + - 2.TIPC自动化测试 + - 3.样本检测样板间概览 +- TIPC规范接入流程 + - 1.准备数据 + - 2.规范化输出日志 + - 2.1 训练日志 + - 2.2 预测日志 + - 3.编写自动化测试代码 + - 3.1 训练接入自动化测试 + - 3.2 评估接入自动化测试 + - 3.3 inference预测接入自动化测试 + - 4.附录 + - 4.1 自动化测试脚本test_train_inference_python.sh 函数介绍 + - 4.2 params.txt参数介绍汇总 + - 4.3 其他说明 + - 4.4 Mac端接入TIPC测试 + - 4.5 Windows端接入TIPC测试 + - 4.6 Jeston端接入TIPC测试 + + +# 1、总览 + +飞桨除了基本的模型训练和预测,还提供了支持多端多平台的高性能推理部署工具。本文档提供了PaddleOCR中所有模型的飞桨训推一体认证 (Training and Inference Pipeline Certification(TIPC)) 信息和测试工具,方便用户查阅每种模型的训练推理部署打通情况,并可以进行一键测试。 + +## 1.1 背景: +创建一个自动化测试CI机制,监控框架代码更新可能导致的**模型训练、预测报错、性能下降**等问题。 + +主要监控的内容有: + + - 框架更新后,套件模型的正常训练,量化训练、裁剪训练、评估、动转静、推理预测是否能正常走通;(比如API的不兼容升级) + - 框架更新后,套件模型的预测速度是否合理; + - 框架更新后,套件模型训练的精度是否达标,或训练的loss出现nan等。 + - 其他 +为了能监控上述问题,希望把套件模型的训练、预测TIPC加到框架的CI和CE中,提升PR合入的质量。因此,需要在套件中加入运行脚本(不影响套件正常运行),完成模型的自动化测试。 + +可以建立的CI/CE机制包括: + + 1. **少量数据训练模型,少量数据预测,走通训练到预测链条,保证各模块输出符合预期。(lite_train_lite_infer)(单模型15分钟内)** + a. 保证训练跑通;训练速度正常(监控batch_cost) + b. 训练资源占用合理(显存) + c. 保证训练可复现,loss曲线收敛正常(固定seed后loss一致) + d. 保证训练后模型动转静→inference预测跑通,预测资源占用合理(监控显存内存) + 2. **少量数据训练模型,全量数据预测,验证预测速度;(lite_train_whole_infer)(单模型30分钟内)** + a. 保证训练跑通;训练速度正常(监控batch_cost) + b. 训练资源占用合理(显存) + c. 保证训练可复现,loss曲线收敛正常(固定seed后loss一致) + d. 保证训练后模型动转静→inference预测跑通,预测速度符合预期,预测资源占用合理(监控显存内存) + + 3. **全量数据训练预测,验证训练模型精度和速度;(whole_train_whole_infer)(周级别)** + a. 保证训练跑通;训练速度正常(监控batch_cost),训练精度达到既定值 + b. 训练资源占用合理(显存) + c. 保证训练可复现,loss曲线收敛正常(固定seed后loss一致) + d. 保证训练后模型动转静→inference预测跑通,预测结果正确,预测速度符合预期,预测资源占用合理(监控显存内存) + + 4. **不训练,全量数据走通开源模型评估、预测,并验证模型预测速度和精度是否符合设定预期;(whole_infer)(单模型30分钟内)** + a. 保证训练后模型动转静→inference预测跑通,预测结果正确,预测速度符合预期,预测资源占用合理(监控显存内存) + + +注:由于CI有时间限制,所以在测试的时候需要限制运行时间,所以需要构建一个很小的数据集完成测试。 + +## 1.2 TIPC自动化测试 + +本规范测试的链条如下(其中相邻两个模块之间是两两组合关系),可以根据套件需要,适当删减链条。 +![pipline](./imgs/pipline.png) + +上图各模块具体测试点如下: + +- 模型训练方面(Linux GPU 和 Linux CPU都需要验证): + - 单机单卡**(必选)** + - 单机多卡**(必选)** + +- 模型压缩方面(Linux GPU 和 Linux CPU都需要验证): + - 裁剪训练(可选) + - 在线量化训练(可选) + - 离线量化(可选) + +- 飞桨模型转换,即动转静功能**(必选)** +- Paddle inference 预测部署方面: + - Linux GPU上不同batchsize,是否开启TensorRT,不同预测精度(FP32,FP16,INT8)的运行状态**(必选)** + - Linux CPU上不同batchsize,是否开启MKLDNN,不同预测精度(FP32,FP16,INT8)的运行状态**(必选)** + +## 1.3 文本检测样板间概览 + +在PaddleOCR中,以文本检测为例,提供了本规范的样板间,可以跑通1.2章节提到的**所有测试链条**,完成1.1背景部分提到的4种CI/CE机制。 + +脚本位于PaddleOCR dygraph分支下的test_tipc文件夹:https://github.com/PaddlePaddle/PaddleOCR/tree/dygraph/test_tipc + +test_tipc文件夹下与本规范相关的文件分别是: +``` +test_tipc/ +test_tipc/ +├── configs/ # 配置文件目录 + ├── ppocr_det_mobile/ # ppocr检测模型mobile版本的配置文件和参数文件夹 + ├── det_mv3_db.yml # 测试mobile版ppocr检测模型训练的yml文件 + ├── train_infer_python.txt. # 测试mobile版ppocr检测模型训练+预测的参数配置文件 + ├── train_linux_cpu_normal_normal_infer_python_mac.txt # Mac端测试mobile版ppocr检测模型的参数配置文件 + ├── train_linux_gpu_normal_normal_infer_python_windows.txt # Windows端测试mobile版ppocr检测模型的参数配置文件 + ├── model_linux_gpu_normal_normal_infer_python_jetson.txt # Jeston端测试mobile版ppocr检测模型的参数配置文件 + ├── ... +|- test_train_inference_python.sh 自动化测试脚本,以ppocr_det_mobile_params.txt 为参数配置,组建出不同的运行命令,完成不同参数配置下的所有链条运行。 +|- prepare.sh 以ppocr_det_mobile_params.txt 为参数配置,完成数据、预训练模型、预测模型的自动下载,方便TIPC测试脚本自动运行和QA同学测试。 +|- readme.md 该代码库测试脚本运行说明 +``` + +# 2. TIPC规范接入流程 +TIPC规范接入包含如下三个步骤,接下来将依次介绍这三个部分。 + + - 准备数据 + - 规范化输出日志 + - 编写自动化测试代码 + +## 2.1 准备数据 +由于不同模型所需要的训练、预测数据、预训练模型不同,所以需要一个自动化下载训练数据、预训练模型的脚本,即是prepare.sh 。 +prepare.sh完成命令运行前准备工作,根据不同的运行模式和测试的模型,完成以下功能: + + - 预训练模型下载并解压 + - 训练、预测数据下载并解压 + - 准备编译或者编译好的第三方库等 + +prepare.sh的代码内容如下,参考链接https://github.com/PaddlePaddle/PaddleOCR/blob/dygraph/test_tipc/prepare.sh: +``` +if [ ${MODE} = "lite_train_lite_infer" ];then + # pretrain lite train data + wget -nc -P ./pretrain_models/ https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/MobileNetV3_large_x0_5_pretrained.pdparams --no-check-certificate + wget -nc -P ./pretrain_models/ https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/det_mv3_db_v2.0_train.tar --no-check-certificate + if [ ${model_name} == "PPOCRv2_ocr_det" ]; then + wget -nc -P ./pretrain_models/ https://paddleocr.bj.bcebos.com/PP-OCRv2/chinese/ch_PP-OCRv2_det_distill_train.tar --no-check-certificate + cd ./pretrain_models/ && tar xf ch_PP-OCRv2_det_distill_train.tar && cd ../ + fi + cd ./pretrain_models/ && tar xf det_mv3_db_v2.0_train.tar && cd ../ + rm -rf ./train_data/icdar2015 + rm -rf ./train_data/ic15_data + wget -nc -P ./train_data/ https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/icdar2015_lite.tar --no-check-certificate + wget -nc -P ./train_data/ https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/ic15_data.tar --no-check-certificate + wget -nc -P ./inference https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/rec_inference.tar --no-check-certificate + wget -nc -P ./deploy/slim/prune https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/sen.pickle --no-check-certificate + + cd ./train_data/ && tar xf icdar2015_lite.tar && tar xf ic15_data.tar + ln -s ./icdar2015_lite ./icdar2015 + cd ../ + cd ./inference && tar xf rec_inference.tar && cd ../ +``` + +prepare.sh的使用方式为: +``` +bash test_tipc/prepare.sh 配置文件路径 运行模式 +``` +具体运行命令如下: +``` +bash test_tipc/prepare.sh ./test_tipc/configs/ppocr_det_mobile/train_infer_python.txt 'lite_train_lite_infer' +``` +运行模式一共有7种,分别是: +``` +# 训练 预测相关测试 +lite_train_lite_infer: 少量数据集训练、预测打通验证 +lite_train_whole_infer: 少量数据训练,全量数据预测,验证训练模型预测速度是否合理 +whole_infer: 不训练, 全量数据预测,走通开源模型评估、动转静,检查inference model预测时间和精度 +whole_train_whole_infer: 全量数据训练,全量数据预测,验证模型训练精度,预测精度,预测速度 + +# cpp_infer 预测相关 +cpp_infer: 测试cpp inference的逻辑,不训练,全量数据预测,检查inference model预测时间和精度 +server_infer: 测试 Paddle Server 部署inference的能力,不训练,全量数据预测 + +# 离线量化相关 +klquant_infer: 测试测试离线量化功能和量化inference model的预测速度 +``` +**prepare.sh 根据不同的运行模式,配合从配置文件中解析得到的模型区别性名称,下载不同的数据和训练模型用于完成后续测试。** + +**Tips:** + +(1)shell脚本(prepare.sh)如何解析配置文件(ppocr_det_mobile_params.txt )的参数可以参看附录。 + +(2)由于测试某个模型CI CE有多种模式,不同模式的区别在于训练和测试数据不同,所以在自动下载某个模式的数据时,如果不同数据文件名字不一致,可以通过ln -s 创建软链,确保训练时可以通过配置文件里的默认数据路径加载到数据。例如文本检测样板间中,在whole_train_infer模式下,先删除本地数据集,然后重新下载新的数据集icdar2015.tar 并完成解压。 + +(3)各套件同学在接入时,prepare.sh中的model_name 判断条件以及下载内容的代码需要自行修改,以便在自己的套件中测试。在文本检测样板间中,在infer 模式下,会从配置文件中解析到模型名称,根据不同的模型名称选择下载不同的数据,比如,model_name为ocr_det时,选择下载ch_det_data_50.tar 和 ch_ppocr_mobile_v2.0_det_infer.tar 。 + +下图是文本检测样本间部分片段代码。 +``` +elif [ ${MODE} = "whole_infer" ];then + # 根据不同模型名字下载不同的模型和数据 + if [ ${model_name} = "ocr_det" ]; then + eval_model_name="ch_ppocr_mobile_v2.0_det_train" + rm -rf ./train_data/icdar2015 + wget -nc -P ./inference https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/ch_det_data_50.tar --no-check-certificate + wget -nc -P ./inference https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_det_train.tar --no-check-certificate + wget -nc -P ./inference https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_det_infer.tar --no-check-certificate + cd ./inference && tar xf ${eval_model_name}.tar && tar xf ch_det_data_50.tar && tar xf ch_ppocr_mobile_v2.0_det_infer.tar && cd ../ +``` + +## 2.2 规范化输出日志 + +目前,Paddle各模型对性能统计,方法各异,没有统一规范,甚至有统计不准问题存在: + +1. 计算不准确 + - reader时间未算入耗时统计。 + - 未连续统计,每N个Step打印第N个Step的batch_cost。 + - 将耗时逻辑算入耗时统计内,耗时逻辑如中途模型保存、中途eval。 +2. 打印格式不统一 + - 打印单位各异,如:steps/s, s/step,samples/s等 + - 打印描述各异,如:time、batch_cost、speed等等 + +这导致: +1. 性能数据无可信度 +2. Paddle模型间性能数据不具备可对比性(统计方法不一致) +3. 模型与竞品性能数据不具备可对比性 + +因此,需要对训练和预测的日志给出一个统一的性能统计规范。 + + +### 2.2.1 训练日志规范 + +训练日志中,除了打印loss、精度等信息,还需要有以下信息: + +- reader_cost:1个Step数据加载用时,单位:秒(sec)。 + 1). N个Step打印1条日志时,reader_cost为N个Step数据加载用时的平均值 + 2). 建议(但不强制)使用DataLoader,而非DataFeeder +- batch_cost:1个Step训练用时,单位:秒(sec)。batch_cost = reader_cost + model.forward()(训练)时间。 +- ips:单卡每秒处理的样本数,单位如:images/sec、sequences/sec、tokens/sec、words/sec、frames/sec等。 +- samples。 对于每个Step样本数可能不同的模型(大多为NLP模型),需要计算samples。samples代表上次打印到本次打印,新完成训练的样本数量。 + +加入reader时间统计,有助于开发和测试人员快速发现模型慢的原因,是模型计算慢还是读数据慢。 + +(1)训练日志格式化输出 + +- 最终打印期望格式如下: +``` +..., ... , loss: 0.12345, avg_reader_cost: 0.12345 sec, avg_batch_cost: 0.12345 sec, avg_samples: 100, avg_ips: 0.12345 images/sec +``` +- avg_reader_cost、avg_batch_cost、avg_samples、avg_ips算法如下: +假如,模型每N个Step打印1次日志,每Step reader用时为:`R1, R2,...Rn`,每Step训练用时:`T1, T2,...Tn`,每Step **单卡BatchSize** 为`S1, S2,...Sn`。 +`avg_reader_cost = sum(R1, R2,...Rn) / N` +`avg_batch_cost = avg_reader_cost + sum(T1, T2,...Tn) / N` +`avg_samples = sum(S1, S2,...Sn) / N` +`avg_ips = samples / batch_cost ` +ips 单位如:images/sec、sequences/sec、tokens/sec、words/sec、frames/sec等,单位与竞品保持一致。 + +- 训练日志规范代码示例,或可参考[PaddleOCR代码示例](https://github.com/PaddlePaddle/PaddleOCR/blob/790b5b0b22c2389f10e4f0f6bc828a207be95209/tools/program.py?_pjax=%23js-repo-pjax-container%2C%20div%5Bitemtype%3D%22http%3A%2F%2Fschema.org%2FSoftwareSourceCode%22%5D%20main%2C%20%5Bdata-pjax-container%5D#L286) +``` +for epoch in range(epochs): + ... + train_reader_cost = 0.0 + train_run_cost = 0.0 + total_samples = 0 + reader_start = time.time() + for data in dataloader(): + train_reader_cost += time.time() - reader_start + do_something_else() + train_start = time.time() + outs = exe.run() + train_run_cost += time.time() - train_start + total_samples += batch_size + if batch_id % args.print_step == 0: + print("avg_reader_cost: %.5f sec, avg_batch_cost: %.5f sec, avg_samples: %.5f, ips: %.5f images/sec" % + ( train_reader_cost / args.print_step, + (train_reader_cost + train_run_cost) / args.print_step, + total_samples / args.print_step, + total_samples / (train_reader_cost + train_run_cost) )) + train_reader_cost = 0.0 + train_run_cost = 0.0 + total_samples = 0 + do_something_else2() + reader_start = time.time() +``` + +### 2.2.2 inference日志规范 +(1)背景 +不同套件中paddle inference预测输出的格式均不相同,并且inference输出的信息不够完善,在自动化测试的时候,希望有一套规范且完善的信息格式输出。 + +要求规范输出的信息中除了预测结果输出,还包括以下信息: + +- 当前paddle版本号以及具体commit +- 运行的硬件,CPU还是GPU +- 运行配置信息,是否开启了IR 优化、TRT、MKLDNN,以及具体使用的线程数 +- 运行的模型名称 +- 运行的数据信息,包括batch size,数据量 +- 性能信息,CPU占用内存,GPU显存、利用率信息,inference 各阶段平均预测时间 +- 输入数据的FP32 和FP16的预测结果,用于校验inference结果的正确性 + +(2)预测格式化输出 + +为了方便格式化输出inference预测log、统计预测过程中内存显存等信息,并且统一标准和减少对套件代码的改动,开发了AutoLog工具包,用于统计以上信息和格式化输出。 +auto_log安装方式参考https://github.com/LDOUBLEV/AutoLog +``` +git clone https://github.com/LDOUBLEV/AutoLog +pip3 install -r requirements.txt +python3 setup.py bdist_wheel +pip3 install ./dist/auto_log-1.0.0-py3-none-any.whl +``` + +使用AutoLog 实现自动化日志输出的功能可以参考PR:https://github.com/PaddlePaddle/PaddleOCR/pull/3182 + +代码修改有四步,分别是: +![图片](./imgs/autolog_example.png) +1). 初始化auto_log类:如上图代码所示(参考[PR](https://github.com/PaddlePaddle/PaddleOCR/pull/3182)),调用了auto_log 实现,初始化一个AutoLogger类,传入参数有模型名称、模型精度,batch_size, 输入shape,日志保存路径,inference配置(self.config),pid号和进程名字可选或设置为None,GPU号gpuid; +AutoLogger的初始化参数: +``` +model_name, # string 模型名称 +model_precision, # string 模型精度,fp32, fp16 或者int8 +batch_size, # int 预测的batch_size, +data_shape, # array | list 输入shape, 动态shape的可以设置为dynamic_shape +save_path, # string 日志保存路径,可以设置为None,默认为None +inference_config=None, # Paddle.inference.Config, 用于获取enable_mkldnn, enable_tensorrt等信息; +pids=None, # list, 当前进程的PID号,为None则会自动获取当前运行进程的PID, +process_name=None, # string 用于根据进程名获取进程PID,比如"Python",默认为None,自动获取当前进程的PID +gpu_ids=None # string 使用的GPU id +time_keys: # list 设置时间戳,默认为'preprocess_time', 'inference_time', 'postprocess_time' +warmup: # int 设置warmup的次数,预测的前warmup次数内,不会统计预测时间 +logger: # 用于打印日志的logger,如果设置为None,在类中会自动创建一个logger,默认为None。该参数没有体现在上述PR中,可以参考链接:https://github.com/PaddlePaddle/PaddleOCR/pull/3333/files#diff-8f5279ac130e64d3da88334d137ee2af3356ac06f5a73bee72591945427104ef +``` +2). 预测耗时打点:在模型预测中,统计前处理,预测,后处理时间,传入AutoLogger的preprocess_time, inference_time, postprocess_time中; + +![图片](./imgs/autolog_time.png) + + +3). 打印输出信息:在完成循环预测后,调用AutoLogger的report函数输出log信息。report函数是必须要调用的,否则,统计内存和显存占用的子进程不会关闭。 +其中,text_detector.auto_log.report()实际调用了AutoLogger.report()函数,根据输入的model信息和统计的时间、内存占用信息,规范化输出日志,输入日志格式如下: + +![图片](./imgs/autolog_results.png) + +4). 预测结果正确性校验 + +预测日志中,除了打印环境信息、内存显存占用信息,和预测时间等,还可以打印每个预测样本的预测结果。用于校验inference预测的是否正确。预测结果可以保存为两个,分别是FP32精度下预测的输入,和FP16预测精度下的输出结果。 + +预测可以打印在运行日志中,或者保存在TXT文件中,确保可以用python加载到输出并和当前预测的结果进行对比。 + +以OCR 为例,在PaddleOCR/test_tipc/results文件夹下存放了两个python预测结果的txt文件,分别是: +``` +python_ppocr_det_mobile_results_fp16.txt +python_ppocr_det_mobile_results_fp32.txt +``` +假设在不同配置下可以得到一系列日志文件: +![图片](./imgs/tipc_log_list.png) + +配置文件中存放的有不同输入的预测结果: +![图片](./imgs/tipc_log_results.png) + +因此,可以分别读取预测日志文件中的预测结果和保存在txt文件中的预测结果,验证两个结果是否是一致的。 + +预测结果精度校验可以参考代码:https://github.com/PaddlePaddle/PaddleOCR/blob/dygraph/test_tipc/compare_results.py +在compare_results.py 分别读取了txt中保存的预测结果,和日志文件中保存的结果,通过对比验证二者是否一致或者误差符合预期。 + +注:如果是fp32精度的预测结果,无论是CPU还是GPU,都不允许有太大的误差。但是如果是fp16精度预测,CPU开mkldnn+fp16精度预测的结果和GPU+tensorrt+fp16预测的结果可能不同。原因是,半精度会导致预测结果的不稳定,甚至导致预测精度下降,在测试半精度的误差时,可以预留更合理的误差范围。 + + +## 3 编写自动化测试代码 + +上文提到,自动化测试脚本包括三个部分,分别是运行脚本test_train_inference_python.sh,参数文件txt文件,数据模型准备脚本prepare.sh。 + +``` +|- configs/ppocr_det_mobile/train_infer_python.txt 参数配置文件,用于配置测试哪些功能; +|- test_train_inference_python.sh 自动化测试脚本,以train_infer_python.txt为参数配置,组建出不同的运行命令,完成不同参数配置下的所有链条运行。 +|- prepare.sh 以train_infer_python.txt为参数配置,完成数据、预训练模型、预测模型的自动下载。 +``` +三个文件各司其职,*.txt是参数配置文件,用于设置测试哪些功能,比如训练部分测试分布式训练和混合精度训练等, +prepare.sh 负责完成测试前的准备工作,包括完成数据、预训练模型、预测模型的自动下载等等。 +test_train_inference_python.sh则是自动化测试的运行脚本,根据params.txt中的参数配置,组合出不同的运行指令并执行指令。 + +本节将详细介绍如何修改txt参数文件,完成模型训练、评估和测试。运行脚本test_train_inference_python.sh将会在附录中详细介绍。 + +### 3.1 训练接入自动化测试 +test_train_inference_python.sh在运行的时候,会依次解析ppocr_det_mobile_params.txt中的参数,根据ppocr_det_mobile_params.txt参数配置完成命令组合,举例如下: + +PaddleOCR 文本检测模型的训练运行命令是: + +``` +python3.7 tools/train.py -c configs/det/det_mv3_db.yml -o Global.pretrained_model=./pretrain_models/ Global.use_gpu=True Global.auto_cast=False Global.epoch_num=10 Global.save_model_dir=./test/output/ +``` +虽然不同套件的训练运行方式差异较大,但是都可以拆分为三个部分: +``` +python run_script set_configs +``` +对应到上述运行命令,python即是python3.7 +``` +run_script 即是 tools/train.py -c configs/det/det_mv3_db.yml -o +set_configs 即是 Global.pretrained_model=./pretrain_models/ Global.use_gpu=True Global.auto_cast=False Global.epoch_num=10 Global.save_model_dir=./test/output/ +``` +因此,可以把上述三个部分参数化,如下格式: +``` +python版本 运行脚本和配置文件 参数1 参数2 参数3 参数4 参数5 +``` +所有套件的运行方式都可以按照上述格式组建出一条完整的运行命令。完成命令组建后,在shell脚本中通过eval $cmd 指令即可完成指令的运行。 + +实际上,params.txt 中完成以上参数的设置,test_train_inference_python.sh 脚本根据params.txt中的配置组建出一条完整的运行命令。 + +以文本检测样板间[ppocr_det_mobile/train_infer_python.txt](https://github.com/PaddlePaddle/PaddleOCR/blob/dygraph/test_tipc/configs/ppocr_det_mobile_params.txt)为例,文件中前22行为训练相关的参数,如下图: +![图片](./imgs/train_infer_params.png) + +|行号 | 参数 | 参数介绍 | 对应PaddleSeg参数设置 | +|---|---|---|---| +|2 | model_name:ocr_det | 定义了model_name: ocr_det ,ocr_det也是prepare.sh中用于区分其他模型的名称 | model_name:hrnetw18_small_v1 | +|3 | python:python3.7 | 定义了python版本: 默认使用python3.7,也可以改为python3, python3.6等等 | python:python3.7 | +|4 | gpu_list:0|0,1 | 第4行定义了GPU列表:0表示用0号GPU,0,1表示用0卡和1卡分布式训练,不同配置中间用|分割开;如果在3,4卡运行,可以设置为 gpu_list:3,4 | gpu_list:0|0,1 | +|5 | Global.use_gpu:True|True | 定义了参数设置:根据gpu_list的配置设置是否使用GPU,如果套件没有这个参数,可以设置为null,当前行的null数量和第四行的配置数量相同,比如null|null; | Global.use_gpu:null|null | +|6 | Global.auto_cast:null | 定义了混合精度训练参数设置:如果测试混合精度训练和非混合精度训练,可以设置为True|False,如果没有这个参数,可以设置为null,让该参数不生效; | Global.auto_cast:null| +|7 | Global.epoch_num:lite_train_lite_infer=1|whole_train_whole_infer=300 | 定义了epoch 设置参数:设置epoch数量,有的套件可能是设置iter数量,都是一个意思,由于不同模式需要的epoch或iter数量不一致,需要设置不同模式下的epoch数;量,:lite_train_lite_infer=2|whole_train_whole_infer=300表示lite_train_lite_infer模式下是2,whole_train_whole_infer模式下设置为300,不设置的话,默认用配置文件里的参数; | --iters:lite_train_lite_infer=50|lite_train_whole_infer=50|whole_train_whole_infer=1000 | +|8 | Global.save_model_dir:./output/ | 定义了保存模型设置参数:需要修改:之前的关键字 | --save_dir: | +|9 | Train.loader.batch_size_per_card:lite_train_lite_infer=2|whole_train_whole_infer=4 | 定义batch_size设置参数:同第7行使用方式相同; | --batch_size:lite_train_lite_infer=2|whole_train_whole_infer=8 | +|10 | Global.pretrained_model:null | 定义了加载预训练模型 设置参数:如果不需要加载预训练模型,可以不用修改,:后可以设置为null | Global.pretrained_model:null | +|11 | train_model_name:latest | 定义了保存模型的名字,目前不同套件保存的模型名字五花八门,为了保证能正确加载到模型,需要这个参数指定到具体的参数名称 | train_model_name:best_model/model.pdparams | +|12 | train_infer_img_dir:./train_data/icdar2015/text_localization/ch4_test_images/ | 定义了训练后执行预测的数据路径,不需要设置数据路径的话,value部分设置为null; | train_infer_img_dir:test_tipc/data/mini_supervisely/test.txt | +|13 | null:null | 为预留的参数位置,如果需要设置其他参数,可以按照格式 params_key:params_value 修改为想要的参数; | null:null | +| 14| ## | 占位符 | ## | +|15 | trainer:norm_train|pact_train | 要测试的trainer;norm_train|pact_train表示测试第16行和第17行的部分,如果不测试pact训练,此处设置为trainer:norm_train|trainer:norm | +| 16| norm_train:tools/train.py -c configs/det/det_mv3_db.yml -o | 设置正常训练的train 运行脚本:OCR检测模型的运行脚本为tools/train.py -c configs/det/det_mv3_db.yml -o | norm_train:train.py --config test_tipc/fcn_hrnetw18_small_v1_humanseg_192x192_mini_supervisely.yml --do_eval --save_interval 100 --seed 100 | +|17|pact_train:deploy/slim/quantization/quant.py -c configs/det/det_mv3_db.yml -o|量化训练的train 运行脚本:使用方法同第16行;不测试量化功能可以设置为null;|pact_train:null| +|18|fpgm_train:deploy/slim/prune/sensitivity_anal.py -c configs/det/det_mv3_db.yml -o Global.pretrained_model=./pretrain_models/det_mv3_db_v2.0_train/best_accuracy|裁剪训练的train 运行脚本:使用方法同第16行;不测试量化功能可以设置为null;|fpgm_train:null| +|19|distill_train:null|蒸馏训练的train 运行脚本:使用方法同第16行;不测试量化功能可以设置为null;|distill_train:null| +|20|null: null|预留行,为以后扩展功能做准备|null: null| +|21|null: null|预留行,为以后扩展功能做准备|null: null| +|22|##|占位符|##| + +params.txt中的参数都是可以修改的,可以修改的内容包括: + +- ':'前后的部分均可修改,根据不同模型的运行命令对应修改 +- 无需设置的参数设置为null:null,设置为null的参数不会生效 +- ===train_params==该行无需修改 + +注:其他模型接入TIPC时,注意:前后不要随意加空格,如果params.txt中的训练参数行数不足以组建运行命令,可以考虑一些参数放在默认训练的配置文件中。如果仍需要添加新的参数,可以考虑扩展null:null的参数行成为新的参数行,或者自行修改test_train_inference_python.sh的代码完成训练配置。 + + +### 3.2 评估接入自动化测试 +该部分用于评估模型的训练精度。模型训练后可以执行模型评估,如果要评估模型,可以在txt参数文件的第23-26行设置, + +需要说明的是,评估是顺接训练后进行的,因此,设置训练的参数等对评估也是生效的,所以在评估阶段不需要额外设置其他参数。同时也不需要设置评估所需要的模型,因为评估的模型会自动加载训练后的模型。 + +如果不希望进行模型评估,可以设置为null,如下设置: +``` +===========================eval_params=========================== +eval:null +null:null +## +``` + +### 3.3 inference预测接入自动化测试 +inference 相关的参数在params.txt中的第27行到51行,如下图: +![](./imgs/train_infer_params_infer.png) + + +各行参数介绍和修改方式如下: +|行号 | 参数 | 参数介绍 | 对应PaddleSeg参数设置 | +|---|---|---|---| +|28 | Global.save_inference_dir:./output/ | 保存导出inference model的参数,主要设置参数名字,后面的路径可以不设置或者设置为null | | +|29 | Global.pretrained_model: | 导出模型时加载模型的参数,主要设置参数名字 | | +| 30| norm_export:tools/export_model.py -c configs/det/det_mv3_db.yml -o | 正常训练模型导出的运行脚本运行方式 | norm_export:export.py --config test_tipc/fcn_hrnetw18_small_v1_humanseg_192x192_mini_supervisely.yml | +| 31| quant_export:deploy/slim/quantization/export_model.py -c configs/det/det_mv3_db.yml -o | 量化训练的模型导出运行方式 | quant_export:null | +| 32| fpgm_export:deploy/slim/prune/export_prune_model.py -c configs/det/det_mv3_db.yml -o | 裁剪训练的模型导出方式 | fpgm_export:null | +|33 | distill_export:null | 蒸馏训练的模型导出方式 | distill_export:null | +|34 | export1:null | 预留位置,无需理会 | export1:null | +| 35| export2:null | 预留位置,无需理会 | export2:null | +|36 | ##| 占位符 | ##| +| 37| infer_model:./inference/ch_ppocr_mobile_v2.0_det_infer/ | infer 模式下加载模型的路径| infer_model:./test_tipc/output/norm_gpus_0_autocast_null/model.pdparams | +|38 | infer_export:null | 是否执行37行设置的模型执行动转静,null表示不执行 | infer_export:export.py --config test_tipc/fcn_hrnetw18_small_v1_humanseg_192x192_mini_supervisely.yml | +|39 | infer_quant:False | 37行设置的模型路径是否是量化模型 | infer_quant:False | +|40 | inference:tools/infer/predict_det.py | inference执行的脚本 | inference:deploy/python/infer.py | +| 41| --use_gpu:True|False | 设置GPU的参数,其他套件可能是device参数,用于设置不同硬件的参数,作用类似。设置多个配置时,中间用|隔开,会分别运行不同配置下的预测 | --device:cpu|gpu| +|42|--enable_mkldnn:True|False | 设置是否开启mkldnn,使用方式同41行 | --enable_mkldnn:True|False | +|43|--cpu_threads:1|6 | 设置CPU线程数,如果要测试CPU上不同线程下的预测速度和精度,可以设置多个值,不同值用|隔开 | --cpu_threads:1|6 | +| 44| --rec_batch_num:1 | 设置batch_size 的参数,使用方法同43行 | --batch_size:1 | +| 45| --use_tensorrt:False|True | 设置开启TRT的参数,使用方法同41 | --use_trt:False|True | +| 46| --precision:fp32|fp16|int8 | 设置开启TRT后预测精度的参数,使用方法同41 | --precision:fp32|int8|fp16 | +|47 | --det_model_dir: | 设置加载inference模型路径的参数,无需设置:后的部分 | null: | +|48 | --image_dir:./inference/ch_det_data_50/all-sum-510/ | 设置infer 模式下预测的数据路径 | --image_path:./test_tipc/data/mini_supervisely/test.txt | +|49 | --save_log_path:null | 设置Autolog保存日志的路径参数;目前默认在test_train_inference_python.sh中用重定向的方式保存运行日志,该参数可以不用设置或者设置为null:null | --save_log_path:null | +| 50| --benchmark:True | 设置是否开启AutoLog的参数,使用参考[链接](https://github.com/PaddlePaddle/PaddleOCR/blob/073a591ceeadc41f7bc67ea829dd7d7698a8215b/tools/infer/predict_det.py#L101) | --save_log_path:null | +| 51| null:null | 扩展参数,如果以上参数不满足需求,可以在此处设置参数,params_key:params_value 格式即可 | null:null | + +**注意:上表中由于格式原因,参数名字前的`—` 实际上应该是`--`。`|`是英文输入下的 `|`.** + + +inference预测大多都是通过arg parse传入参数的方式,并且不同套件预测的超参数命名也不尽相同。 + +文本检测样板间执行预测的命令格式是: +``` +python3.7 tools/infer/predict_det.py --use_gpu=True --use_tensorrt=False --precision=fp32 --det_model_dir=./test/output/infer --rec_batch_num=1 --image_dir=./ch_det_data_50/all-sum-510 --save_log_path=./test/output +``` +可以明显发现 `tools/infer/predict_det.py` 对应到40行参数设置的值,`--use_gpu ... --use_tensorrt `等参数可以通过41-50行的参数分别进行设置。另外,可以发现以下参数有多个参数值: +``` +--use_gpu:True|False +--enable_mkldnn:True|False +--cpu_threads:1|6 +--rec_batch_num:1 +--use_tensorrt:False|True +--precision:fp32|fp16 +``` +原因是,在自动化测试的时候,希望测试覆盖的链条更加全面,比如CPU上开启mkldnn,设置不同的线程数和batch_size大小,预测速度也会有很大变化,因此,可以根据参数的选项组合出更多的测试情况,如: +``` +python3.7 tools/infer/predict_det.py --enable_mkldnn=True --cpu_threads=1 --rec_batch_num=1 # 开启mkldnn + 1线程+ 1 batchsize +python3.7 tools/infer/predict_det.py --enable_mkldnn=True --cpu_threads=6 --rec_batch_num=1 # 开启mkldnn + 6线程+ 1 batchsize +python3.7 tools/infer/predict_det.py --use_gpu=True --use_tensorrt=True --precision=fp16 # GPU运行 + 开启TRT+ fp16精度预测 +``` + + +**Tips:调试技巧** + +为了快速解决接入自动化测试遇到的问题,一些调试技巧列举如下: + + - test_train_inference_python.sh中的 eval 改为echo,即不运行指令而是打印要运行的指令; + + - 功能测试时,可以先单独运行命令是否能正常运行,确保功能正常; + + - shell中对空格的使用非常严格,= 前后不要加空格 + + +# 4. 附录 +## 4.1 common_func.sh 函数介绍 + +common_func.sh 中包含了5个函数,会被test_train_inference_python.sh 等执行脚本调用,分别是: +``` +func_parser_key() 解析params.txt中:前的部分 + +func_parser_value() 解析params.txt中:后的部分 + +func_set_params() 会反馈key=value的字符串,用与组建参数命令,如果key或者value为null,则返回空字符,即这个参数不会生效 + +func_parser_params() 为了解析和测试模式MODE相关的参数,目前只用来解析epoch和batch size参数 + +status_check() 状态检查函数,获取上条指令运行的状态,如果是0,则运行成功,如果是其他则运行失败,失败和成功的指令都会存放在results.log文件中 +``` +同一个模型要测试的组合可以通过一个txt文件管理,如下,构建了一个test_tipc/configs/ppocr_det_mobile/train_infer_python.txt文件 用于管理训练配置。 + +![](./imgs/train_infer_params_train.png) +上述部分是test_train_inference_python.sh运行所需要的参数部分,包含正常训练脚本(第16行),量化训练执行脚本(17行),训练所需配置的参数(第4-10行) + +在执行test_train_inference_python.sh脚本执行的时候,会解析对应行的参数,如下: +``` +dataline=$(awk 'NR==1, NR==51{print}' $FILENAME) +``` +首先,FILENAME变量传入的是参数文件,从参数文件中获取到params.txt中的所有参数,如果是lite_train_lite_infer模式下,获取FILENAME参数文件第1行到51行的参数。 + +参数解析格式通过func_parser_params和func_parser_value函数完成,如下: +``` +# The training params +model_name=$(func_parser_value "${lines[1]}") +python=$(func_parser_value "${lines[2]}") +gpu_list=$(func_parser_value "${lines[3]}") +train_use_gpu_key=$(func_parser_key "${lines[4]}") +train_use_gpu_value=$(func_parser_value "${lines[4]}") +autocast_list=$(func_parser_value "${lines[5]}") +autocast_key=$(func_parser_key "${lines[5]}") +epoch_key=$(func_parser_key "${lines[6]}") +epoch_num=$(func_parser_params "${lines[6]}") +save_model_key=$(func_parser_key "${lines[7]}") +train_batch_key=$(func_parser_key "${lines[8]}") +train_batch_value=$(func_parser_params "${lines[8]}") +pretrain_model_key=$(func_parser_key "${lines[9]}") +pretrain_model_value=$(func_parser_value "${lines[9]}") +train_model_name=$(func_parser_value "${lines[10]}") +train_infer_img_dir=$(func_parser_value "${lines[11]}") +train_param_key1=$(func_parser_key "${lines[12]}") +train_param_value1=$(func_parser_value "${lines[12]}") +``` + +解析到的训练参数在test_train_inference_python.sh中的第263-269行,通过`func_set_params`完成参数配置,`func_set_params`有两个输入分别是key value,最终返回的格式为key=value,比如: +``` +# case1 +cpp_batch_size_key="batch_size" +batch_size="10" +set_batchsize=$(func_set_params "${cpp_batch_size_key}" "${batch_size}") + +echo $set_batchsize +# batch_size=10 # 输出结果是字符串batch_size=10 + +# case2 +cpp_batch_size_key="batch_size" +batch_size="null" +set_batchsize=$(func_set_params "${cpp_batch_size_key}" "${batch_size}") +echo $set_batchsize +# # 输出结果是空字符 +``` +如果value为空格,或者null,则`func_set_params`返回的结果为空格,在组建命令的时候,这个参数就不会生效,因此,如果不希望设置某个参数,可以把参数设置为null。 + +最终,所有参数可以组合出一个完整的命令,组合方式: +![](./imgs/train_infer_params_train_run.png) +上图中273行即是组合出的命令,python对应python3.7, run_train 可以是`ppocr_det_mobile_params.txt`中的`norm_train`,`quant_train`参数后的执行脚本,即要执行正常训练的脚本还是执行量化训练的脚本等等。 + +### 4.2 params.txt参数介绍汇总 +文件链接 https://github.com/PaddlePaddle/PaddleOCR/blob/dygraph/test_tipc/configs/ppocr_det_mobile_params.txt +![](./imgs/train_infer_params1.png) +![](./imgs/train_infer_params2.png) +![](./imgs/train_infer_params3.png) + + +### 4.4 Mac端接入TIPC测试 + +在第3节:编写自动化测试章节,介绍了linux端如何完成训练、评估、预测的测试。Mac端的测试方法同Linux端。但是由于Mac端没有GPU,并且CPU芯片不支持Mkldnn,因此在Mac端无需测试GPU训练、TensorRT以及mkldnn相关的功能。本节以PaddleOCR为例,介绍如何在Mac端接入TIPC测试。 + +#### 4.4.1 Mac端训练评估接入自动化测试 + +由于Mac上没有GPU,因此只需要测试CPU训练的链条,包括: +- CPU上正常训练 +- CPU上量化训练 +- CPU上裁剪训练 + +训练参数配置参考[链接](https://github.com/PaddlePaddle/PaddleOCR/blob/bc95e05de88dc7484bc2ed1bb11069455c49ec94/test_tipc/configs/ppocr_det_mobile/train_linux_cpu_normal_normal_infer_python_mac_cpu.txt?_pjax=%23js-repo-pjax-container%2C%20div%5Bitemtype%3D%22http%3A%2F%2Fschema.org%2FSoftwareSourceCode%22%5D%20main%2C%20%5Bdata-pjax-container%5D#L1-L26),如下: + +![图片](./imgs/mac_train_params.png) + +可以对比[Linux端参数配置](https://github.com/PaddlePaddle/PaddleOCR/blob/bc95e05de88dc7484bc2ed1bb11069455c49ec94/test_tipc/configs/ppocr_det_mobile/train_infer_python.txt?_pjax=%23js-repo-pjax-container%2C%20div%5Bitemtype%3D%22http%3A%2F%2Fschema.org%2FSoftwareSourceCode%22%5D%20main%2C%20%5Bdata-pjax-container%5D#L1-L26)发现二者的区别。 + +Mac端需要设置不使用GPU训练,可以通过设置gpu_list:-1实现,-1表示使用CPU训练,同时PaddleOCR通过设置Global.use_gpu参数选择是否在GPU上运行,CPU上运行时需要设置为False。另外,Mac端也无需测试混合精度训练,因此,设置混合精度的参数选项Global.auto_cast为null,表示当前参数不生效。 +``` +gpu_list:-1 +Global.use_gpu:False +Global.auto_cast:null +``` + +#### 4.4.1 Mac端预测接入自动化测试 + +Mac端预测无需测试TensorRT和Mkldnn相关的预测链条,仅需要测试CPU上运行情况,PaddleOCR DB检测模型关于Mac端预测参数配置参考[链接](https://github.com/PaddlePaddle/PaddleOCR/blob/bc95e05de88dc7484bc2ed1bb11069455c49ec94/test_tipc/configs/ppocr_det_mobile/train_linux_cpu_normal_normal_infer_python_mac_cpu.txt?_pjax=%23js-repo-pjax-container%2C%20div%5Bitemtype%3D%22http%3A%2F%2Fschema.org%2FSoftwareSourceCode%22%5D%20main%2C%20%5Bdata-pjax-container%5D#L27-L51) + +在参数文件中,将tensorrt,mkldnn相关的参数--use_tensortt 、--enable_mkldnn均设置为False。 + +### 4.5 Windows端接入TIPC测试 + +Windows接入TIPC测试与Linux端接入方法完全相同,因此Windows端的测试方法可以参考第3节:编写自动化测试章节。 + +PaddleOCR检测模型在Windows上的TIPC配置文件参考[链接](https://github.com/PaddlePaddle/PaddleOCR/blob/dygraph/test_tipc/configs/ppocr_det_mobile/train_linux_gpu_normal_normal_infer_python_windows_cpu_gpu.txt) + +另外,考虑到Windows上和linux的文件路径方式不同,建议在win上安装gitbash终端,在gitbash中执行指令的方式和在linux端执行指令方式相同,更方便tipc测试。gitbash下载[链接](https://git-scm.com/download/win)。 + + + +### 4.6 Jeston端接入TIPC测试 + +Jeston产品是Nvidia推出的开发者套件,用于部署AI模型。Jeston系列的产品有Jeston Nano, TX,NX等等。本节以PaddleOCR检测模型和JestonNX为例,介绍如何在Jeston上接入TIPC预测推理的测试。 + +Jeston的CPU性能远差于笔记本或者台式机,因此在Jeston上,只需要测试GPU上预测相关的链条即可,包括GPU预测,GPU+TensorRT(fp32),GPU+TensorRT(fp16)预测。 + +Jeston上预测推理的参数如下: +``` +===========================infer_params=========================== +model_name:ocr_det +python:python +infer_model:./inference/ch_ppocr_mobile_v2.0_det_infer +infer_export:null +infer_quant:False +inference:tools/infer/predict_det.py +--use_gpu:True|False +--enable_mkldnn:False +--cpu_threads:1|6 +--rec_batch_num:1 +--use_tensorrt:False|True +--precision:fp16|fp32 +--det_model_dir: +--image_dir:./inference/ch_det_data_50/all-sum-510/ +null:null +--benchmark:True +null:null +``` + +可以发现上图中第5行参数infer_export参数设置为null,表示不执行动转静的逻辑,同样在执行预测参数的选择上,做如下配置: +``` +--use_gpu:True|False +--enable_mkldnn:False +--cpu_threads:1|6 +--rec_batch_num:1 +--use_tensorrt:False|True +--precision:fp16|fp32 +``` +在Jeston CPU上执行预测时,仅测试CPU不同线程数的情况,由于jeston机器上的CPU不支持开启mlkdnn,所以设置参数--enable_mkldnn为False。 +在Jeston GPU上,需要测试开启TensorRT在不同精度(fp32, fp16)下的预测情况。所以设置--use_tensorrt:False|True, --precision:fp16|fp32。 + + + diff --git "a/docs/tipc_test/\346\265\213\350\257\225\346\226\207\346\241\243/python\345\237\272\347\241\200\350\256\255\347\273\203\351\242\204\346\265\213\346\265\213\350\257\225\346\226\207\346\241\243\350\247\204\350\214\203.md" "b/docs/tipc_test/\346\265\213\350\257\225\346\226\207\346\241\243/python\345\237\272\347\241\200\350\256\255\347\273\203\351\242\204\346\265\213\346\265\213\350\257\225\346\226\207\346\241\243\350\247\204\350\214\203.md" new file mode 100644 index 0000000000000000000000000000000000000000..219f933663d4a85463fc1b9a879e33008d540e68 --- /dev/null +++ "b/docs/tipc_test/\346\265\213\350\257\225\346\226\207\346\241\243/python\345\237\272\347\241\200\350\256\255\347\273\203\351\242\204\346\265\213\346\265\213\350\257\225\346\226\207\346\241\243\350\247\204\350\214\203.md" @@ -0,0 +1,309 @@ +# 背景 + +基础训练文档对应基础训练预测功能测试,主程序为`test_train_inference_python.sh`。本文介绍基础训练预测在Linux端,Mac端,Windows端,Jeston端的使用方法。 + +# 文档规范 + +本文档为TIPC的基础训练预测功能测试文档。包含linux端,Mac端,Windows端,jeston端的测试方法。 + +### 1.基础训练预测规范 +基础训练预测工具测试的功能包括训练和Python预测两部分,汇总结论也分为`训练相关`和`预测相关`两部分。 +下面以[PaddleOCR样板间](https://github.com/PaddlePaddle/PaddleOCR/tree/dygraph/test_tipc)为例说明目录结构规范。 +```shell +test_tipc/ +├── configs/ # 配置文件目录 + ├── ppocr_det_mobile/ # ppocr检测模型mobile版本的配置文件和参数文件夹 + ├── det_mv3_db.yml # 测试mobile版ppocr检测模型训练的yml文件 + ├── train_infer_python.txt. # 测试mobile版ppocr检测模型训练+预测的参数配置文件 + ├── train_linux_cpu_normal_normal_infer_python_mac.txt # Mac端测试mobile版ppocr检测模型的参数配置文件 + ├── train_linux_gpu_normal_normal_infer_python_windows.txt # Windows端测试mobile版ppocr检测模型的参数配置文件 + ├── model_linux_gpu_normal_normal_infer_python_jetson.txt # Jeston端测试mobile版ppocr检测模型的参数配置文件 + ├── ... +├── results/ # 预先保存的预测结果,用于和实际预测结果进行精读比对 + ├── python_ppocr_det_mobile_results_fp32.txt # 预存的mobile版ppocr检测模型python预测fp32精度的结果 + ├── python_ppocr_det_mobile_results_fp16.txt # 预存的mobile版ppocr检测模型python预测fp16精度的结果 + ├── cpp_ppocr_det_mobile_results_fp32.txt # 预存的mobile版ppocr检测模型c++预测的fp32精度的结果 + ├── cpp_ppocr_det_mobile_results_fp16.txt # 预存的mobile版ppocr检测模型c++预测的fp16精度的结果 + ├── ... +├── prepare.sh # 完成test_*.sh运行所需要的数据和模型下载 +├── test_train_inference_python.sh # 测试python训练预测的主程序 +├── test_inference_cpp.sh # 测试c++预测的主程序 +├── test_serving.sh # 测试serving部署预测的主程序 +├── test_lite.sh # 测试lite部署预测的主程序 +├── compare_results.py # 用于对比log中的预测结果与results中的预存结果精度误差是否在限定范围内 +└── readme.md # 使用文档 +``` +主要关注: +1. 所有工具位于`test_tipc`目录下,`test_tipc`目录位于套件根目录下; +2. `configs`目录存放测试所需的所有配置文件; +2. `results`目录存放精度测试所需的gt文件; +3. `doc`目录存放readme.md以外的其他子文档; +4. `prepare.sh`用于准备测试所需的模型、数据等; +5. `test_*.sh`为测试主程序,按照功能分为多个文件,命名格式为`test_[功能]_[语言].sh`。 + + +(1)训练相关 + +内容:给出套件所有模型的基础训练预测打通情况汇总信息,表格形式呈现,须包含`算法名称`、`模型名称`、`单机单卡`、`单机多卡`、`多机多卡`、`模型压缩(单机多卡)`这6个字段。 + +- 算法名称:该模型对应的算法,可以是算法简称; +- 模型名称:与套件提供模型的名称对应; +- 单机单卡:单机单卡训练的支持情况,包括`正常训练`和`混合精度`两种模式,支持哪种模式就填写哪种。 +- 单机多卡:同上。 +- 多机多卡:同上。 +- 模型压缩(单机多卡):单机多卡模式下,支持的模型压缩算法,分别给出`正常训练`、`混合精度`、`离线量化`三种情况的模型压缩算法支持情况。 + +示例: +| 算法名称 | 模型名称 | 单机单卡 | 单机多卡 | 多机多卡 | 模型压缩(单机多卡) | +| :---- | :---- | :---- | :---- | :---- | :---- | +| 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 | 正常训练
混合精度 | 正常训练
混合精度 | 正常训练
混合精度 | - | + + +(2)预测相关 + +内容:基于训练是否使用量化,可以将训练产出的模型可以分为`正常模型`和`量化模型`,表格形式给出这两类模型对应的预测功能汇总情况,包含`模型类型`、`device`、`batchsize`、`tensorrt`、`mkldnn`、`cpu多线程`这6个字段。 + +- 算法名称:该模型对应的算法,可以是算法简称; +- device:CPU或GPU,其他字段取值对应本字段指定的环境; +- batchsize:一般包括1、6两种batchsize,根据实际支持情况填写。 +- tensorrt:开启tensorrt支持的精度,包括`fp32`、`fp16`、`int8`三种,当device为CPU时,本字段填`-`。 +- mkldnn:开启mkldnn支持的精度,包括`fp32`、`fp16`、`int8`三种,当device为GPU时,本字段填`-`。 +- cpu多线程:支持时填`支持`,不支持时留空即可,当device为GPU时,本字段填`-`。 + +基于训练是否使用量化,可以将训练产出的模型可以分为`正常模型`和`量化模型`,这两类模型对应的预测功能汇总如下: + +| 模型类型 |device | batchsize | tensorrt | mkldnn | cpu多线程 | +| ---- | ---- | ---- | :----: | :----: | :----: | +| 正常模型 | GPU | 1/6 | fp32/fp16 | - | - | +| 正常模型 | CPU | 1/6 | - | fp32/fp16 | 支持 | +| 量化模型 | GPU | 1/6 | int8 | - | - | +| 量化模型 | CPU | 1/6 | - | int8 | 支持 | + + + + +### 2.测试流程 +#### 2.1 安装依赖 +安装测试本功能所需的依赖,包括`autolog`工具和PaddleSlim。 +[autolog](https://github.com/LDOUBLEV/AutoLog)是一个辅助工具,用户规范化打印inference的输出结果。 +autolog安装方式如下,参考文档:https://github.com/LDOUBLEV/AutoLog +``` +git clone https://github.com/LDOUBLEV/AutoLog +pip3 install -r requirements.txt +python3 setup.py bdist_wheel +pip3 install ./dist/auto_log-1.0.0-py3-none-any.whl +``` + +PaddleSlim安装方式如下,参考文档https://github.com/PaddlePaddle/PaddleSlim: +``` +pip3 install paddleslim +``` + + +#### 2.2 Linux端功能测试 +内容:分别给出5种模式下的具体测试命令。 +参考文档:https://github.com/PaddlePaddle/PaddleOCR/blob/dygraph/test_tipc/docs/test_train_inference_python.md#22-%E5%8A%9F%E8%83%BD%E6%B5%8B%E8%AF%95 +示例: + +先运行`prepare.sh`准备数据和模型,然后运行`test_train_inference_python.sh`进行测试,最终在```test_tipc/output```目录下生成`python_infer_*.log`格式的日志文件。 + + +`test_train_inference_python.sh`包含5种运行模式,每种模式的运行数据不同,分别用于测试速度和精度,分别是: + +- 模式1:lite_train_lite_infer,使用少量数据训练,用于快速验证训练到预测的走通流程,不验证精度和速度; +```shell +bash test_tipc/prepare.sh ./test_tipc/configs/ppocr_det_mobile/train_infer_python.txt 'lite_train_lite_infer' +bash test_tipc/test_train_inference_python.sh ./test_tipc/configs/ppocr_det_mobile/train_infer_python.txt 'lite_train_lite_infer' +``` + +- 模式2:lite_train_whole_infer,使用少量数据训练,一定量数据预测,用于验证训练后的模型执行预测,预测速度是否合理; +```shell +bash test_tipc/prepare.sh ./test_tipc/configs/ppocr_det_mobile/train_infer_python.txt 'lite_train_whole_infer' +bash test_tipc/test_train_inference_python.sh ../test_tipc/configs/ppocr_det_mobile/train_infer_python.txt 'lite_train_whole_infer' +``` + +- 模式3:whole_infer,不训练,全量数据预测,走通开源模型评估、动转静,检查inference model预测时间和精度; +```shell +bash test_tipc/prepare.sh ./test_tipc/configs/ppocr_det_mobile/train_infer_python.txt 'whole_infer' +# 用法1: +bash test_tipc/test_train_inference_python.sh ../test_tipc/configs/ppocr_det_mobile/train_infer_python.txt 'whole_infer' +# 用法2: 指定GPU卡预测,第三个传入参数为GPU卡号 +bash test_tipc/test_train_inference_python.sh ./test_tipc/configs/ppocr_det_mobile/train_infer_python.txt 'whole_infer' '1' +``` + +- 模式4:whole_train_whole_infer,CE: 全量数据训练,全量数据预测,验证模型训练精度,预测精度,预测速度; +```shell +bash test_tipc/prepare.sh ./test_tipc/configs/ppocr_det_mobile/train_infer_python.txt 'whole_train_whole_infer' +bash test_tipc/test_train_inference_python.sh ./test_tipc/configs/ppocr_det_mobile/train_infer_python.txt 'whole_train_whole_infer' +``` + +- 模式5:klquant_whole_infer,测试离线量化; +```shell +bash test_tipc/prepare.sh ./test_tipc/configs/ppocr_det_mobile/train_infer_python.txt 'klquant_whole_infer' +bash test_tipc/test_train_inference_python.sh ./test_tipc/configs/ppocr_det_mobile/train_infer_python.txt 'klquant_whole_infer' +``` + +运行相应指令后,在`test_tipc/output`文件夹下自动会保存运行日志。如'lite_train_lite_infer'模式下,会运行训练+inference的链条,因此,在`test_tipc/output`文件夹有以下文件: +``` +test_tipc/output/ +|- results_python.log # 运行指令状态的日志 +|- norm_train_gpus_0_autocast_null/ # GPU 0号卡上正常训练的训练日志和模型保存文件夹 +|- pact_train_gpus_0_autocast_null/ # GPU 0号卡上量化训练的训练日志和模型保存文件夹 +...... +|- python_infer_cpu_usemkldnn_True_threads_1_batchsize_1.log # CPU上开启Mkldnn线程数设置为1,测试batch_size=1条件下的预测运行日志 +|- python_infer_gpu_usetrt_True_precision_fp16_batchsize_1.log # GPU上开启TensorRT,测试batch_size=1的半精度预测日志 +...... +``` + + +#### 2.3. MAC端功能测试 + +Mac端不包含GPU,并且CPU不支持mkldnn预测,因此在Mac端无需测试tipc中关于GPU和mkldnn相关的部分。 + +为了方便Mac端功能测试,把需要测试的功能拆分为了新的参数文件`./test_tipc/configs/ppocr_det_mobile/train_mac_cpu_normal_normal_infer_python_mac_cpu.txt` + +除了修改配置文件之外,其余测试方法同2.1节的功能测试方法: + +先运行`prepare.sh`准备数据和模型,然后运行`test_train_inference_python.sh`进行测试,最终在```test_tipc/output```目录下生成`python_infer_*.log`格式的日志文件。 + +`test_train_inference_python.sh`包含5种运行模式,每种模式的运行数据不同,分别用于测试速度和精度,分别是: + +- 模式1:lite_train_lite_infer,使用少量数据训练,用于快速验证训练到预测的走通流程,不验证精度和速度; +```shell +# 同linux端运行不同的是,Mac端测试使用新的配置文件mac_ppocr_det_mobile_params.txt, +# 配置文件中默认去掉了GPU和mkldnn相关的测试链条 +bash test_tipc/prepare.sh ./test_tipc/configs/ppocr_det_mobile/train_mac_cpu_normal_normal_infer_python_mac_cpu.txt 'lite_train_lite_infer' +bash test_tipc/test_train_inference_python.sh ./test_tipc/configs/ppocr_det_mobile/train_mac_cpu_normal_normal_infer_python_mac_cpu.txt 'lite_train_lite_infer' +``` + +- 模式2:lite_train_whole_infer,使用少量数据训练,一定量数据预测,用于验证训练后的模型执行预测,预测速度是否合理; +```shell +bash test_tipc/prepare.sh ./test_tipc/configs/ppocr_det_mobile/train_mac_cpu_normal_normal_infer_python_mac_cpu.txt 'lite_train_whole_infer' +bash test_tipc/test_train_inference_python.sh ./test_tipc/configs/ppocr_det_mobile/train_mac_cpu_normal_normal_infer_python_mac_cpu.txt 'lite_train_whole_infer' +``` + +- 模式3:whole_infer,不训练,全量数据预测,走通开源模型评估、动转静,检查inference model预测时间和精度; +```shell +bash test_tipc/prepare.sh ./test_tipc/configs/ppocr_det_mobile/train_mac_cpu_normal_normal_infer_python_mac_cpu.txt 'whole_infer' +# 用法1: +bash test_tipc/test_train_inference_python.sh ./test_tipc/configs/ppocr_det_mobile/train_mac_cpu_normal_normal_infer_python_mac_cpu.txt 'whole_infer' +# 用法2: 指定GPU卡预测,第三个传入参数为GPU卡号 +bash test_tipc/test_train_inference_python.sh ./test_tipc/configs/ppocr_det_mobile/train_mac_cpu_normal_normal_infer_python_mac_cpu.txt 'whole_infer' '1' +``` + +- 模式4:whole_train_whole_infer,CE: 全量数据训练,全量数据预测,验证模型训练精度,预测精度,预测速度;(Mac端不建议运行此模式) +```shell +bash test_tipc/prepare.sh ./test_tipc/configs/ppocr_det_mobile/train_mac_cpu_normal_normal_infer_python_mac_cpu.txt 'whole_train_whole_infer' +bash test_tipc/test_train_inference_python.sh ./test_tipc/configs/ppocr_det_mobile/train_mac_cpu_normal_normal_infer_python_mac_cpu.txt 'whole_train_whole_infer' +``` + +- 模式5:klquant_whole_infer,测试离线量化; +```shell +bash test_tipc/prepare.sh ./test_tipc/ppocr_det_mobile/train_mac_cpu_normal_normal_infer_python_mac_cpu.txt 'klquant_whole_infer' +bash test_tipc/test_train_inference_python.sh test_tipc/configs/ppocr_det_mobile/train_mac_cpu_normal_normal_infer_python_mac_cpu.txt 'klquant_whole_infer' +``` + + +#### 2.4 Windows端功能测试 + +windows端的功能测试同Linux端,为了方便区分Windows端功能测试,把需要测试的功能拆分为了新的参数文件`./test_tipc/configs/ppocr_det_mobile/train_windows_gpu_normal_normal_infer_python_windows_cpu_gpu.txt` + +除了修改配置文件之外,其余测试方法同2.1节的功能测试方法。 + +先运行`prepare.sh`准备数据和模型,然后运行`test_train_inference_python.sh`进行测试,最终在```test_tipc/output```目录下生成`python_infer_*.log`格式的日志文件。 + +`test_train_inference_python.sh`包含5种运行模式,每种模式的运行数据不同,分别用于测试速度和精度,分别是: + +- 模式1:lite_train_lite_infer,使用少量数据训练,用于快速验证训练到预测的走通流程,不验证精度和速度; +```shell +bash test_tipc/prepare.sh ./test_tipc/configs/ppocr_det_mobile/train_windows_gpu_normal_normal_infer_python_windows_cpu_gpu.txt 'lite_train_lite_infer' +bash test_tipc/test_train_inference_python.sh ./test_tipc/configs/ppocr_det_mobile/train_windows_gpu_normal_normal_infer_python_windows_cpu_gpu.txt 'lite_train_lite_infer' +``` + +- 模式2:lite_train_whole_infer,使用少量数据训练,一定量数据预测,用于验证训练后的模型执行预测,预测速度是否合理; +```shell +bash test_tipc/prepare.sh ./test_tipc/configs/ppocr_det_mobile/train_windows_gpu_normal_normal_infer_python_windows_cpu_gpu.txt 'lite_train_whole_infer' +bash test_tipc/test_train_inference_python.sh ./test_tipc/configs/ppocr_det_mobile/train_windows_gpu_normal_normal_infer_python_windows_cpu_gpu.txt 'lite_train_whole_infer' +``` + +- 模式3:whole_infer,不训练,全量数据预测,走通开源模型评估、动转静,检查inference model预测时间和精度; +```shell +bash test_tipc/prepare.sh ./test_tipc/configs/ppocr_det_mobile/train_windows_gpu_normal_normal_infer_python_windows_cpu_gpu.txt 'whole_infer' +# 用法1: +bash test_tipc/test_train_inference_python.sh ./test_tipc/configs/ppocr_det_mobile/train_windows_gpu_normal_normal_infer_python_windows_cpu_gpu.txt 'whole_infer' +# 用法2: 指定GPU卡预测,第三个传入参数为GPU卡号 +bash test_tipc/test_train_inference_python.sh ./test_tipc/configs/ppocr_det_mobile/train_windows_gpu_normal_normal_infer_python_windows_cpu_gpu.txt 'whole_infer' '1' +``` + +- 模式4:whole_train_whole_infer,CE: 全量数据训练,全量数据预测,验证模型训练精度,预测精度,预测速度; +```shell +bash test_tipc/prepare.sh ./test_tipc/configs/ppocr_det_mobile/train_windows_gpu_normal_normal_infer_python_windows_cpu_gpu.txt 'whole_train_whole_infer' +bash test_tipc/test_train_inference_python.sh ./test_tipc/configs/ppocr_det_mobile/train_windows_gpu_normal_normal_infer_python_windows_cpu_gpu.txt 'whole_train_whole_infer' +``` + +- 模式5:klquant_whole_infer,测试离线量化; +```shell +bash test_tipc/prepare.sh ./test_tipc/configs/ppocr_det_mobile/train_windows_gpu_normal_normal_infer_python_windows_cpu_gpu.txt 'klquant_whole_infer' +bash test_tipc/test_train_inference_python.sh test_tipc/configs/ppocr_det_mobile/train_windows_gpu_normal_normal_infer_python_windows_cpu_gpu.txt 'klquant_whole_infer' +``` + +#### 2.5 Jeston端功能测试 + +Jeston产品是Nvidia推出的开发者套件,用于部署AI模型。Jeston系列的产品有Jeston Nano, TX,NX等等。本节以PaddleOCR检测模型和JestonNX为例,介绍如何在Jeston上接入TIPC预测推理的测试。 + +Jeston的CPU性能远差于笔记本或者台式机,因此在Jeston上,只需要测试GPU上预测相关的链条即可,包括GPU预测,GPU+TensorRT(fp32),GPU+TensorRT(fp16)预测。 + +Jeston上无需测试TIPC训练部分,仅需要测试预测推理部分即可,因此,仅需要测试inferenc部分。 +jeston 的测试脚本为`test_inference_jeston.sh`,测试方法如下: + +- 模式3:whole_infer,不训练,全量数据预测,走通开源模型评估、动转静,检查inference model预测时间和精度; +```shell +bash test_tipc/prepare.sh ./test_tipc/configs/ppocr_det_mobile/model_linux_gpu_normal_normal_infer_python_jetson.txt 'whole_infer' +# 用法1: +bash test_tipc/test_inference_jeston.sh ./test_tipc/configs/ppocr_det_mobile/model_linux_gpu_normal_normal_infer_python_jetson.txt 'whole_infer' +``` + + +#### 2.6 精度测试 + +使用compare_results.py脚本比较模型预测的结果是否符合预期,主要步骤包括: +- 提取日志中的预测坐标; +- 从本地文件中提取保存好的坐标结果; +- 比较上述两个结果是否符合精度预期,误差大于设置阈值时会报错。 + +运行命令: +```shell +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: 设置的相对误差 + +运行结果: +正常运行效果如下: +``` +Assert allclose passed! The results of python_infer_cpu_usemkldnn_False_threads_1_batchsize_1.log and ./test_tipc/results/python_ppocr_det_mobile_results_fp32.txt are consistent! +``` + +出现不一致结果时的运行输出: +``` +...... +Traceback (most recent call last): + File "test_tipc/compare_results.py", line 140, in + format(filename, gt_filename)) +ValueError: The results of python_infer_cpu_usemkldnn_False_threads_1_batchsize_1.log and the results of ./test_tipc/results/python_ppocr_det_mobile_results_fp32.txt are inconsistent! +``` + + + + +