Tingquan commited on
Commit
43eefa9
·
verified ·
1 Parent(s): 1f85e7d

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +224 -0
README.md ADDED
@@ -0,0 +1,224 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ ---
4
+
5
+ # PP-LCNet_x1_0_table_cls
6
+
7
+ ## Introduction
8
+
9
+ The Table Classification Module is a key component in computer vision systems, responsible for classifying input table images. The performance of this module directly affects the accuracy and efficiency of the entire table recognition process. The Table Classification Module typically receives table images as input and, using deep learning algorithms, classifies them into predefined categories based on the characteristics and content of the images, such as wired and wireless tables. The classification results from the Table Classification Module serve as output for use in table recognition pipelines. The key metrics are as follow:
10
+
11
+ <table>
12
+ <tr>
13
+ <th>Model</th>
14
+ <th>Top1 Acc(%)</th>
15
+ <th>GPU Inference Time (ms)<br/>[Regular Mode / High-Performance Mode]</th>
16
+ <th>CPU Inference Time (ms)<br/>[Regular Mode / High-Performance Mode]</th>
17
+ <th>Model Storage Size (M)</th>
18
+ </tr>
19
+ <tr>
20
+ <td>PP-LCNet_x1_0_table_cls</td>
21
+ <td>94.2</td>
22
+ <td>2.35 / 0.47</td>
23
+ <td>4.03 / 1.35</td>
24
+ <td>6.6M</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_classification \
62
+ -i https://cdn-uploads.huggingface.co/production/uploads/681c1ecd9539bdde5ae1733c/6rfhb-CXOHowonjpBsaUJ.png
63
+ ```
64
+
65
+ 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.
66
+
67
+ ```python
68
+ from paddleocr import TableClassification
69
+ model = TableClassification(model_name="PP-LCNet_x1_0_table_cls")
70
+ output = model.predict("mabagznApI1k9R8qFoTLc.png", batch_size=1)
71
+ for res in output:
72
+ res.print(json_format=False)
73
+ res.save_to_json("./output/res.json")
74
+ res.save_to_img("./output/res.png")
75
+ ```
76
+
77
+ After running, the obtained result is as follows:
78
+
79
+ ```json
80
+ {'res': {'input_path': 'mabagznApI1k9R8qFoTLc.png', 'page_index': None, 'class_ids': array([1, 0], dtype=int32), 'scores': array([0.79982, 0.20018], dtype=float32), 'label_names': ['wireless_table', 'wired_table']}}
81
+ ```
82
+
83
+ The visualized image is as follows:
84
+
85
+ ![image/jpeg](https://cdn-uploads.huggingface.co/production/uploads/681c1ecd9539bdde5ae1733c/h_ThLpcpkLr5JevT2-xWp.png)
86
+
87
+ 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/text_recognition.html#iii-quick-start).
88
+
89
+ ### Pipeline Usage
90
+
91
+ 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.
92
+
93
+ #### General Table Recognition V2 Pipeline
94
+
95
+ 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:
96
+ * Table Classification Module
97
+ * Table Structure Recognition Module
98
+ * Table Cell Detection Module
99
+ * Text Detection Module
100
+ * Text Recognition Module
101
+ * Layout Region Detection Module (Optional)
102
+ * Document Image Orientation Classification Module (Optional)
103
+ * Text Image Unwarping Module (Optional)
104
+
105
+ Run a single command to quickly experience the general table recognition V2 pipeline:
106
+
107
+ ```bash
108
+
109
+ paddleocr table_recognition_v2 -i https://cdn-uploads.huggingface.co/production/uploads/681c1ecd9539bdde5ae1733c/mabagznApI1k9R8qFoTLc.png \
110
+ --use_doc_orientation_classify False \
111
+ --use_doc_unwarping False \
112
+ --save_path ./output \
113
+ --device gpu:0
114
+ ```
115
+
116
+ Results are printed to the terminal:
117
+
118
+ ```json
119
+ {'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],
120
+ ...,
121
+ [ 9, 59]],
122
+
123
+ ...,
124
+
125
+ [[1046, 536],
126
+ ...,
127
+ [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],
128
+ ...,
129
+ [ 9, 59]],
130
+
131
+ ...,
132
+
133
+ [[1046, 536],
134
+ ...,
135
+ [1046, 573]]], dtype=int16), 'rec_boxes': array([[ 9, ..., 59],
136
+ ...,
137
+ [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],
138
+ ...,
139
+ [ 9, 59]],
140
+
141
+ ...,
142
+
143
+ [[1046, 536],
144
+ ...,
145
+ [1046, 573]]], dtype=int16), 'rec_texts': ['部门', '报销人', '报销事由', '批准人:', '单据', '张', '合计金额', '元', '车费票', '其', '火车费票', '飞机票', '中', '旅住宿费', '其他', '补贴'], 'rec_scores': array([0.99958128, ..., 0.99317062]), 'rec_boxes': array([[ 9, ..., 59],
146
+ ...,
147
+ [1046, ..., 573]], dtype=int16)}}]}}
148
+ ```
149
+
150
+ If save_path is specified, the visualization results will be saved under `save_path`. The visualization output is shown below:
151
+
152
+ ![image/jpeg](https://cdn-uploads.huggingface.co/production/uploads/681c1ecd9539bdde5ae1733c/b3mPpaMsK049qxsTbotvI.png)
153
+
154
+ The command-line method is for quick experience. For project integration, also only a few codes are needed as well:
155
+
156
+ ```python
157
+ from paddleocr import TableRecognitionPipelineV2
158
+
159
+ pipeline = TableRecognitionPipelineV2(
160
+ use_doc_orientation_classify=False, # Use use_doc_orientation_classify to enable/disable document orientation classification model
161
+ use_doc_unwarping=False, # Use use_doc_unwarping to enable/disable document unwarping module
162
+ )
163
+ # pipeline = TableRecognitionPipelineV2(use_doc_orientation_classify=True) # Specify whether to use the document orientation classification model with use_doc_orientation_classify
164
+ # pipeline = TableRecognitionPipelineV2(use_doc_unwarping=True) # Specify whether to use the text image unwarping module with use_doc_unwarping
165
+ # pipeline = TableRecognitionPipelineV2(device="gpu") # Specify the device to use GPU for model inference
166
+ output = pipeline.predict("https://cdn-uploads.huggingface.co/production/uploads/681c1ecd9539bdde5ae1733c/mabagznApI1k9R8qFoTLc.png")
167
+ for res in output:
168
+ res.print() ## Print the predicted structured output
169
+ res.save_to_img("./output/")
170
+ res.save_to_xlsx("./output/")
171
+ res.save_to_html("./output/")
172
+ res.save_to_json("./output/")
173
+ ```
174
+
175
+ 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).
176
+
177
+ #### PP-StructureV3
178
+
179
+ Layout analysis is a technique used to extract structured information from document images. PP-StructureV3 includes the following six modules:
180
+ * Layout Detection Module
181
+ * General OCR Pipeline
182
+ * Document Image Preprocessing Pipeline (Optional)
183
+ * Table Recognition Pipeline (Optional)
184
+ * Seal Recognition Pipeline (Optional)
185
+ * Formula Recognition Pipeline (Optional)
186
+
187
+ Run a single command to quickly experience the PP-StructureV3 pipeline:
188
+
189
+ ```bash
190
+ paddleocr pp_structurev3 -i https://cdn-uploads.huggingface.co/production/uploads/681c1ecd9539bdde5ae1733c/mG4tnwfrvECoFMu-S9mxo.png \
191
+ --use_doc_orientation_classify False \
192
+ --use_doc_unwarping False \
193
+ --use_textline_orientation False \
194
+ --device gpu:0
195
+ ```
196
+
197
+ Results would be printed to the terminal. If save_path is specified, the results will be saved under `save_path`.
198
+
199
+ Just a few lines of code can experience the inference of the pipeline. Taking the PP-StructureV3 pipeline as an example:
200
+
201
+ ```python
202
+ from paddleocr import PPStructureV3
203
+
204
+ pipeline = PPStructureV3(
205
+ use_doc_orientation_classify=False, # Use use_doc_orientation_classify to enable/disable document orientation classification model
206
+ use_doc_unwarping=False, # Use use_doc_unwarping to enable/disable document unwarping module
207
+ use_textline_orientation=False, # Use use_textline_orientation to enable/disable textline orientation classification model
208
+ device="gpu:0", # Use device to specify GPU for model inference
209
+ )
210
+ output = pipeline.predict("mG4tnwfrvECoFMu-S9mxo.png")
211
+ for res in output:
212
+ res.print() # Print the structured prediction output
213
+ res.save_to_json(save_path="output") ## Save the current image's structured result in JSON format
214
+ res.save_to_markdown(save_path="output") ## Save the current image's result in Markdown format
215
+ ```
216
+
217
+ 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).
218
+
219
+ ## Links
220
+
221
+ [PaddleOCR Repo](https://github.com/paddlepaddle/paddleocr)
222
+
223
+ [PaddleOCR Documentation](https://paddlepaddle.github.io/PaddleOCR/latest/en/index.html)
224
+