PaddleOCR Windows 端 TIPC 基础训练预测功能测试完整指南 PaddleOCR Windows 端 TIPC 基础训练预测功能测试完整指南【免费下载链接】PaddleOCRTurn any PDF or image document into structured data for your AI. A powerful, lightweight OCR toolkit that bridges the gap between images/PDFs and LLMs. Supports 100 languages.项目地址: https://gitcode.com/GitHub_Trending/pa/PaddleOCR本篇指南围绕 PaddleOCR 仓库中的test_tipc自动化测试体系系统讲解如何在 Windows 环境下运行基于 Python 的训练、评估、动转静导出与推理的全链路功能测试覆盖正常训练、混合精度AMP、FPGM 裁剪与 PACT 量化等模型压缩场景。读完本文你将掌握test_tipc/prepare.sh与test_tipc/test_train_inference_python.sh的四种运行模式、Windows 专用配置文件的结构与参数语义、日志产物解读方法以及基于compare_results.py的预测精度校验手段。1. 测试体系定位与覆盖范围Windows 端基础训练预测功能测试的主程序为 test_train_inference_python.sh它与 Linux 端共用同一套测试脚本只是通过不同后缀的配置文件区分平台特性。该脚本可以完整测试基于 Python 的模型训练、评估、推理等基本功能并覆盖三种模型压缩手段裁剪Pruning基于 FPGM 算法的结构化裁剪量化Quantization基于 PACT 的在线量化蒸馏Distillation教师-学生模型蒸馏训练。在 Windows 上由于路径管理方式与 Linux 不同官方推荐安装 Git Bash 终端可通过 Git 官方渠道下载 Windows 版安装包在 Git Bash 中执行指令的方式与 Linux 端一致可以最大程度复用 TIPC 测试脚本避免 Windows CMD/PowerShell 与 bash 语法差异带来的额外适配成本。2. 测试结论汇总2.1 训练相关结论Windows 端当前已覆盖 DB 检测算法的训练链路具体支持情况如下算法名称模型名称单机单卡单机多卡多机多卡模型压缩单机多卡DBch_ppocr_mobile_v2_0_det正常训练混合精度--正常训练FPGM裁剪、PACT量化从表中可以看出Windows 端以单机单卡为主要测试形态支持混合精度训练AMP对应配置文件中的Global.auto_cast: fp32|amp并可通过ch_ppocr_mobile_v2_0_det_KL、ch_ppocr_mobile_v2_0_det_PACT、ch_ppocr_mobile_v2_0_det_FPGM等后缀配置验证模型压缩链路相关配置位于 test_tipc/configs/ch_ppocr_mobile_v2_0_det/ 与 test_tipc/configs/ch_ppocr_mobile_v2_0_det_KL/ 目录。2.2 预测相关结论基于训练时是否使用量化训练产出的模型可分为正常模型和量化模型两类两者的预测功能覆盖矩阵如下模型类型devicebatchsizetensorrtmkldnncpu多线程正常模型GPU1/6fp32/fp16--正常模型CPU1/6-fp32/fp16支持量化模型GPU1/6int8--量化模型CPU1/6-int8支持这份矩阵与 test_train_inference_python.sh 中func_inference函数的循环逻辑一一对应CPU 分支遍历enable_mkldnn、cpu_threads、batch_size、precision四个维度的笛卡尔积脚本中会跳过「关闭 Mkldnn 却开启 fp16」「量化模型却非 int8 精度」等非法组合GPU 分支则遍历use_tensorrt与precision的组合并跳过「正常模型配 int8」「关闭 TensorRT 却要求 fp16/int8」等无意义组合。3. 测试流程从环境准备到一键运行3.1 运行环境配置TIPC 运行环境的完整搭建方式请参考 test_tipc/docs/install.md其推荐环境组合包括CUDA 10.1/10.2CUDNN 7.6/cudnn8.1TensorRT 6.1.0.5 / 7.1 / 7.2PaddlePaddle 2.3。环境搭建支持两种路径一是使用nvidia-docker拉起paddlepaddle/paddle:latest-dev-cuda10.1-cudnn7-gcc82镜像并安装带 TensorRT 的 Paddle 预编译 wheel 包二是在本地按「CUDA CUDNN TensorRT PaddlePaddle」组合手动配置。若本地 Paddle 为带 TRT 的版本但找不到 TensorRT 动态库可通过设置LD_LIBRARY_PATH指向解压后的 TensorRT lib 目录解决。3.2 安装依赖在进入功能测试前需要依次安装以下依赖安装 PaddlePaddle 2.3按 requirements.txt 对应平台选择安装方式安装 PaddleOCR 依赖pip install -r ../requirements.txt安装 autolog规范化日志输出工具TIPC 推理日志的解析依赖该工具输出规范化的 benchmark 结果pip install https://paddleocr.bj.bcebos.com/libs/auto_log-1.2.0-py3-none-any.whl安装 PaddleSlim可选# 如果要测试量化、裁剪等功能需要安装PaddleSlim pip install paddleslim值得注意的是prepare.sh在lite_train_lite_infer与whole_infer模式下会自动完成上述依赖安装见 prepare.sh 与 prepare.sh因此在完整走一遍 prepare → test 流程时依赖会被自动补齐手动单步执行时则需先自行安装。3.3 功能测试的两步式流程功能测试遵循「先准备、后测试」的两步式流程先运行prepare.sh准备数据和模型下载预训练权重、解压测试数据集并建立软链接再运行test_train_inference_python.sh执行实际测试最终在test_tipc/output目录下生成model_name/lite_train_lite_infer/*.log格式的日志文件。Windows 端以ch_ppocr_mobile_v2_0_det为例其平台专用配置文件为 test_tipc/configs/ch_ppocr_mobile_v2_0_det/train_windows_gpu_normal_normal_infer_python_windows_cpu_gpu.txt文件名语义可拆解为Windows 平台、GPU 正常训练、Python 推理、CPU/GPU 双端覆盖。4. 功能测试的四种运行模式test_train_inference_python.sh包含基础链条的 4 种运行模式每种模式使用的数据量与目标不同分别用于测试「流程走通」「预测速度」「预测精度」等维度模式 1lite_train_lite_infer少量训练 少量预测使用少量数据训练用于快速验证「训练 → 动转静导出 → 预测」整条链路能否走通不验证精度和速度bash test_tipc/prepare.sh ./test_tipc/configs/ch_ppocr_mobile_v2_0_det/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/ch_ppocr_mobile_v2_0_det/train_windows_gpu_normal_normal_infer_python_windows_cpu_gpu.txt lite_train_lite_infer在该模式下prepare.sh会下载icdar2015_lite.tar等精简数据集并用rec_gt_train_lite.txt/rec_gt_test_lite.txt替换完整标注使训练在几分钟内即可完成一轮验证见 prepare.sh。模式 2lite_train_whole_infer少量训练 全量预测使用少量数据训练、一定量数据预测用于验证训练后的模型执行预测时预测速度是否合理bash test_tipc/prepare.sh ./test_tipc/configs/ch_ppocr_mobile_v2_0_det/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/ch_ppocr_mobile_v2_0_det/train_windows_gpu_normal_normal_infer_python_windows_cpu_gpu.txt lite_train_whole_infer模式 3whole_infer不训练仅全量预测不训练直接使用全量数据预测走通开源模型评估、动转静动态图转静态图导出检查 inference model 的预测时间和精度bash test_tipc/prepare.sh ./test_tipc/configs/ch_ppocr_mobile_v2_0_det/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/ch_ppocr_mobile_v2_0_det/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/ch_ppocr_mobile_v2_0_det/train_windows_gpu_normal_normal_infer_python_windows_cpu_gpu.txt whole_infer 1该模式的第三个可选参数为 GPU 卡号脚本内部会据此设置CUDA_VISIBLE_DEVICES见 test_train_inference_python.sh。在此模式下prepare.sh会下载开源检测模型ch_ppocr_mobile_v2.0_det_train与 50 张测试图片ch_det_data_50先执行tools/export_model.py完成动转静再对导出模型做批量预测。模式 4whole_train_whole_infer全量训练 全量预测CE 模式全量数据训练、全量数据预测用于验证模型训练精度、预测精度与预测速度是接近真实发布质量的回归测试CEContinuous Evaluationbash test_tipc/prepare.sh ./test_tipc/configs/ch_ppocr_mobile_v2_0_det/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/ch_ppocr_mobile_v2_0_det/train_windows_gpu_normal_normal_infer_python_windows_cpu_gpu.txt whole_train_whole_infer四种模式之间通过脚本第二个参数MODE区分脚本头部的注释明确给出了合法取值集合[lite_train_lite_infer lite_train_whole_infer whole_train_whole_infer, whole_infer]见 test_train_inference_python.sh不同模式下配置文件中的Global.epoch_num、Train.loader.batch_size_per_card等参数会通过func_parser_params按模式取出对应值。5. Windows 配置文件结构与参数语义以 train_windows_gpu_normal_normal_infer_python_windows_cpu_gpu.txt 为例配置文件按train_params、eval_params、infer_params三大区块组织每行以key:value形式声明脚本通过 common_func.sh 中的func_parser_key/func_parser_value/func_parser_params按固定行号解析。5.1 训练参数区块行内容参数名语义model_name:ocr_detmodel_name模型标识用于组织输出目录python:pythonpythonPython 解释器命令gpu_list:0gpu_listGPU 卡号列表-1表示 CPUGlobal.use_gpu:Truetrain_use_gpu训练是否使用 GPUGlobal.auto_cast:fp32\|ampautocast精度模式支持 fp32 与混合精度 ampGlobal.epoch_num:lite_train_lite_infer5\|whole_train_whole_infer50epoch_num按模式区分的训练轮数Global.save_model_dir:./output/save_model_key模型保存目录Train.loader.batch_size_per_card:lite_train_lite_infer2\|whole_train_whole_infer4train_batch按模式区分的单卡 batch sizeGlobal.pretrained_model:nullpretrain_model预训练模型路径null 表示不使用train_model_name:latesttrain_model_name训练产出的模型文件名train_infer_img_dir:./train_data/icdar2015/text_localization/ch4_test_images/train_infer_img_dir训练后推理使用的测试图片目录trainer:norm_traintrainer_list训练器列表可扩展 pact/fpgm/distillnorm_train:tools/train.py -c configs/det/ch_ppocr_v2.0/ch_det_mv3_db_v2.0.yml -o Global.pretrained_model./pretrain_models/MobileNetV3_large_x0_5_pretrainednorm_trainer正常训练的完整命令模板其中trainer一行是脚本选择训练器的关键脚本会将trainer_list中的值与pact_key、fpgm_key、distill_key逐一比对命中后切换到对应的pact_trainer/fpgm_trainer/distill_trainer并同步切换导出命令见 test_train_inference_python.sh。当Global.auto_cast取值为amp时脚本会追加Global.use_ampTrue Global.scale_loss1024.0 Global.use_dynamic_loss_scalingTrue三个混合精度配置项见 test_train_inference_python.sh。5.2 推理参数区块行内容参数名语义--use_gpu:True\|Falseuse_gpu_listGPU/CPU 双端推理开关--enable_mkldnn:Falseuse_mkldnn_list是否启用 MkldnnCPU 加速--cpu_threads:1\|6cpu_threads_listCPU 线程数取值集合--use_tensorrt:Falseuse_trt_list是否启用 TensorRT--precision:fp32\|fp16\|int8precision_list推理精度取值集合--det_model_dir:infer_model_key检测模型目录由脚本动态填充--image_dir:./inference/ch_det_data_50/all-sum-510/infer_img_dir推理测试图片目录--benchmark:Truebenchmark_key是否输出 benchmark 性能数据norm_export:tools/export_model.py -c configs/det/ch_ppocr_v2.0/ch_det_mv3_db_v2.0.yml -onorm_export动转静导出命令模板infer_export:tools/export_model.py -c configs/det/ch_ppocr_v2.0/ch_det_mv3_db_v2.0.yml -oinfer_export_listwhole_infer 模式下的导出命令infer_quant:Falseinfer_is_quant推理模型是否为量化模型脚本的func_inference函数会依据这些取值集合做多层嵌套循环CPU 端遍历use_mkldnn × cpu_threads × batch_size × precisionGPU 端遍历use_tensorrt × precision × batch_size每条组合命令的日志以python_infer_cpu_gpus_{gpu}_usemkldnn_{mkldnn}_threads_{threads}_precision_{precision}_batchsize_{batch}.log/python_infer_gpu_gpus_{gpu}_usetrt_{trt}_precision_{precision}_batchsize_{batch}.log命名落盘到test_tipc/output下见 test_train_inference_python.sh 与 test_train_inference_python.sh。6. 运行日志产物与结果判定运行相应指令后test_tipc/output文件夹下会自动保存运行日志。以lite_train_lite_infer模式为例会运行完整的「训练 动转静导出 推理」链条目录结构如下test_tipc/output/model_name/lite_train_lite_infer/ |- results_python.log # 运行指令状态的日志 |- norm_train_gpus_0_autocast_null/ # GPU 0号卡上正常训练的训练日志和模型保存文件夹 ...... |- python_infer_cpu_usemkldnn_False_threads_6_precision_fp32_batchsize_1.log # CPU上关闭Mkldnn线程数设置为6测试batch_size1条件下的fp32精度预测运行日志 |- python_infer_gpu_usetrt_False_precision_fp32_batchsize_1.log # GPU上关闭TensorRT测试batch_size1的fp32精度预测日志 ......其中results_python.log汇总了每一条指令的运行状态其写入逻辑位于脚本的status_check辅助函数见 common_func.sh退出码为 0 时追加成功记录否则追加失败记录。如果运行成功results_python.log中会输出Run successfully with command - python3.7 tools/train.py -c tests/configs/det_mv3_db.yml -o Global.pretrained_model./pretrain_models/MobileNetV3_large_x0_5_pretrained Global.use_gpuTrue Global.save_model_dir./tests/output/norm_train_gpus_0_autocast_null Global.epoch_num1 Train.loader.batch_size_per_card2 ! Run successfully with command - python3.7 tools/export_model.py -c tests/configs/det_mv3_db.yml -o Global.pretrained_model./tests/output/norm_train_gpus_0_autocast_null/latest Global.save_inference_dir./tests/output/norm_train_gpus_0_autocast_null! ......如果运行失败会输出Run failed with command - python3.7 tools/train.py -c tests/configs/det_mv3_db.yml -o Global.pretrained_model./pretrain_models/MobileNetV3_large_x0_5_pretrained Global.use_gpuTrue Global.save_model_dir./tests/output/norm_train_gpus_0_autocast_null Global.epoch_num1 Train.loader.batch_size_per_card2 ! Run failed with command - python3.7 tools/export_model.py -c tests/configs/det_mv3_db.yml -o Global.pretrained_model./tests/output/norm_train_gpus_0_autocast_null/latest Global.save_inference_dir./tests/output/norm_train_gpus_0_autocast_null! ......每条记录中完整保留了实际执行的命令字符串因此可以很方便地根据results_python.log定位是哪一条指令运行出错将失败命令复制到终端单独执行即可复现与排查问题。7. 精度测试compare_results.py功能测试只保证流程走通预测结果是否符合数值预期则由精度测试环节把关。7.1 原理与步骤compare_results.py 的校验逻辑分为三步见 compare_results.py提取日志中的预测坐标通过grep从推理日志中匹配检测结果关键字解析出文本框坐标每个坐标点被解析为N×4的数组或 JSON 形式的预测结果从本地文件提取保存好的坐标结果读取test_tipc/results/下的基准结果 txt 文件按fp32/fp16/int8精度关键词分类索引见 compare_results.py比较两者是否符合精度预期对每个样本调用np.testing.assert_allclose误差大于设置阈值时抛出异常并报错见 compare_results.py。7.2 使用方式运行命令python test_tipc/compare_results.py --gt_file./test_tipc/results/python_*.txt --log_file./test_tipc/output/python_*.log --atol1e-3 --rtol1e-3参数介绍gt_file指向事先保存好的预测结果路径支持*.txt结尾脚本会自动通过 glob 索引全部匹配的 txt 文件基准结果默认保存在test_tipc/results/文件夹下仓库中已预置 python_ppocr_det_mobile_results_fp32.txt 与 python_ppocr_det_mobile_results_fp16.txt 两组基准log_file指向运行test_tipc/test_train_inference_python.sh脚本的 infer 模式保存的预测日志日志中打印有预测结果文本框、预测文本、类别等同样支持python_infer_*.log格式传入atol设置的绝对误差默认 1e-3rtol设置的相对误差默认 1e-3。7.3 运行结果判定正常运行效果如下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 module 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!从源码实现看assert_allclose会对同一图片名下的坐标数组逐元素比较绝对误差与相对误差容差由atol/rtol控制任一元素超差即触发ValueError。因此当某个精度档位如 fp16 或 int8出现不一致时通常意味着该精度下的数值稳定度不达标需要进一步排查模型转换或推理配置。8. 测试脚本工作机制源码级解读理解脚本内部机制有助于在 Windows 上排查路径与参数问题参数解析test_train_inference_python.sh通过awk NR1{print} $FILENAME将配置文件按行读入数组随后按固定行号提取训练、评估、导出、推理四类参数见 test_train_inference_python.sh。func_parser_key与func_parser_value以冒号切分键值对func_parser_params则支持modevalue1|mode2value2这种按运行模式取值的语法。训练器分发trainer_list决定本轮跑哪些训练器脚本依次比对pact、fpgm、distill、to_static等关键字命中后替换为对应的训练命令与导出命令若对应训练器为null则直接跳过见 test_train_inference_python.sh。分布式与混合精度GPU 列表长度决定训练方式——单卡直接执行训练脚本多卡通过python -m paddle.distributed.launch --gpus...拉起多机则追加--ips...参数amp 模式下自动注入Global.use_amp等混合精度开关见 test_train_inference_python.sh。whole_infer 模式该模式跳过训练直接对train_model指定的开源模型执行导出与推理infer_export非空时先执行tools/export_model.py动转静再调用tools/infer/predict_det.py做批量预测见 test_train_inference_python.sh。数据准备prepare.sh 按 MODE 分支下载对应数据集——lite_train_lite_infer下载精简版icdar2015_lite并建立icdar2015软链接whole_infer下载ch_det_data_50测试图片与ch_ppocr_mobile_v2.0_det_train模型包whole_train_whole_infer则下载全量icdar2015.tar。各分支还针对不同模型det/rec/table/kie准备了对应的预训练权重与数据集覆盖 DB、CRNN、SLANet、LayoutXLM 等多个算法族。9. 进阶参考本文档定位为 Windows 端功能测试指南更丰富的训练与预测使用教程可继续深入仓库内以下入口训练入口与参数体系tools/train.py 与 tools/program.py动转静导出tools/export_model.pyPython 预测引擎tools/infer/predict_det.py 及 tools/infer 目录下的分类/识别/表格等预测脚本对应算法配置configs/det/ch_ppocr_v2.0/ch_det_mv3_db_v2.0.ymlLinux 端对应文档test_tipc/docs/test_train_inference_python.md可用于对比两平台测试配置的差异。【免费下载链接】PaddleOCRTurn any PDF or image document into structured data for your AI. A powerful, lightweight OCR toolkit that bridges the gap between images/PDFs and LLMs. Supports 100 languages.项目地址: https://gitcode.com/GitHub_Trending/pa/PaddleOCR创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考