🚀 PP-Chart2Table
PP-Chart2Table是由PaddlePaddle團隊開發的一款先進的多模態模型,專注於中英文圖表解析。它通過一種新穎的“Shuffled Chart Data Retrieval”訓練任務驅動,結合精細的令牌掩碼策略,顯著提高了將圖表轉換為數據表的效率。此外,該模型還藉助先進的數據合成管道,利用高質量種子數據、RAG和大語言模型角色設計,創建了更豐富、更多樣化的訓練集。為應對大規模無標籤、分佈外(OOD)數據的挑戰,團隊實施了兩階段蒸餾過程,確保了模型在實際數據上的強大適應性和泛化能力。內部基準測試表明,PP-Chart2Table不僅優於類似規模的模型,而且在關鍵應用場景中達到了與70億參數視覺語言模型(VLMs)相當的性能。
🚀 快速開始
📦 安裝指南
1. 安裝PaddlePaddle
請參考以下命令,使用pip安裝PaddlePaddle:
python -m pip install paddlepaddle-gpu==3.0.0 -i https://www.paddlepaddle.org.cn/packages/stable/cu118/
python -m pip install paddlepaddle-gpu==3.0.0 -i https://www.paddlepaddle.org.cn/packages/stable/cu126/
python -m pip install paddlepaddle==3.0.0 -i https://www.paddlepaddle.org.cn/packages/stable/cpu/
有關PaddlePaddle安裝的詳細信息,請參考PaddlePaddle官方網站。
2. 安裝PaddleX
從PyPI安裝最新版本的PaddleX推理包:
python -m pip install paddlex && python -m pip install "paddlex[multimodal]"
💻 使用示例
基礎用法
你可以將PP-Chart2Table的模型推理集成到你的項目中。在運行以下代碼之前,請將示例圖像下載到本地。
from paddlex import create_model
model = create_model('PP-Chart2Table')
results = model.predict(
input={"image": "https://cdn-uploads.huggingface.co/production/uploads/684acf07de103b2d44c85531/OrlFuIXQUhO3Fg1G9_H1u.png"},
batch_size=1
)
for res in results:
res.print()
res.save_to_json(f"./output/res.json")
運行後,得到的結果如下:
{'res': {'image': 'https://cdn-uploads.huggingface.co/production/uploads/684acf07de103b2d44c85531/OrlFuIXQUhO3Fg1G9_H1u.png', 'result': 'Agency | Favorable | Not Sure | Unfavorable\nNational Park Service | 81% | 12% | 7%\nU.S. Postal Service | 77% | 3% | 20%\nNASA | 74% | 17% | 9%\nSocial Security Administration | 61% | 12% | 28%\nCDC | 56% | 6% | 38%\nVeterans Affairs | 56% | 16% | 28%\nEPA | 55% | 14% | 31%\nHealth and Human Services | 55% | 15% | 30%\nFBI | 52% | 12% | 36%\nDepartment of Transportation | 52% | 12% | 36%\nDepartment of Homeland Security | 51% | 18% | 35%\nDepartment of Justice | 49% | 10% | 41%\nCIA | 46% | 21% | 33%\nDepartment of Education | 45% | 8% | 47%\nFederal Reserve | 43% | 20% | 37%\nIRS | 42% | 7% | 51%'}}
可視化結果如下:
有關使用命令和參數說明的詳細信息,請參考文檔。
高級用法
單個模型的能力是有限的,但由多個模型組成的管道可以提供更強的能力來解決實際場景中的難題。
PP-StructureV3
佈局分析是一種從文檔圖像中提取結構化信息的技術。PP-StructureV3包含以下七個模塊:
- 佈局檢測模塊
- 圖表識別模塊(可選)
- 通用OCR子管道
- 文檔圖像預處理子管道(可選)
- 表格識別子管道(可選)
- 印章識別子管道(可選)
- 公式識別子管道(可選)
你可以使用單個命令快速體驗PP-StructureV3管道:
paddleocr pp_structurev3 --chart_recognition_model_name PP-Chart2Table \
--use_chart_recognition True \
-i https://cdn-uploads.huggingface.co/production/uploads/684acf07de103b2d44c85531/Mk1PKgszCEEutZukT3FPB.png
你也可以用幾行代碼體驗管道的推理。以PP-StructureV3管道為例:
from paddleocr import PPStructureV3
pipeline = PPStructureV3(chart_recognition_model_name="PP-Chart2Table", use_chart_recognition=True)
output = pipeline.predict("./Mk1PKgszCEEutZukT3FPB.png", use_chart_recognition=True)
for res in output:
res.print()
res.save_to_json(save_path="output")
res.save_to_markdown(save_path="output")
管道中使用的默認模型是PP-Chart2Table
,因此你不必為chart_recognition_model_name
參數指定PP-Chart2Table
,但你可以通過chart_recognition_model_dir
參數使用本地模型文件。有關使用命令和參數說明的詳細信息,請參考文檔。
📚 詳細文檔
相關鏈接
📄 許可證
本項目採用Apache-2.0許可證。