Upload folder using huggingface_hub
Browse files
README.md
ADDED
@@ -0,0 +1,141 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: apache-2.0
|
3 |
+
---
|
4 |
+
|
5 |
+
# PicoDet_layout_1x_table
|
6 |
+
|
7 |
+
## Introduction
|
8 |
+
|
9 |
+
A high-efficiency layout area localization model trained on a self-built dataset using PicoDet-1x, capable of detecting table regions. The key metrics are as follow:
|
10 |
+
|
11 |
+
| Model| mAP(0.5) (%) |
|
12 |
+
| --- | --- |
|
13 |
+
|PicoDet_layout_1x_table | 97.5 |
|
14 |
+
|
15 |
+
## Quick Start
|
16 |
+
|
17 |
+
### Installation
|
18 |
+
|
19 |
+
1. PaddlePaddle
|
20 |
+
|
21 |
+
Please refer to the following commands to install PaddlePaddle using pip:
|
22 |
+
|
23 |
+
```bash
|
24 |
+
# for CUDA11.8
|
25 |
+
python -m pip install paddlepaddle-gpu==3.0.0 -i https://www.paddlepaddle.org.cn/packages/stable/cu118/
|
26 |
+
|
27 |
+
# for CUDA12.6
|
28 |
+
python -m pip install paddlepaddle-gpu==3.0.0 -i https://www.paddlepaddle.org.cn/packages/stable/cu126/
|
29 |
+
|
30 |
+
# for CPU
|
31 |
+
python -m pip install paddlepaddle==3.0.0 -i https://www.paddlepaddle.org.cn/packages/stable/cpu/
|
32 |
+
```
|
33 |
+
|
34 |
+
For details about PaddlePaddle installation, please refer to the [PaddlePaddle official website](https://www.paddlepaddle.org.cn/en/install/quick).
|
35 |
+
|
36 |
+
2. PaddleOCR
|
37 |
+
|
38 |
+
Install the latest version of the PaddleOCR inference package from PyPI:
|
39 |
+
|
40 |
+
```bash
|
41 |
+
python -m pip install paddleocr
|
42 |
+
```
|
43 |
+
|
44 |
+
|
45 |
+
### Model Usage
|
46 |
+
|
47 |
+
You can quickly experience the functionality with a single command:
|
48 |
+
|
49 |
+
```bash
|
50 |
+
paddleocr layout_detection \
|
51 |
+
--model_name PicoDet_layout_1x_table \
|
52 |
+
-i https://cdn-uploads.huggingface.co/production/uploads/63d7b8ee07cd1aa3c49a2026/N5C68HPVAI-xQAWTxpbA6.jpeg
|
53 |
+
```
|
54 |
+
|
55 |
+
You can also integrate the model inference of the layout detection module into your project. Before running the following code, please download the sample image to your local machine.
|
56 |
+
|
57 |
+
```python
|
58 |
+
from paddleocr import LayoutDetection
|
59 |
+
|
60 |
+
model = LayoutDetection(model_name="PicoDet_layout_1x_table")
|
61 |
+
output = model.predict("N5C68HPVAI-xQAWTxpbA6.jpeg", batch_size=1, layout_nms=True)
|
62 |
+
for res in output:
|
63 |
+
res.print()
|
64 |
+
res.save_to_img(save_path="./output/")
|
65 |
+
res.save_to_json(save_path="./output/res.json")
|
66 |
+
```
|
67 |
+
|
68 |
+
After running, the obtained result is as follows:
|
69 |
+
|
70 |
+
```json
|
71 |
+
{'res': {'input_path': '/root/.paddlex/predict_input/N5C68HPVAI-xQAWTxpbA6.jpeg', 'page_index': None, 'boxes': [{'cls_id': 0, 'label': 'Table', 'score': 0.9617661237716675, 'coordinate': [435.82446, 106.01748, 665.04346, 316.21014]}, {'cls_id': 0, 'label': 'Table', 'score': 0.9583022594451904, 'coordinate': [72.52834, 106.46287, 322.751, 301.454]}]}}
|
72 |
+
```
|
73 |
+
|
74 |
+
The visualized image is as follows:
|
75 |
+
|
76 |
+

|
77 |
+
|
78 |
+
For details about usage command and descriptions of parameters, please refer to the [Document](https://paddlepaddle.github.io/PaddleOCR/latest/en/version3.x/module_usage/layout_detection.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-TableMagic (table_recognition_v2)
|
85 |
+
|
86 |
+
The General Table Recognition v2 pipeline (PP-TableMagic) is designed to tackle table recognition tasks, identifying tables in images and outputting them in HTML format. PP-TableMagic includes the following 8 modules:
|
87 |
+
|
88 |
+
* Table Structure Recognition Module
|
89 |
+
* Table Classification Module
|
90 |
+
* Table Cell Detection Module
|
91 |
+
* Text Detection Module
|
92 |
+
* Text Recognition Module
|
93 |
+
* Layout Region Detection Module (optional)
|
94 |
+
* Document Image Orientation Classification Module (optional)
|
95 |
+
* Text Image Unwarping Module (optional)
|
96 |
+
|
97 |
+
You can quickly experience the PP-TableMagic pipeline with a single command.
|
98 |
+
|
99 |
+
```bash
|
100 |
+
paddleocr table_recognition_v2 -i https://cdn-uploads.huggingface.co/production/uploads/63d7b8ee07cd1aa3c49a2026/tuY1zoUdZsL6-9yGG0MpU.jpeg \
|
101 |
+
--layout_detection_model_name PicoDet_layout_1x_table \
|
102 |
+
--use_doc_orientation_classify False \
|
103 |
+
--use_doc_unwarping False \
|
104 |
+
--save_path ./output \
|
105 |
+
--device gpu:0
|
106 |
+
|
107 |
+
```
|
108 |
+
|
109 |
+
|
110 |
+
If save_path is specified, the visualization results will be saved under `save_path`.
|
111 |
+
|
112 |
+
The command-line method is for quick experience. For project integration, also only a few codes are needed as well:
|
113 |
+
|
114 |
+
|
115 |
+
```python
|
116 |
+
from paddleocr import TableRecognitionPipelineV2
|
117 |
+
|
118 |
+
pipeline = TableRecognitionPipelineV2(
|
119 |
+
layout_detection_model_name=PicoDet_layout_1x_table,
|
120 |
+
use_doc_orientation_classify=False, # Use use_doc_orientation_classify to enable/disable document orientation classification model
|
121 |
+
use_doc_unwarping=False, # Use use_doc_unwarping to enable/disable document unwarping module
|
122 |
+
device="gpu:0", # Use device to specify GPU for model inference
|
123 |
+
)
|
124 |
+
|
125 |
+
output = pipeline.predict("tuY1zoUdZsL6-9yGG0MpU.jpeg")
|
126 |
+
for res in output:
|
127 |
+
res.print() ## Print the predicted structured output
|
128 |
+
res.save_to_img("./output/")
|
129 |
+
res.save_to_xlsx("./output/")
|
130 |
+
res.save_to_html("./output/")
|
131 |
+
res.save_to_json("./output/")
|
132 |
+
```
|
133 |
+
|
134 |
+
The default model used in pipeline is `PP-DocLayout-L`, so it is needed that specifing to `PicoDet_layout_1x_table` by argument `layout_detection_model_name`. And you can also use the local model file by argument `layout_detection_model_dir`. For details about usage command and descriptions of parameters, please refer to the [Document](https://paddlepaddle.github.io/PaddleOCR/main/en/version3.x/pipeline_usage/table_recognition_v2.html#2-quick-start).
|
135 |
+
|
136 |
+
## Links
|
137 |
+
|
138 |
+
[PaddleOCR Repo](https://github.com/paddlepaddle/paddleocr)
|
139 |
+
|
140 |
+
[PaddleOCR Documentation](https://paddlepaddle.github.io/PaddleOCR/latest/en/index.html)
|
141 |
+
|