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
| 12 |
+
---
|
| 13 |
+
|
| 14 |
+
# PP-Chart2Table
|
| 15 |
+
|
| 16 |
+
## Introduction
|
| 17 |
+
|
| 18 |
+
PP-Chart2Table is a SOTA multimodal model developed by the PaddlePaddle team, specializing in chart parsing for both Chinese and English. Its high performance is driven by a novel "Shuffled Chart Data Retrieval" training task, which, combined with a refined token masking strategy, significantly improves its efficiency in converting charts to data tables. The model is further strengthened by an advanced data synthesis pipeline that uses high-quality seed data, RAG, and LLMs persona design to create a richer, more diverse training set. To address the challenge of large-scale unlabeled, out-of-distribution (OOD) data, the team implemented a two-stage distillation process, ensuring robust adaptability and generalization on real-world data. In-house benchmarks demonstrate that PP-Chart2Table not only outperforms models of a similar scale but also achieves performance on par with 7-billion parameter Vision Language Models (VLMs) in critical application scenarios.
|
| 19 |
+
|
| 20 |
+
<img src="https://cdn-uploads.huggingface.co/production/uploads/684acf07de103b2d44c85531/IsYzsgw5f8ehK4zn9IP1x.png"/>
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
## Quick Start
|
| 24 |
+
|
| 25 |
+
### Installation
|
| 26 |
+
|
| 27 |
+
1. PaddlePaddle
|
| 28 |
+
|
| 29 |
+
Please refer to the following commands to install PaddlePaddle using pip:
|
| 30 |
+
|
| 31 |
+
```bash
|
| 32 |
+
# for CUDA11.8
|
| 33 |
+
python -m pip install paddlepaddle-gpu==3.0.0 -i https://www.paddlepaddle.org.cn/packages/stable/cu118/
|
| 34 |
+
|
| 35 |
+
# for CUDA12.6
|
| 36 |
+
python -m pip install paddlepaddle-gpu==3.0.0 -i https://www.paddlepaddle.org.cn/packages/stable/cu126/
|
| 37 |
+
|
| 38 |
+
# for CPU
|
| 39 |
+
python -m pip install paddlepaddle==3.0.0 -i https://www.paddlepaddle.org.cn/packages/stable/cpu/
|
| 40 |
+
```
|
| 41 |
+
|
| 42 |
+
For details about PaddlePaddle installation, please refer to the [PaddlePaddle official website](https://www.paddlepaddle.org.cn/en/install/quick).
|
| 43 |
+
|
| 44 |
+
2. PaddleX
|
| 45 |
+
|
| 46 |
+
Install the latest version of the PaddleX inference package from PyPI:
|
| 47 |
+
|
| 48 |
+
```bash
|
| 49 |
+
python -m pip install paddlex && python -m pip install "paddlex[multimodal]"
|
| 50 |
+
```
|
| 51 |
+
|
| 52 |
+
### Model Usage
|
| 53 |
+
|
| 54 |
+
You can integrate the model inference of PP-Chart2Table into your project. Before running the following code, please download the sample image to your local machine.
|
| 55 |
+
|
| 56 |
+
```python
|
| 57 |
+
from paddlex import create_model
|
| 58 |
+
model = create_model('PP-Chart2Table')
|
| 59 |
+
results = model.predict(
|
| 60 |
+
input={"image": "https://cdn-uploads.huggingface.co/production/uploads/684acf07de103b2d44c85531/OrlFuIXQUhO3Fg1G9_H1u.png"},
|
| 61 |
+
batch_size=1
|
| 62 |
+
)
|
| 63 |
+
for res in results:
|
| 64 |
+
res.print()
|
| 65 |
+
res.save_to_json(f"./output/res.json")
|
| 66 |
+
```
|
| 67 |
+
|
| 68 |
+
After running, the obtained result is as follows:
|
| 69 |
+
|
| 70 |
+
```bash
|
| 71 |
+
{'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%'}}
|
| 72 |
+
```
|
| 73 |
+
|
| 74 |
+
The visualized result is as follows:
|
| 75 |
+
|
| 76 |
+
<img src="https://cdn-uploads.huggingface.co/production/uploads/684acf07de103b2d44c85531/vxlQiD7IGA4n9U7eJFUJo.png"/>
|
| 77 |
+
|
| 78 |
+
For details about usage command and descriptions of parameters, please refer to the [Document](https://paddlepaddle.github.io/PaddleX/latest/en/module_usage/tutorials/vlm_modules/chart_parsing.html#iii-quick-integration).
|
| 79 |
+
|
| 80 |
+
### Pipeline Usage
|
| 81 |
+
|
| 82 |
+
The ability of a single model is limited. But the pipeline consists of several models can provide more capacity to resolve difficult problems in real-world scenarios.
|
| 83 |
+
|
| 84 |
+
#### PP-StructureV3
|
| 85 |
+
|
| 86 |
+
Layout analysis is a technique used to extract structured information from document images. PP-StructureV3 includes the following seven modules:
|
| 87 |
+
* Layout Detection Module
|
| 88 |
+
* Chart Recognition Module(Optional)
|
| 89 |
+
* General OCR Sub-pipeline
|
| 90 |
+
* Document Image Preprocessing Sub-pipeline (Optional)
|
| 91 |
+
* Table Recognition Sub-pipeline (Optional)
|
| 92 |
+
* Seal Recognition Sub-pipeline (Optional)
|
| 93 |
+
* Formula Recognition Sub-pipeline (Optional)
|
| 94 |
+
|
| 95 |
+
You can quickly experience the PP-StructureV3 pipeline with a single command.
|
| 96 |
+
|
| 97 |
+
```bash
|
| 98 |
+
paddleocr pp_structurev3 --chart_recognition_model_name PP-Chart2Table \
|
| 99 |
+
--use_chart_recognition True \
|
| 100 |
+
-i https://cdn-uploads.huggingface.co/production/uploads/684acf07de103b2d44c85531/Mk1PKgszCEEutZukT3FPB.png
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
You can experience the inference of the pipeline with just a few lines of code. Taking the PP-StructureV3 pipeline as an example:
|
| 104 |
+
|
| 105 |
+
```python
|
| 106 |
+
from paddleocr import PPStructureV3
|
| 107 |
+
|
| 108 |
+
pipeline = PPStructureV3(chart_recognition_model_name="PP-Chart2Table", use_chart_recognition=True)
|
| 109 |
+
# ocr = PPStructureV3(use_doc_orientation_classify=True) # Use use_doc_orientation_classify to enable/disable document orientation classification model
|
| 110 |
+
# ocr = PPStructureV3(use_doc_unwarping=True) # Use use_doc_unwarping to enable/disable document unwarping module
|
| 111 |
+
# ocr = PPStructureV3(use_textline_orientation=True) # Use use_textline_orientation to enable/disable textline orientation classification model
|
| 112 |
+
# ocr = PPStructureV3(device="gpu") # Use device to specify GPU for model inference
|
| 113 |
+
output = pipeline.predict("./Mk1PKgszCEEutZukT3FPB.png", use_chart_recognition=True)
|
| 114 |
+
for res in output:
|
| 115 |
+
res.print() ## Print the structured prediction output
|
| 116 |
+
res.save_to_json(save_path="output") ## Save the current image's structured result in JSON format
|
| 117 |
+
res.save_to_markdown(save_path="output") ## Save the current image's result in Markdown format
|
| 118 |
+
```
|
| 119 |
+
|
| 120 |
+
The default model used in pipeline is `PP-Chart2Table`, so you don't have to specify `PP-Chart2Table` for the `chart_recognition_model_name argument`, but you can use the local model file by argument `chart_recognition_model_dir`.
|
| 121 |
+
For details about usage command and descriptions of parameters, please refer to the [Document](https://paddlepaddle.github.io/PaddleOCR/latest/en/version3.x/pipeline_usage/PP-StructureV3.html#2-quick-start).
|
| 122 |
+
|
| 123 |
+
## Links
|
| 124 |
+
|
| 125 |
+
[PaddleOCR Repo](https://github.com/paddlepaddle/paddleocr)
|
| 126 |
+
|
| 127 |
+
[PaddleOCR Documentation](https://paddlepaddle.github.io/PaddleOCR/latest/en/index.html)
|
| 128 |
+
|
| 129 |
+
[PaddleX Repo](https://github.com/paddlepaddle/paddlex)
|
| 130 |
+
|
| 131 |
+
[PaddleX Documentation](https://paddlepaddle.github.io/PaddleX/latest/en/index.html)
|