Tingquan commited on
Commit
05efeba
·
verified ·
1 Parent(s): b0ad0a1

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +139 -0
README.md ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ ---
4
+
5
+ # PicoDet_layout_1x
6
+
7
+ ## Introduction
8
+
9
+ A high-efficiency layout area localization model trained on a self-built dataset using PicoDet-1x, capable of detecting 5-Class english document area, including Text, Title, Table, Figure, and List. The key metrics are as follow:
10
+
11
+ | Model| mAP(0.5) (%) |
12
+ | --- | --- |
13
+ |PicoDet_layout_1x | 97.8 |
14
+
15
+
16
+
17
+ ## Quick Start
18
+
19
+ ### Installation
20
+
21
+ 1. PaddlePaddle
22
+
23
+ Please refer to the following commands to install PaddlePaddle using pip:
24
+
25
+ ```bash
26
+ # for CUDA11.8
27
+ python -m pip install paddlepaddle-gpu==3.0.0 -i https://www.paddlepaddle.org.cn/packages/stable/cu118/
28
+
29
+ # for CUDA12.6
30
+ python -m pip install paddlepaddle-gpu==3.0.0 -i https://www.paddlepaddle.org.cn/packages/stable/cu126/
31
+
32
+ # for CPU
33
+ python -m pip install paddlepaddle==3.0.0 -i https://www.paddlepaddle.org.cn/packages/stable/cpu/
34
+ ```
35
+
36
+ For details about PaddlePaddle installation, please refer to the [PaddlePaddle official website](https://www.paddlepaddle.org.cn/en/install/quick).
37
+
38
+ 2. PaddleOCR
39
+
40
+ Install the latest version of the PaddleOCR inference package from PyPI:
41
+
42
+ ```bash
43
+ python -m pip install paddleocr
44
+ ```
45
+
46
+
47
+ ### Model Usage
48
+
49
+ You can quickly experience the functionality with a single command:
50
+
51
+ ```bash
52
+ paddleocr layout_detection \
53
+ --model_name PicoDet_layout_1x \
54
+ -i https://cdn-uploads.huggingface.co/production/uploads/63d7b8ee07cd1aa3c49a2026/-oU2IpNLcA0gTMJ34wDBR.png
55
+ ```
56
+
57
+ 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.
58
+
59
+ ```python
60
+ from paddleocr import LayoutDetection
61
+
62
+ model = LayoutDetection(model_name="PicoDet_layout_1x")
63
+ output = model.predict("-oU2IpNLcA0gTMJ34wDBR.png", batch_size=1, layout_nms=True)
64
+ for res in output:
65
+ res.print()
66
+ res.save_to_img(save_path="./output/")
67
+ res.save_to_json(save_path="./output/res.json")
68
+ ```
69
+
70
+ After running, the obtained result is as follows:
71
+
72
+ ```json
73
+ {'res': {'input_path': '-oU2IpNLcA0gTMJ34wDBR.png', 'page_index': None, 'boxes': [{'cls_id': 0, 'label': 'Text', 'score': 0.9922339916229248, 'coordinate': [84.18926, 1248.3407, 583.2205, 1582.3639]}, {'cls_id': 0, 'label': 'Text', 'score': 0.991148829460144, 'coordinate': [606.0175, 1209.0277, 1105.669, 1538.559]}, {'cls_id': 0, 'label': 'Text', 'score': 0.989486813545227, 'coordinate': [84.11199, 710.821, 582.4992, 1208.4802]}, {'cls_id': 0, 'label': 'Text', 'score': 0.9823781847953796, 'coordinate': [605.9509, 951.964, 1105.8907, 1089.925]}, {'cls_id': 3, 'label': 'Table', 'score': 0.98123699426651, 'coordinate': [608.91614, 301.1981, 1111.2635, 805.45233]}, {'cls_id': 4, 'label': 'Figure', 'score': 0.971710741519928, 'coordinate': [84.329, 200.35394, 577.5106, 681.766]}, {'cls_id': 0, 'label': 'Text', 'score': 0.950641930103302, 'coordinate': [607.27435, 826.2146, 1107.0017, 911.43726]}, {'cls_id': 0, 'label': 'Text', 'score': 0.9468774795532227, 'coordinate': [605.6758, 197.66481, 1105.3107, 265.3606]}, {'cls_id': 1, 'label': 'Title', 'score': 0.86313396692276, 'coordinate': [606.6188, 1170.0265, 827.1196, 1192.0656]}, {'cls_id': 1, 'label': 'Title', 'score': 0.8427881002426147, 'coordinate': [605.2791, 1131.709, 823.0802, 1152.363]}, {'cls_id': 0, 'label': 'Text', 'score': 0.5990690588951111, 'coordinate': [625.3928, 1558.7576, 849.12946, 1583.5391]}]}}
74
+ ```
75
+
76
+ The visualized image is as follows:
77
+
78
+ ![image/jpeg](https://cdn-uploads.huggingface.co/production/uploads/63d7b8ee07cd1aa3c49a2026/syzCGwEeqaZ6nqM_u8Qs5.png)
79
+
80
+ 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).
81
+
82
+ ### Pipeline Usage
83
+
84
+ 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 scenJust a few lines of code can experience the inference of the pipelinearios.
85
+
86
+ #### PP-TableMagic (table_recognition_v2)
87
+
88
+ 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:
89
+
90
+ * Table Structure Recognition Module
91
+ * Table Classification Module
92
+ * Table Cell Detection Module
93
+ * Text Detection Module
94
+ * Text Recognition Module
95
+ * Layout Region Detection Module (optional)
96
+ * Document Image Orientation Classification Module (optional)
97
+ * Text Image Unwarping Module (optional)
98
+
99
+ You can quickly experience the PP-TableMagic pipeline with a single command.
100
+
101
+ ```bash
102
+ paddleocr table_recognition_v2 -i https://cdn-uploads.huggingface.co/production/uploads/63d7b8ee07cd1aa3c49a2026/-oU2IpNLcA0gTMJ34wDBR.png \
103
+ --layout_detection_model_name PicoDet_layout_1x \
104
+ --use_doc_orientation_classify False \
105
+ --use_doc_unwarping False \
106
+ --save_path ./output \
107
+ --device gpu:0
108
+
109
+ ```
110
+
111
+ You can also integrate the PP-TableMagic pipeline into your project. Before running the following code, please download the sample image to your local machine.
112
+
113
+ ```python
114
+ from paddleocr import TableRecognitionPipelineV2
115
+
116
+ pipeline = TableRecognitionPipelineV2(
117
+ layout_detection_model_name=PicoDet_layout_1x,
118
+ use_doc_orientation_classify=False, # Use use_doc_orientation_classify to enable/disable document orientation classification model
119
+ use_doc_unwarping=False, # Use use_doc_unwarping to enable/disable document unwarping module
120
+ device="gpu:0", # Use device to specify GPU for model inference
121
+ )
122
+
123
+ output = pipeline.predict("-oU2IpNLcA0gTMJ34wDBR.png")
124
+ for res in output:
125
+ res.print() ## Print the predicted structured output
126
+ res.save_to_img("./output/")
127
+ res.save_to_xlsx("./output/")
128
+ res.save_to_html("./output/")
129
+ res.save_to_json("./output/")
130
+ ```
131
+
132
+ The default model used in pipeline is `PP-DocLayout-L`, so it is needed that specifing to `PicoDet_layout_1x` 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).
133
+
134
+ ## Links
135
+
136
+ [PaddleOCR Repo](https://github.com/paddlepaddle/paddleocr)
137
+
138
+ [PaddleOCR Documentation](https://paddlepaddle.github.io/PaddleOCR/latest/en/index.html)
139
+