模型概述
模型特點
模型能力
使用案例
🚀 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 許可證。










