PaddleOCR PP-StructureV3:文档结构化解析流水线的技术解析与基准实测
【免费下载链接】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 仓库中 PP-StructureV3 算法文档,系统梳理该文档解析流水线的定位与能力边界(版面检测、表格/公式/印章/图表识别、阅读顺序恢复、Markdown 输出),完整呈现其在 OmniDocBench 上的精度对比、V100/A100 上的端到端时延与资源占用实测数据,并结合 流水线包装类源码 解析其参数体系与调用链路。读完后你将能够:根据硬件条件选择合适模型配置、理解各use_*开关与检测参数的含义、通过 CLI 或 Python API 实际运行该流水线并做二次开发。
1. PP-StructureV3 是什么:在 Layout Parsing v1 基础上的能力增强
PP-StructureV3 是基于 Layout Parsing v1(布局解析)流水线的增强版本,核心提升集中在以下几个方面:
- 版面区域检测(Layout Detection)能力增强:默认的版面检测模型
PP-DocLayout-L覆盖文档标题、段落标题、文本、页码、摘要、表格、参考文献、脚注、页眉页脚、算法、公式、公式编号、图像、图题、表题、印章、图、侧栏文本等 20 个常见类别;同时提供单类 Block 区块检测模型PP-DocBlockLayout(region detection)用于阅读顺序恢复; - 表格识别增强:内置有/无线表格结构识别(SLANeXt_wired / SLANeXt_wireless)、表格分类(PP-LCNet_x1_0_table_cls)、表格单元格检测(RT-DETR-L_wired/wireless_table_cell_det)等模型;
- 公式识别增强:默认使用 PP-FormulaNet-L 等 PP-FormulaNet 系列模型;
- 新增图表理解能力:通过 PP-Chart2Table 多模态模型将图表解析为表格;
- 新增多栏阅读顺序恢复能力;
- 结果可直接转换为 Markdown 文件,面向文档数字化与 LLM 数据接入场景。
该流水线同样支持灵活的服务化部署(多语言客户端、多种硬件),并且支持二次开发:每个子模块/子流水线可独立训练与推理,基于自有数据集训练或微调后的模型可以无缝集成回流水线。其模块构成在 使用文档 中描述为 7 个可独立训练的模块/子流水线:
| 模块 | 是否必需 | 默认模型示例 |
|---|---|---|
| 文档图像预处理子流水线(DocPreprocessor) | 可选 | 方向分类 PP-LCNet_x1_0_doc_ori、矫正 UVDoc |
| 版面检测模块(Layout Detection) | 必需 | PP-DocLayout-L |
| 通用 OCR 子流水线(GeneralOCR) | 必需 | PP-OCRv5_server_det / PP-OCRv5_server_rec |
| 表格识别子流水线(Table Recognition) | 可选 | SLANeXt_wired/wireless + RT-DETR-L 单元格检测 |
| 印章文本识别子流水线(Seal Recognition) | 可选 | PP-OCRv4_server/mobile_seal_det |
| 公式识别子流水线(Formula Recognition) | 可选 | PP-FormulaNet-L |
| 图表解析模块(Chart Parsing) | 可选 | PP-Chart2Table |
各子模块的模型清单与指标详见 PP-StructureV3 使用文档 与 中文版算法文档。
2. OmniDocBench 关键指标:与主流文档解析工具及 VLM 的精度对比
算法文档给出了一组基于OmniDocBench(面向多样化 PDF 文档解析的综合标注基准)的端到端精度数据。指标为 Edit 编辑距离,数值越低越好,分 Overall(整体)、Text(文本)、Formula(公式)、Table(表格)、Read Order(阅读顺序)五个维度,且每个维度区分中英文(EN/ZH)。
| 方法类型 | 方法 | Overall EN | Overall ZH | Text EN | Text ZH | Formula EN | Formula ZH | Table EN | Table ZH | Read Order EN | Read Order ZH |
|---|---|---|---|---|---|---|---|---|---|---|---|
| Pipeline Tools | PP-StructureV3 | 0.145 | 0.206 | 0.058 | 0.088 | 0.295 | 0.535 | 0.159 | 0.109 | 0.069 | 0.091 |
| Pipeline Tools | MinerU-0.9.3 | 0.15 | 0.357 | 0.061 | 0.215 | 0.278 | 0.577 | 0.18 | 0.344 | 0.079 | 0.292 |
| Pipeline Tools | MinerU-1.3.11 | 0.166 | 0.310 | 0.0826 | 0.2000 | 0.3368 | 0.6236 | 0.1613 | 0.1833 | 0.0834 | 0.2316 |
| Pipeline Tools | Marker-1.2.3 | 0.336 | 0.556 | 0.08 | 0.315 | 0.53 | 0.883 | 0.619 | 0.685 | 0.114 | 0.34 |
| Pipeline Tools | Mathpix | 0.191 | 0.365 | 0.105 | 0.384 | 0.306 | 0.454 | 0.243 | 0.32 | 0.108 | 0.304 |
| Pipeline Tools | Docling-2.14.0 | 0.589 | 0.909 | 0.416 | 0.987 | 0.999 | 1 | 0.627 | 0.81 | 0.313 | 0.837 |
| Pipeline Tools | Pix2Text-1.1.2.3 | 0.32 | 0.528 | 0.138 | 0.356 | 0.276 | 0.611 | 0.584 | 0.645 | 0.281 | 0.499 |
| Pipeline Tools | Unstructured-0.17.2 | 0.586 | 0.716 | 0.198 | 0.481 | 0.999 | 1 | 1 | 0.998 | 0.145 | 0.387 |
| Pipeline Tools | OpenParse-0.7.0 | 0.646 | 0.814 | 0.681 | 0.974 | 0.996 | 1 | 0.284 | 0.639 | 0.595 | 0.641 |
| Expert VLMs | GOT-OCR | 0.287 | 0.411 | 0.189 | 0.315 | 0.36 | 0.528 | 0.459 | 0.52 | 0.141 | 0.28 |
| Expert VLMs | Nougat | 0.452 | 0.973 | 0.365 | 0.998 | 0.488 | 0.941 | 0.572 | 1 | 0.382 | 0.954 |
| Expert VLMs | Mistral OCR | 0.268 | 0.439 | 0.072 | 0.325 | 0.318 | 0.495 | 0.6 | 0.65 | 0.083 | 0.284 |
| Expert VLMs | OLMOCR-sglang | 0.326 | 0.469 | 0.097 | 0.293 | 0.455 | 0.655 | 0.608 | 0.652 | 0.145 | 0.277 |
| Expert VLMs | SmolDocling-256M_transformer | 0.493 | 0.816 | 0.262 | 0.838 | 0.753 | 0.997 | 0.729 | 0.907 | 0.227 | 0.522 |
| General VLMs | Gemini2.0-flash | 0.191 | 0.264 | 0.091 | 0.139 | 0.389 | 0.584 | 0.193 | 0.206 | 0.092 | 0.128 |
| General VLMs | Gemini2.5-Pro | 0.148 | 0.212 | 0.055 | 0.168 | 0.356 | 0.439 | 0.13 | 0.119 | 0.049 | 0.121 |
| General VLMs | GPT4o | 0.233 | 0.399 | 0.144 | 0.409 | 0.425 | 0.606 | 0.234 | 0.329 | 0.128 | 0.251 |
| General VLMs | Qwen2-VL-72B | 0.252 | 0.327 | 0.096 | 0.218 | 0.404 | 0.487 | 0.387 | 0.408 | 0.119 | 0.193 |
| General VLMs | Qwen2.5-VL-72B | 0.214 | 0.261 | 0.092 | 0.18 | 0.315 | 0.434 | 0.341 | 0.262 | 0.106 | 0.168 |
| General VLMs | InternVL2-76B | 0.44 | 0.443 | 0.353 | 0.29 | 0.543 | 0.701 | 0.547 | 0.555 | 0.317 | 0.228 |
从表格结构看,官方将对比对象分为三类:流水线工具(Pipeline Tools)、专家 VLM(Expert VLMs,如 GOT-OCR、Nougat、Mistral OCR)、通用 VLM(General VLMs,如 Gemini、GPT4o、Qwen2.5-VL)。加粗值为各自最优。可以观察到的事实性结论:
- PP-StructureV3 在Pipeline Tools类别中 Overall(EN/ZH)、Text(ZH)、Table(ZH)、Read Order(EN/ZH)取得最低 Edit 距离;
- 在公式(Formula ZH)单项上,Pix2Text-1.1.2.3(0.276)与 Qwen2.5-VL-72B(0.434,通用 VLM 类最优)优于 PP-StructureV3 的 0.535,说明公式识别是该场景下仍有明显差距的维度,选型时若公式密集可优先考虑更强的公式模型或 VLM 方案;
- 相比同类的 MinerU-1.3.11,PP-StructureV3 在中文 Overall 上从 0.310 降到 0.206,阅读顺序指标差距尤为显著(EN 0.069 vs 0.0834,ZH 0.091 vs 0.2316),与文档"阅读顺序恢复"能力增强的描述相互印证。
3. 端到端 Benchmark:时延、资源占用与服务化并发
端到端测试的依赖环境为:Paddle 3.0、PaddleOCR 3.0.0、MinerU 1.3.10、CUDA 11.8、cuDNN 8.9。测试数据为 15 个 PDF 文件共 925 页,包含表格、公式、印章、图表等元素。
3.1 本地推理:NVIDIA Tesla V100 + Intel Xeon Gold 6271C
PP-StructureV3 在 6 种"OCR 模型 × 公式识别模型 × 图表识别 × 文本检测max_side_limit"配置下的实测表现如下(OCR 模型分为 Server / Mobile 两档,详见 PP-OCRv5 算法文档;公式模型细节见 公式识别文档;文本检测模块的侧长限制参数见 文本检测文档):
| 方法 | OCR 模型 | 公式识别模型 | 图表识别模型 | 文本检测 max_side_limit | 每页平均耗时 (s) | 平均 CPU (%) | 峰值内存 (GB) | 平均内存 (GB) | 平均 GPU (%) | 峰值显存 (GB) | 平均显存 (GB) |
|---|---|---|---|---|---|---|---|---|---|---|---|
| PP-StructureV3 | Server | PP-FormulaNet-L | 关 | 4096 | 1.77 | 111.4 | 6.7 | 5.2 | 38.9 | 17.0 | 16.5 |
| PP-StructureV3 | Server | PP-FormulaNet-L | 开 | 4096 | 4.09 | 105.3 | 5.5 | 4.0 | 24.7 | 17.0 | 16.6 |
| PP-StructureV3 | Mobile | PP-FormulaNet-L | 关 | 4096 | 1.56 | 113.7 | 6.6 | 4.9 | 29.1 | 10.7 | 10.6 |
| PP-StructureV3 | Server | PP-FormulaNet-M | 关 | 4096 | 1.42 | 112.9 | 6.8 | 5.1 | 38 | 16.0 | 15.5 |
| PP-StructureV3 | Mobile | PP-FormulaNet-M | 关 | 4096 | 1.15 | 114.8 | 6.5 | 5.0 | 26.1 | 8.4 | 8.3 |
| PP-StructureV3 | Mobile | PP-FormulaNet-M | 关 | 1200 | 0.99 | 113 | 7.0 | 5.6 | 29.2 | 8.6 | 8.5 |
| MinerU | - | - | - | - | 1.57 | 142.9 | 13.3 | 11.8 | 43.3 | 31.6 | 9.7 |
3.2 本地推理:NVIDIA A100 + Intel Xeon Platinum 8350C
| 方法 | OCR 模型 | 公式识别模型 | 图表识别模型 | 文本检测 max_side_limit | 每页平均耗时 (s) | 平均 CPU (%) | 峰值内存 (GB) | 平均内存 (GB) | 平均 GPU (%) | 峰值显存 (GB) | 平均显存 (GB) |
|---|---|---|---|---|---|---|---|---|---|---|---|
| PP-StructureV3 | Server | PP-FormulaNet-L | 关 | 4096 | 1.12 | 109.8 | 9.2 | 7.8 | 29.8 | 21.8 | 21.1 |
| PP-StructureV3 | Server | PP-FormulaNet-L | 开 | 4096 | 2.76 | 103.7 | 9.0 | 7.7 | 24 | 21.8 | 21.1 |
| PP-StructureV3 | Mobile | PP-FormulaNet-L | 关 | 4096 | 1.04 | 110.7 | 9.3 | 7.8 | 22 | 12.2 | 12.1 |
| PP-StructureV3 | Server | PP-FormulaNet-M | 关 | 4096 | 0.95 | 111.4 | 9.1 | 7.8 | 28.1 | 21.8 | 21.0 |
| PP-StructureV3 | Mobile | PP-FormulaNet-M | 关 | 4096 | 0.89 | 112.1 | 9.2 | 7.8 | 18.5 | 11.4 | 11.2 |
| PP-StructureV3 | Mobile | PP-FormulaNet-M | 关 | 1200 | 0.64 | 113.5 | 10.2 | 8.5 | 23.7 | 11.4 | 11.2 |
| MinerU | - | - | - | - | 1.06 | 168.3 | 18.3 | 16.8 | 27.5 | 76.9 | 14.8 |
两张表共同传达的选型结论:
- 开启图表识别是主要耗时来源:V100 上开启图表识别后每页耗时从 1.77 s 升至 4.09 s,A100 上从 1.12 s 升至 2.76 s;若无图表解析需求,
use_chart_recognition=False是最明显的提速手段; - Mobile OCR + PP-FormulaNet-M +
max_side_limit=1200是最省资源组合:V100 下每页 0.99 s、峰值显存仅 8.6 GB;A100 下 0.64 s、峰值显存 11.4 GB,而 MinerU 在 A100 上峰值显存高达 76.9 GB; - 公式模型从 L 换成 M 可显著降低显存占用(Server 档 V100:17.0 GB → 16.0 GB,Mobile 档 10.7 GB → 8.4 GB)。
3.3 服务化(Serving)并发性能
服务化测试基于 A100 + Xeon Platinum 8350C 环境,测试数据为 1500 张含表格、公式、印章、图表等元素的图像:
| 实例数 | 并发请求数 | 吞吐(req/s) | 平均时延 (s) | 成功率 |
|---|---|---|---|---|
| 4 GPU × 1 实例/GPU | 4 | 1.69 | 2.36 | 100% |
| 4 GPU × 4 实例/GPU | 16 | 4.05 | 3.87 | 100% |
即单机 4 卡下,通过每卡多实例的水平扩展,可将吞吐从 1.69 提升到 4.05(约 2.4 倍),代价是平均时延从 2.36 s 上升到 3.87 s,并发 16 请求下保持 100% 成功。
3.4 不同流水线配置的组合性能数据
文档还给出了 8 种流水线配置在多种硬件上的完整性能矩阵(测试环境:PaddlePaddle 3.1.0、CUDA 11.8、cuDNN 8.9;测试数据 280 张含表格/印章/公式/图表的图像;策略为先 20 张预热后完整跑一遍;NPU/XPU 未采集显存数据,记为 N/A):
| 流水线配置 | 硬件 | 平均推理时间 (s) | 峰值 CPU (%) | 平均 CPU (%) | 峰值主机内存 (MB) | 平均主机内存 (MB) | 峰值 GPU (%) | 平均 GPU (%) | 峰值显存 (MB) | 平均显存 (MB) |
|---|---|---|---|---|---|---|---|---|---|---|
| default | Intel 8350C + A100 | 1.38 | 1384.60 | 113.26 | 5781.59 | 3431.21 | 100 | 32.79 | 37370.00 | 34165.68 |
| default | Intel 6271C + V100 | 2.38 | 608.70 | 109.96 | 6388.91 | 3737.19 | 100 | 39.08 | 26824.00 | 24581.61 |
| default | Intel 8563C + H20 | 1.36 | 744.30 | 112.82 | 6199.01 | 3865.78 | 100 | 43.81 | 35132.00 | 32077.12 |
| default | Intel 8350C + A10 | 1.74 | 418.50 | 105.96 | 6138.25 | 3503.41 | 100 | 48.54 | 18536.00 | 18353.93 |
| default | Intel 6271C + T4 | 3.70 | 434.40 | 105.45 | 6865.87 | 3595.68 | 100 | 71.92 | 13970.00 | 12668.58 |
| pp | Intel 8350C + A100 | 3.50 | 679.30 | 105.96 | 13850.20 | 5146.50 | 100 | 14.01 | 37656.00 | 34716.95 |
| pp | Intel 6271C + V100 | 5.03 | 494.20 | 105.63 | 13542.94 | 4833.55 | 100 | 20.36 | 29402.00 | 26607.92 |
| pp | Intel 8563C + H20 | 3.17 | 481.50 | 105.13 | 14179.97 | 5608.80 | 100 | 19.35 | 35454.00 | 32512.19 |
| full | Intel 8350C + A100 | 8.92 | 697.30 | 102.88 | 13777.07 | 4573.65 | 100 | 18.39 | 38776.00 | 37554.09 |
| full | Intel 6271C + V100 | 13.12 | 437.40 | 102.36 | 13974.00 | 4484.00 | 100 | 17.50 | 29878.00 | 28733.59 |
| seal | Intel 8350C + A100 | 1.39 | 747.50 | 112.55 | 5788.79 | 3742.03 | 100 | 33.81 | 38966.00 | 35832.44 |
| seal | Intel 6271C + V100 | 2.44 | 630.10 | 110.18 | 6343.39 | 3725.98 | 100 | 42.23 | 28078.00 | 25834.70 |
| seal | Intel 8563C + H20 | 1.40 | 792.20 | 113.63 | 6673.60 | 4417.34 | 100 | 46.33 | 35530.00 | 32516.87 |
| seal | Intel 8350C + A10 | 1.75 | 422.40 | 106.08 | 6068.87 | 3973.49 | 100 | 50.12 | 19630.00 | 18374.37 |
| seal | Intel 6271C + T4 | 3.76 | 400.30 | 105.10 | 6296.28 | 3651.42 | 100 | 72.57 | 14304.00 | 13268.36 |
| chart | Intel 8350C + A100 | 7.70 | 746.80 | 102.69 | 6355.58 | 4006.48 | 100 | 22.38 | 37380.00 | 36730.73 |
| chart | Intel 6271C + V100 | 10.58 | 599.20 | 102.51 | 5754.14 | 3333.78 | 100 | 21.99 | 26820.00 | 26253.70 |
| chart | Intel 8350C + A10 | 8.03 | 413.30 | 101.31 | 6473.29 | 3689.84 | 100 | 26.19 | 18540.00 | 18494.69 |
| chart | Intel 6271C + T4 | 11.69 | 460.90 | 101.85 | 6503.12 | 3524.06 | 100 | 46.81 | 13966.00 | 12481.94 |
| notable | Intel 8350C + A100 | 1.24 | 738.30 | 110.45 | 5638.16 | 3278.30 | 100 | 35.32 | 30320.00 | 27026.17 |
| notable | Intel 6271C + V100 | 2.24 | 452.40 | 107.79 | 5579.15 | 3635.95 | 100 | 43.00 | 23098.00 | 20684.43 |
| notable | Intel 8563C + H20 | 1.18 | 989.00 | 107.71 | 6041.76 | 4024.76 | 100 | 50.67 | 33780.00 | 29733.15 |
| notable | Intel 8350C + A10 | 1.58 | 225.00 | 102.56 | 5518.10 | 3333.08 | 100 | 49.90 | 21532.00 | 18567.99 |
| notable | Intel 6271C + T4 | 3.40 | 413.30 | 103.58 | 5874.88 | 3662.49 | 100 | 76.82 | 13764.00 | 11890.62 |
| noformula | Intel 6271C(纯 CPU) | 7.85 | 1172.50 | 964.70 | 17739.00 | 11101.02 | N/A | N/A | N/A | N/A |
| noformula | Intel 8350C(纯 CPU) | 8.83 | 1053.50 | 970.64 | 15463.48 | 9408.19 | N/A | N/A | N/A | N/A |
| noformula | Intel 8350C + A100 | 0.84 | 788.60 | 124.25 | 6246.39 | 3674.32 | 100 | 30.57 | 40084.00 | 37358.45 |
| noformula | Intel 6271C + V100 | 1.42 | 606.20 | 115.53 | 7015.57 | 3707.03 | 100 | 35.63 | 29540.00 | 27620.28 |
| noformula | Intel 8563C + H20 | 0.87 | 644.10 | 119.23 | 6895.76 | 4222.85 | 100 | 50.00 | 36878.00 | 34104.59 |
| noformula | Intel 8350C + A10 | 1.03 | 377.50 | 106.87 | 5819.88 | 3830.19 | 100 | 42.87 | 19340.00 | 17550.94 |
| noformula | Intel 6271C + T4 | 2.02 | 430.20 | 109.21 | 6600.62 | 3824.18 | 100 | 65.75 | 14332.00 | 12712.18 |
| lightweight | Intel 6271C(纯 CPU) | 4.36 | 1189.70 | 995.78 | 14000.50 | 9374.97 | N/A | N/A | N/A | N/A |
| lightweight | Intel 8350C(纯 CPU) | 3.74 | 1049.60 | 967.77 | 12960.96 | 7644.25 | N/A | N/A | N/A | N/A |
| lightweight | Hygon 7490 + P800 | 0.86 | 572.20 | 120.84 | 8290.49 | 3569.44 | N/A | N/A | N/A | N/A |
| lightweight | Intel 8350C + A100 | 0.61 | 823.40 | 126.25 | 9258.22 | 3776.63 | 52 | 18.95 | 7456.00 | 7131.95 |
| lightweight | Intel 6271C + V100 | 1.07 | 686.80 | 116.70 | 9381.75 | 4126.28 | 58 | 22.92 | 8450.00 | 8083.30 |
| lightweight | Intel 8563C + H20 | 0.46 | 999.00 | 122.21 | 9734.78 | 4516.40 | 61 | 24.41 | 7524.00 | 7167.52 |
| lightweight | Intel 8350C + A10 | 0.70 | 355.40 | 111.51 | 9415.45 | 4094.06 | 89 | 30.85 | 7248.00 | 6927.58 |
| lightweight | M4(Apple Silicon) | 12.22 | 223.60 | 107.35 | 9531.22 | 7884.61 | N/A | N/A | N/A | N/A |
| lightweight | Intel 6271C + T4 | 1.13 | 461.40 | 112.16 | 7923.09 | 3837.31 | 85 | 41.67 | 8218.00 | 7902.04 |
各配置的含义:
| 配置 | 说明 |
|---|---|
| PP_StructureV3-default | 默认配置 |
| PP_StructureV3-pp | 默认配置 + 开启文档图像预处理 |
| PP_StructureV3-full | 默认配置 + 开启文档图像预处理 + 图表解析 |
| PP_StructureV3-seal | 默认配置 + 开启印章文本识别 |
| PP_StructureV3-chart | 默认配置 + 开启图表解析 |
| PP_StructureV3-notable | 默认配置 - 关闭表格识别 |
| PP_StructureV3-noformula | 默认配置 - 关闭公式识别 |
| PP_StructureV3-lightweight | 默认配置,所有任务模型替换为轻量版本 |
几个可直接用于容量规划的数据点:full配置在 A100 上每张图 8.92 s,是default(1.38 s)的 6 倍以上,瓶颈即图表解析;lightweight配置在 H20 上可达 0.46 s/张、峰值显存约 7.5 GB,在纯 CPU 的 Intel 8350C 上为 3.74 s/张,验证了"CPU 也能跑"的可行性(对应 FAQ 的结论);noformula在纯 CPU 下耗时 7.85~8.83 s,说明公式识别模型对 CPU 推理是重大负担。
4. 源码解析:PPStructureV3 包装类的参数体系
PaddleOCR 3.x 的paddleocr包通过 PPStructureV3 包装类 将底层 PaddleX 的PP-StructureV3流水线暴露给用户。阅读 paddleocr/_pipelines/pp_structurev3.py 可以得到几个有实战价值的信息:
4.1 构造参数:每个模块都可用model_name/model_dir替换
构造函数接收 60 余个参数,按模块分组(节选自 L34-L100):
- 版面检测:
layout_detection_model_name/layout_detection_model_dir、layout_threshold(置信度阈值)、layout_nms、layout_unclip_ratio(框扩张系数)、layout_merge_bboxes_mode(重叠框过滤策略); - 图表解析:
chart_recognition_model_name/model_dir/batch_size; - 区块检测(阅读顺序):
region_detection_model_name/model_dir; - 文档预处理:
doc_orientation_classify_model_name、doc_unwarping_model_name等; - 通用 OCR:
text_detection_model_name、text_det_limit_side_len(即文档中的max_side_limit,输入图像侧长上限)、text_det_limit_type(侧长限制应用方式)、text_det_thresh(像素阈值)、text_det_box_thresh(框阈值)、text_det_unclip_ratio、text_recognition_model_name、text_rec_score_thresh; - 表格识别:
table_classification_model_name、wired/wireless_table_structure_recognition_model_name、wired/wireless_table_cells_detection_model_name、table_orientation_classify_model_name; - 印章识别:
seal_text_detection_model_name、seal_det_*系列参数、seal_text_recognition_model_name; - 公式识别:
formula_recognition_model_name、formula_recognition_batch_size; - 功能开关:
use_doc_orientation_classify、use_doc_unwarping、use_textline_orientation、use_seal_recognition、use_table_recognition、use_formula_recognition、use_chart_recognition、use_region_detection; - 输出控制:
format_block_content(是否将块内容格式化为 Markdown)、markdown_ignore_labels(Markdown 输出中忽略的版面标签列表)、lang、ocr_version。
这些用户参数最终通过_get_paddlex_config_overrides方法映射到 PaddleX 流水线的层级化配置路径上,从源码结构看,整个流水线配置树为:
SubPipelines.DocPreprocessor ├── use_doc_orientation_classify / use_doc_unwarping └── SubModules: DocOrientationClassify, DocUnwarping SubPipelines.GeneralOCR └── SubModules: TextDetection, TextLineOrientation, TextRecognition SubPipelines.TableRecognition ├── SubModules: TableClassification, WiredTableStructureRecognition, │ WirelessTableStructureRecognition, Wired/WirelessTableCellsDetection, │ TableOrientationClassify └── SubPipelines.GeneralOCR(表格内文字复用同一套文本检测/识别模型) SubPipelines.SealRecognition └── SubPipelines.SealOCR → TextDetection / TextRecognition SubPipelines.FormulaRecognition SubModules: LayoutDetection, ChartRecognition, RegionDetection值得注意的一处实现细节:表格识别子流水线内部复用了与全局 OCR 相同的text_detection_model_name/text_recognition_model_name(见 L446-L487),即替换通用 OCR 模型时表格内文字识别也会同步切换,无需单独配置。
4.2 语言与 OCR 版本映射:_get_ocr_model_names
当用户只提供lang+ocr_version而不指定具体模型名时,_get_ocr_model_names负责解析默认模型。从源码看:
ocr_version仅支持PP-OCRv3、PP-OCRv4、PP-OCRv5(由_SUPPORTED_OCR_VERSIONS约束,传其他值直接抛ValueError);lang为 None 时默认取"ch";未指定版本时,中/繁/英/日/韩/泰/希腊语及拉丁、斯拉夫语系默认走PP-OCRv5(检测统一用PP-OCRv5_server_det,识别按语种选择PP-OCRv5_server_rec或*_PP-OCRv5_mobile_rec),阿拉伯、西里尔、天城文及其他特定语种回退到PP-OCRv3的语种 mobile 识别模型(如arabic_PP-OCRv3_mobile_rec);PP-OCRv4仅支持ch(PP-OCRv4_mobile_det+PP-OCRv4_mobile_rec)与en(PP-OCRv4_mobile_det+en_PP-OCRv4_mobile_rec);- 若已显式传入检测/识别模型名或模型目录,
lang与ocr_version会被忽略(仅打印警告)。
这解释了文档基准表中"Server / Mobile"两档 OCR 模型的来源——它们对应 PP-OCRv5 系列的 server 与 mobile 型号。
4.3 CLI 子命令与测试验证
PPStructureV3CLISubcommandExecutor注册了pp_structurev3子命令,除通用推理参数(输入、设备、引擎等)外,逐一暴露了上文 4.1 节的全部参数,其中--markdown_ignore_labels支持多值列表(nargs="+")。参数帮助文本也给出了语义说明,例如text_det_thresh是"输出概率图中高于该阈值的像素视为文本像素",text_det_unclip_ratio是"文本区域扩张系数,值越大扩张区域越大"。
测试侧的 tests/pipelines/test_pp_structurev3.py 提供了两层验证:
test_predict对含公式的文档图片执行推理,断言结果中overall_ocr_res的dt_polys、rec_texts、rec_polys、rec_boxes均非空,可据此了解返回结果的最小字段结构;test_predict_params通过 monkeypatch 验证 18 组参数被正确转发到底层 PaddleX 流水线,覆盖use_*开关、layout_threshold标量/列表/字典三种写法(字典按类别索引,如{0: 0.45, 2: 0.48, 7: 0.4})、layout_unclip_ratio同构写法、layout_merge_bboxes_mode("large"或按类别字典)、text_det_limit_side_len+text_det_limit_type、检测/识别阈值等。这说明阈值类参数支持"全局标量、按范围列表、按类别字典"三种粒度,是调参时容易忽略但很有用的能力。
5. 实战使用:CLI 快速上手与关键调参
5.1 安装前提
本地使用 PP-StructureV3 前需按 安装文档 完成 wheel 安装,该流水线对应的依赖组为doc-parser。若运行中出现程序无响应、意外退出、内存耗尽或推理极慢,文档建议的处置方式是按配置文档调整:关闭不需要的功能开关、或改用更轻量模型。
5.2 命令行方式
# 一条命令体验默认流水线(输入可为本地路径或 URL) paddleocr pp_structurev3 -i https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/pp_structure_v3_demo.png # 开启文档方向分类 paddleocr pp_structurev3 -i ./pp_structure_v3_demo.png --use_doc_orientation_classify True # 开启文档矫正(unwarping) paddleocr pp_structurev3 -i ./pp_structure_v3_demo.png --use_doc_unwarping True # 关闭文本行方向分类 paddleocr pp_structurev3 -i ./pp_structure_v3_demo.png --use_textline_orientation False # 指定 GPU 推理 paddleocr pp_structurev3 -i ./pp_structure_v3_demo.png --device gpu示例默认使用本地 Paddle 推理引擎:仅支持动态图的模型使用paddle_dynamic,静态/动态图均支持的模型优先paddle_static。如需切换推理引擎,可参考 推理引擎与配置文档 配置环境后追加--engine参数:
# 使用 transformers 引擎 paddleocr pp_structurev3 -i ./pp_structure_v3_demo.png --engine transformers # 使用 onnxruntime 引擎 paddleocr pp_structurev3 -i ./pp_structure_v3_demo.png --engine onnxruntime5.3 Python API 与 Markdown 页面合并
从源码定义看,Python 侧的入口类为paddleocr.PPStructureV3,提供predict/predict_iter(批量/迭代)两个推理入口,以及concatenate_markdown_pages方法用于将多页 Markdown 结果合并为整份文档的 Markdown。基本用法:
from paddleocr import PPStructureV3 pipeline = PPStructureV3( use_formula_recognition=True, # 开启公式识别 use_chart_recognition=False, # 关闭图表解析以降低时延(见 3.2 节数据) ) result = pipeline.predict("page.png") # 逐页输出 Markdown;多页场景可调用 # pipeline.concatenate_markdown_pages(markdown_list) 合并predict的所有关键字参数与 CLI 的--参数一一对应(见 4.1 节),因此基准测试中的"Mobile OCR + PP-FormulaNet-M +max_side_limit=1200"组合在 Python 中即写作text_detection_model_name="PP-OCRv5_mobile_det"、formula_recognition_model_name="PP-FormulaNet-M"、text_det_limit_side_len=1200。
5.4 关键调参策略(结合第 2、3 节数据)
| 目标 | 推荐操作 | 依据 |
|---|---|---|
| 降低时延 | use_chart_recognition=False;关闭use_formula_recognition |
【免费下载链接】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),仅供参考