🚀 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许可证。