模型简介
模型特点
模型能力
使用案例
🚀 PP-DocLayout-L
PP-DocLayout-L 是一个高精度的布局区域定位模型,它基于 RT-DETR-L 架构,在自建的包含中英文论文、杂志、合同、书籍、试卷和研究报告等文档的数据集上进行训练。该模型可检测 23 种常见的文档布局类别,能有效解决文档布局检测的问题,为文档处理提供准确的布局信息。
🚀 快速开始
📦 安装指南
1. 安装 PaddlePaddle
请参考以下命令,使用 pip 安装 PaddlePaddle:
# 适用于 CUDA11.8
python -m pip install paddlepaddle-gpu==3.0.0 -i https://www.paddlepaddle.org.cn/packages/stable/cu118/
# 适用于 CUDA12.6
python -m pip install paddlepaddle-gpu==3.0.0 -i https://www.paddlepaddle.org.cn/packages/stable/cu126/
# 适用于 CPU
python -m pip install paddlepaddle==3.0.0 -i https://www.paddlepaddle.org.cn/packages/stable/cpu/
PaddlePaddle 安装的详细信息,请参考 PaddlePaddle 官方网站。
2. 安装 PaddleOCR
从 PyPI 安装最新版本的 PaddleOCR 推理包:
python -m pip install paddleocr
💻 使用示例
基础用法
你可以使用单个命令快速体验模型功能:
paddleocr layout_detection \
--model_name PP-DocLayout-L \
-i https://cdn-uploads.huggingface.co/production/uploads/63d7b8ee07cd1aa3c49a2026/N5C68HPVAI-xQAWTxpbA6.jpeg
你也可以将布局检测模块的模型推理集成到你的项目中。在运行以下代码之前,请将示例图像下载到本地机器。
from paddleocr import LayoutDetection
model = LayoutDetection(model_name="PP-DocLayout-L")
output = model.predict("N5C68HPVAI-xQAWTxpbA6.jpeg", batch_size=1)
for res in output:
res.print()
res.save_to_img(save_path="./output/")
res.save_to_json(save_path="./output/res.json")
运行后,得到的结果如下:
{'res': {'input_path': '/root/.paddlex/predict_input/N5C68HPVAI-xQAWTxpbA6.jpeg', 'page_index': None, 'boxes': [{'cls_id': 8, 'label': 'table', 'score': 0.9866371154785156, 'coordinate': [74.3101, 105.714195, 321.98795, 299.11014]}, {'cls_id': 2, 'label': 'text', 'score': 0.9859796166419983, 'coordinate': [34.659634, 349.9106, 358.33762, 611.34357]}, {'cls_id': 2, 'label': 'text', 'score': 0.9850561618804932, 'coordinate': [34.94621, 647.37744, 358.32578, 849.23584]}, {'cls_id': 8, 'label': 'table', 'score': 0.9850051403045654, 'coordinate': [438.06946, 105.37968, 662.88696, 313.88608]}, {'cls_id': 2, 'label': 'text', 'score': 0.9847787022590637, 'coordinate': [385.971, 497.0397, 710.95557, 697.68115]}, {'cls_id': 2, 'label': 'text', 'score': 0.980556845664978, 'coordinate': [385.79675, 345.93768, 710.07336, 459.1456]}, {'cls_id': 2, 'label': 'text', 'score': 0.9799885749816895, 'coordinate': [386.07678, 735.3819, 710.60815, 850.1992]}, {'cls_id': 9, 'label': 'table_title', 'score': 0.9376334547996521, 'coordinate': [35.275173, 19.85299, 358.9236, 77.812965]}, {'cls_id': 0, 'label': 'paragraph_title', 'score': 0.8755854964256287, 'coordinate': [386.63153, 476.6075, 699.78394, 490.1158]}, {'cls_id': 0, 'label': 'paragraph_title', 'score': 0.8617689609527588, 'coordinate': [387.2742, 715.95734, 524.38525, 729.20825]}, {'cls_id': 0, 'label': 'paragraph_title', 'score': 0.860828161239624, 'coordinate': [35.453644, 627.4963, 185.6373, 640.4026]}, {'cls_id': 0, 'label': 'paragraph_title', 'score': 0.857572615146637, 'coordinate': [35.33445, 330.80554, 141.46928, 344.407]}, {'cls_id': 9, 'label': 'table_title', 'score': 0.7964489459991455, 'coordinate': [385.9402, 19.755222, 711.51154, 75.00652]}, {'cls_id': 2, 'label': 'text', 'score': 0.5557674765586853, 'coordinate': [385.9402, 19.755222, 711.51154, 75.00652]}]}}
可视化图像如下:
高级用法
单个模型的能力是有限的,但由多个模型组成的管道可以提供更强的能力来解决现实场景中的难题。
PP-StructureV3
布局分析是一种从文档图像中提取结构化信息的技术。PP-StructureV3 包括以下六个模块:
- 布局检测模块
- 通用 OCR 子管道
- 文档图像预处理子管道(可选)
- 表格识别子管道(可选)
- 印章识别子管道(可选)
- 公式识别子管道(可选)
你可以使用单个命令快速体验 PP-StructureV3 管道:
paddleocr pp_structurev3 --layout_detection_model_name PP-DocLayout-L -i https://cdn-uploads.huggingface.co/production/uploads/63d7b8ee07cd1aa3c49a2026/KP10tiSZfAjMuwZUSLtRp.png
你也可以使用几行代码体验管道推理。以 PP-StructureV3 管道为例:
from paddleocr import PPStructureV3
pipeline = PPStructureV3(layout_detection_model_name="PP-DocLayout-L")
# ocr = PPStructureV3(use_doc_orientation_classify=True) # 使用 use_doc_orientation_classify 启用/禁用文档方向分类模型
# ocr = PPStructureV3(use_doc_unwarping=True) # 使用 use_doc_unwarping 启用/禁用文档去畸变模块
# ocr = PPStructureV3(use_textline_orientation=True) # 使用 use_textline_orientation 启用/禁用文本行方向分类模型
# ocr = PPStructureV3(device="gpu") # 使用 device 指定 GPU 进行模型推理
output = pipeline.predict("./KP10tiSZfAjMuwZUSLtRp.png")
for res in output:
res.print() ## 打印结构化预测输出
res.save_to_json(save_path="output") ## 以 JSON 格式保存当前图像的结构化结果
res.save_to_markdown(save_path="output") ## 以 Markdown 格式保存当前图像的结果
管道中默认使用的模型是 PP-DocLayout_plus-L
,因此需要通过参数 layout_detection_model_name
指定为 PP-DocLayout-L
。你也可以通过参数 layout_detection_model_dir
使用本地模型文件。
使用命令和参数说明的详细信息,请参考 文档。
📚 详细文档
模型介绍
PP-DocLayout-L 是一个高精度的布局区域定位模型,使用 RT-DETR-L 在自建的包含中英文论文、杂志、合同、书籍、考试和研究报告的数据集上进行训练。该布局检测模型包括 23 个常见类别:文档标题、段落标题、文本、页码、摘要、目录、参考文献、脚注、页眉、页脚、算法、公式、公式编号、图像、图注、表格、表格标题、印章、图标题、图形、页眉图像、页脚图像和侧边文本。关键指标如下:
模型 | mAP(0.5) (%) |
---|---|
PP-DocLayout-L | 90.4 |
注意:上述准确率指标的评估集是一个自建的布局区域检测数据集,包括 500 张文档类型图像,如中英文论文、报纸、研究论文和试卷。
相关链接
📄 许可证
本项目采用 Apache-2.0 许可证。










