Tingquan commited on
Commit
75e789f
·
verified ·
1 Parent(s): 8fc63b6

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +266 -0
README.md ADDED
@@ -0,0 +1,266 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ ---
4
+
5
+ # SLANet
6
+
7
+ ## Introduction
8
+
9
+ Table structure recognition is an important component of table recognition systems, capable of converting non-editable table images into editable table formats (such as HTML). The goal of table structure recognition is to identify the positions of rows, columns, and cells in tables. The performance of this module directly affects the accuracy and efficiency of the entire table recognition system. The table structure recognition module usually outputs HTML code for the table area, which is then passed as input to the tabl recognition pipeline for further processing.
10
+
11
+ <table>
12
+ <tr>
13
+ <th>Model</th>
14
+ <th>Accuracy (%)</th>
15
+ <th>GPU Inference Time (ms)<br/>[Normal Mode / High Performance Mode]</th>
16
+ <th>CPU Inference Time (ms)<br/>[Normal Mode / High Performance Mode]</th>
17
+ <th>Model Storage Size (M)</th>
18
+ </tr>
19
+ <tr>
20
+ <td>SLANet</td>
21
+ <td>59.52</td>
22
+ <td>103.08 / 103.08</td>
23
+ <td>197.99 / 197.99</td>
24
+ <td>6.9 M</td>
25
+ </tr>
26
+ </table>
27
+
28
+
29
+ ### Installation
30
+
31
+ 1. PaddlePaddle
32
+
33
+ Please refer to the following commands to install PaddlePaddle using pip:
34
+
35
+ ```bash
36
+ # for CUDA11.8
37
+ python -m pip install paddlepaddle-gpu==3.0.0 -i https://www.paddlepaddle.org.cn/packages/stable/cu118/
38
+
39
+ # for CUDA12.6
40
+ python -m pip install paddlepaddle-gpu==3.0.0 -i https://www.paddlepaddle.org.cn/packages/stable/cu126/
41
+
42
+ # for CPU
43
+ python -m pip install paddlepaddle==3.0.0 -i https://www.paddlepaddle.org.cn/packages/stable/cpu/
44
+ ```
45
+
46
+ For details about PaddlePaddle installation, please refer to the [PaddlePaddle official website](https://www.paddlepaddle.org.cn/en/install/quick).
47
+
48
+ 2. PaddleOCR
49
+
50
+ Install the latest version of the PaddleOCR inference package from PyPI:
51
+
52
+ ```bash
53
+ python -m pip install paddleocr
54
+ ```
55
+
56
+ ### Model Usage
57
+
58
+ You can quickly experience the functionality with a single command:
59
+
60
+ ```bash
61
+ paddleocr table_structure_recognition \
62
+ --model_name SLANet \
63
+ -i https://cdn-uploads.huggingface.co/production/uploads/681c1ecd9539bdde5ae1733c/6rfhb-CXOHowonjpBsaUJ.png
64
+ ```
65
+
66
+ You can also integrate the model inference of the table classification module into your project. Before running the following code, please download the sample image to your local machine.
67
+
68
+ ```python
69
+ from paddleocr import TableStructureRecognition
70
+ model = TableStructureRecognition(model_name="SLANet")
71
+ output = model.predict(input="6rfhb-CXOHowonjpBsaUJ.png", batch_size=1)
72
+ for res in output:
73
+ res.print(json_format=False)
74
+ res.save_to_json("./output/res.json")
75
+ ```
76
+
77
+ After running, the obtained result is as follows:
78
+
79
+ ```json
80
+ {'res': {'input_path': '6rfhb-CXOHowonjpBsaUJ.png', 'page_index': None, 'bbox': [[2, 2, 60, 3, 60, 37, 2, 37], [50, 1, 193, 2, 195, 36, 51, 36], [175, 1, 252, 1, 255, 36, 178, 36], [246, 2, 321, 2, 322, 36, 248, 36], [316, 2, 390, 2, 391, 36, 318, 36], [392, 2, 493, 2, 493, 40, 393, 40], [5, 39, 52, 40, 52, 82, 5, 82], [65, 40, 181, 41, 181, 89, 65, 89], [186, 40, 252, 41, 252, 84, 186, 84], [251, 40, 323, 41, 324, 82, 252, 82], [323, 40, 385, 41, 386, 82, 324, 81], [384, 39, 496, 40, 496, 84, 385, 84], [5, 79, 52, 79, 52, 120, 5, 120], [63, 79, 182, 79, 183, 119, 63, 119], [188, 79, 252, 80, 252, 118, 189, 118], [253, 78, 324, 79, 326, 117, 254, 117], [322, 78, 383, 78, 385, 117, 324, 117], [397, 77, 495, 77, 495, 120, 398, 120], [4, 117, 50, 117, 51, 153, 4, 153], [67, 116, 181, 116, 183, 152, 68, 153], [190, 115, 251, 115, 252, 150, 191, 151], [253, 114, 324, 114, 326, 151, 255, 151], [324, 114, 383, 114, 384, 150, 326, 150], [398, 113, 494, 113, 494, 154, 400, 155], [1, 150, 53, 149, 53, 187, 1, 187], [73, 150, 179, 149, 180, 187, 73, 187], [188, 150, 254, 149, 255, 186, 189, 187], [253, 149, 326, 149, 328, 187, 255, 187], [325, 150, 383, 149, 385, 187, 327, 187], [393, 148, 493, 148, 493, 187, 394, 187]], 'structure': ['<html>', '<body>', '<table>', '<tr>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '</tr>', '<tr>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '</tr>', '<tr>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '</tr>', '<tr>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '</tr>', '<tr>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '<td></td>', '</tr>', '</table>', '</body>', '</html>'], 'structure_score': 0.9999815}}
81
+ ```
82
+
83
+ For details about usage command and descriptions of parameters, please refer to the [Document](https://paddlepaddle.github.io/PaddleOCR/main/en/version3.x/module_usage/table_structure_recognition.html#iii-quick-start).
84
+
85
+ ### Pipeline Usage
86
+
87
+ 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.
88
+
89
+ #### General Table Recognition V2 Pipeline
90
+
91
+ The general table recognition V2 pipeline is used to solve table recognition tasks by extracting information from images and outputting it in HTML or Excel format. And there are 8 modules in the pipeline:
92
+ * Table Classification Module
93
+ * Table Structure Recognition Module
94
+ * Table Cell Detection Module
95
+ * Text Detection Module
96
+ * Text Recognition Module
97
+ * Layout Region Detection Module (Optional)
98
+ * Document Image Orientation Classification Module (Optional)
99
+ * Text Image Unwarping Module (Optional)
100
+
101
+ Run a single command to quickly experience the general table recognition V2 pipeline:
102
+
103
+ ```bash
104
+
105
+ paddleocr table_recognition_v2 -i https://cdn-uploads.huggingface.co/production/uploads/681c1ecd9539bdde5ae1733c/mabagznApI1k9R8qFoTLc.png \
106
+ --use_doc_orientation_classify False \
107
+ --use_doc_unwarping False \
108
+ --save_path ./output \
109
+ --device gpu:0
110
+ ```
111
+
112
+ Results are printed to the terminal:
113
+
114
+ ```json
115
+ {'res': {'input_path': 'mabagznApI1k9R8qFoTLc.png', 'page_index': None, 'model_settings': {'use_doc_preprocessor': False, 'use_layout_detection': True, 'use_ocr_model': True}, 'layout_det_res': {'input_path': None, 'page_index': None, 'boxes': [{'cls_id': 8, 'label': 'table', 'score': 0.86655592918396, 'coordinate': [0.0125130415, 0.41920784, 1281.3737, 585.3884]}]}, 'overall_ocr_res': {'input_path': None, 'page_index': None, 'model_settings': {'use_doc_preprocessor': False, 'use_textline_orientation': False}, 'dt_polys': array([[[ 9, 21],
116
+ ...,
117
+ [ 9, 59]],
118
+
119
+ ...,
120
+
121
+ [[1046, 536],
122
+ ...,
123
+ [1046, 573]]], dtype=int16), 'text_det_params': {'limit_side_len': 960, 'limit_type': 'max', 'thresh': 0.3, 'box_thresh': 0.6, 'unclip_ratio': 2.0}, 'text_type': 'general', 'textline_orientation_angles': array([-1, ..., -1]), 'text_rec_score_thresh': 0, 'rec_texts': ['部门', '报销人', '报销事由', '批准人:', '单据', '张', '合计金额', '元', '车费票', '其', '火车费票', '飞机票', '中', '旅住宿费', '其他', '补贴'], 'rec_scores': array([0.99958128, ..., 0.99317062]), 'rec_polys': array([[[ 9, 21],
124
+ ...,
125
+ [ 9, 59]],
126
+
127
+ ...,
128
+
129
+ [[1046, 536],
130
+ ...,
131
+ [1046, 573]]], dtype=int16), 'rec_boxes': array([[ 9, ..., 59],
132
+ ...,
133
+ [1046, ..., 573]], dtype=int16)}, 'table_res_list': [{'cell_box_list': [array([ 0.13052222, ..., 73.08310249]), array([104.43082511, ..., 73.27777413]), array([319.39041221, ..., 73.30439308]), array([424.2436837 , ..., 73.44736794]), array([580.75836265, ..., 73.24003914]), array([723.04370201, ..., 73.22717598]), array([984.67315757, ..., 73.20420387]), array([1.25130415e-02, ..., 5.85419208e+02]), array([984.37072837, ..., 137.02281502]), array([984.26586998, ..., 201.22290352]), array([984.24017417, ..., 585.30775765]), array([1039.90606773, ..., 265.44664314]), array([1039.69549644, ..., 329.30540779]), array([1039.66546714, ..., 393.57319954]), array([1039.5122689 , ..., 457.74644783]), array([1039.55535972, ..., 521.73030403]), array([1039.58612144, ..., 585.09468392])], 'pred_html': '<html><body><table><tbody><tr><td>部门</td><td></td><td>报销人</td><td></td><td>报销事由</td><td></td><td colspan="2">批准人:</td></tr><tr><td colspan="6" rowspan="8"></td><td colspan="2">单据 张</td></tr><tr><td colspan="2">合计金额 元</td></tr><tr><td rowspan="6">其 中</td><td>车费票</td></tr><tr><td>火车费票</td></tr><tr><td>飞机票</td></tr><tr><td>旅住宿费</td></tr><tr><td>其他</td></tr><tr><td>补贴</td></tr></tbody></table></body></html>', 'table_ocr_pred': {'rec_polys': array([[[ 9, 21],
134
+ ...,
135
+ [ 9, 59]],
136
+
137
+ ...,
138
+
139
+ [[1046, 536],
140
+ ...,
141
+ [1046, 573]]], dtype=int16), 'rec_texts': ['部门', '报销人', '报销事由', '批准人:', '单据', '张', '合计金额', '元', '车费票', '其', '火车费票', '飞机票', '中', '旅住宿费', '其他', '补贴'], 'rec_scores': array([0.99958128, ..., 0.99317062]), 'rec_boxes': array([[ 9, ..., 59],
142
+ ...,
143
+ [1046, ..., 573]], dtype=int16)}}]}}
144
+ ```
145
+
146
+ If save_path is specified, the visualization results will be saved under `save_path`. The visualization output is shown below:
147
+
148
+ ![image/jpeg](https://cdn-uploads.huggingface.co/production/uploads/681c1ecd9539bdde5ae1733c/b3mPpaMsK049qxsTbotvI.png)
149
+
150
+ The command-line method is for quick experience. For project integration, also only a few codes are needed as well:
151
+
152
+ ```python
153
+ from paddleocr import TableRecognitionPipelineV2
154
+
155
+ pipeline = TableRecognitionPipelineV2(
156
+ use_doc_orientation_classify=False, # Use use_doc_orientation_classify to enable/disable document orientation classification model
157
+ use_doc_unwarping=False, # Use use_doc_unwarping to enable/disable document unwarping module
158
+ )
159
+ # pipeline = TableRecognitionPipelineV2(use_doc_orientation_classify=True) # Specify whether to use the document orientation classification model with use_doc_orientation_classify
160
+ # pipeline = TableRecognitionPipelineV2(use_doc_unwarping=True) # Specify whether to use the text image unwarping module with use_doc_unwarping
161
+ # pipeline = TableRecognitionPipelineV2(device="gpu") # Specify the device to use GPU for model inference
162
+ output = pipeline.predict("https://cdn-uploads.huggingface.co/production/uploads/681c1ecd9539bdde5ae1733c/mabagznApI1k9R8qFoTLc.png")
163
+ for res in output:
164
+ res.print() ## Print the predicted structured output
165
+ res.save_to_img("./output/")
166
+ res.save_to_xlsx("./output/")
167
+ res.save_to_html("./output/")
168
+ res.save_to_json("./output/")
169
+ ```
170
+
171
+ Then, if you want to use the SLANet model for table recognition, just change the model name and use the end-to-end prediction mode as below:
172
+
173
+ ```bash
174
+ paddleocr table_recognition_v2 -i https://cdn-uploads.huggingface.co/production/uploads/681c1ecd9539bdde5ae1733c/mabagznApI1k9R8qFoTLc.png \
175
+ --use_doc_orientation_classify False \
176
+ --use_doc_unwarping False \
177
+ --wired_table_structure_recognition_model_name SLANet \
178
+ --use_e2e_wired_table_rec_model True \
179
+ --wireless_table_structure_recognition_model_name SLANet \
180
+ --use_e2e_wireless_table_rec_model True \
181
+ --save_path ./output \
182
+ --device gpu:0
183
+ ```
184
+
185
+ ```python
186
+ from paddleocr import TableRecognitionPipelineV2
187
+
188
+ pipeline = TableRecognitionPipelineV2(
189
+ use_doc_orientation_classify=False,
190
+ use_doc_unwarping=False,
191
+ wired_table_structure_recognition_model_name=SLANet, ## for wired table recognition
192
+ wireless_table_structure_recognition_model_name=SLANet, ## for wireless table recognition
193
+ )
194
+ output = pipeline.predict(
195
+ "https://cdn-uploads.huggingface.co/production/uploads/681c1ecd9539bdde5ae1733c/mabagznApI1k9R8qFoTLc.png",
196
+ use_e2e_wired_table_rec_model=True, ## for wired table recognition
197
+ use_e2e_wireless_table_rec_model=True, ## for wireless table recognition
198
+ )
199
+ for res in output:
200
+ res.print() ## Print the predicted structured output
201
+ res.save_to_img("./output/")
202
+ res.save_to_xlsx("./output/")
203
+ res.save_to_html("./output/")
204
+ res.save_to_json("./output/")
205
+ ```
206
+
207
+ 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).
208
+
209
+ #### PP-StructureV3
210
+
211
+ Layout analysis is a technique used to extract structured information from document images. PP-StructureV3 includes the following six modules:
212
+ * Layout Detection Module
213
+ * General OCR Pipeline
214
+ * Document Image Preprocessing Pipeline (Optional)
215
+ * Table Recognition Pipeline (Optional)
216
+ * Seal Recognition Pipeline (Optional)
217
+ * Formula Recognition Pipeline (Optional)
218
+
219
+ Run a single command to quickly experience the PP-StructureV3 pipeline:
220
+
221
+ ```bash
222
+ paddleocr pp_structurev3 -i https://cdn-uploads.huggingface.co/production/uploads/681c1ecd9539bdde5ae1733c/mG4tnwfrvECoFMu-S9mxo.png \
223
+ --use_doc_orientation_classify False \
224
+ --use_doc_unwarping False \
225
+ --wired_table_structure_recognition_model_name SLANet \
226
+ --use_e2e_wired_table_rec_model True \
227
+ --wireless_table_structure_recognition_model_name SLANet \
228
+ --use_e2e_wireless_table_rec_model True \
229
+ --use_textline_orientation False \
230
+ --device gpu:0
231
+ ```
232
+
233
+ Results would be printed to the terminal. If save_path is specified, the results will be saved under `save_path`.
234
+
235
+ Just a few lines of code can experience the inference of the pipeline. Taking the PP-StructureV3 pipeline as an example:
236
+
237
+ ```python
238
+ from paddleocr import PPStructureV3
239
+
240
+ pipeline = PPStructureV3(
241
+ wired_table_structure_recognition_model_name=SLANet, ## for wired table recognition
242
+ wireless_table_structure_recognition_model_name=SLANet, ## for wireless table recognition
243
+ use_doc_orientation_classify=False, # Use use_doc_orientation_classify to enable/disable document orientation classification model
244
+ use_doc_unwarping=False, # Use use_doc_unwarping to enable/disable document unwarping module
245
+ use_textline_orientation=False, # Use use_textline_orientation to enable/disable textline orientation classification model
246
+ device="gpu:0", # Use device to specify GPU for model inference
247
+ )
248
+ output = pipeline.predict(
249
+ "mG4tnwfrvECoFMu-S9mxo.png",
250
+ use_e2e_wired_table_rec_model=True, ## for wired table recognition
251
+ use_e2e_wireless_table_rec_model=True, ## for wireless table recognition
252
+ )
253
+ for res in output:
254
+ res.print() # Print the structured prediction output
255
+ res.save_to_json(save_path="output") ## Save the current image's structured result in JSON format
256
+ res.save_to_markdown(save_path="output") ## Save the current image's result in Markdown format
257
+ ```
258
+
259
+ The default model used in pipeline is `SLANeXt_wired` and `SLANeXt_wireless`, so it is needed that specifing to `SLANet` by argument. 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).
260
+
261
+ ## Links
262
+
263
+ [PaddleOCR Repo](https://github.com/paddlepaddle/paddleocr)
264
+
265
+ [PaddleOCR Documentation](https://paddlepaddle.github.io/PaddleOCR/latest/en/index.html)
266
+