Tingquan commited on
Commit
522d1e8
·
verified ·
1 Parent(s): d57ac8c

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +127 -0
README.md ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ ---
4
+
5
+ # PP-DocLayout-S
6
+
7
+ ## Introduction
8
+
9
+ A high-efficiency layout area localization model trained on a self-built dataset containing Chinese and English papers, magazines, contracts, books, exams, and research reports using PicoDet-S. capable of detecting 23 common categories: document title, paragraph title, text, page number, abstract, table of contents, references, footnotes, header, footer, algorithm, formula, formula number, image, figure caption, table, table caption, seal, figure title, figure, header image, footer image, and aside text. The key metrics are as follow:
10
+
11
+ | Model| mAP(0.5) (%) |
12
+ | --- | --- |
13
+ |PP-DocLayout-S | 70.9 |
14
+
15
+ **Note**: the evaluation set of the above accuracy indicators is a self built layout area detection data set, including 500 document type images such as Chinese and English papers, newspapers, research papers and test papers.
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 PP-DocLayout-S \
54
+ -i https://cdn-uploads.huggingface.co/production/uploads/63d7b8ee07cd1aa3c49a2026/N5C68HPVAI-xQAWTxpbA6.jpeg
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="PP-DocLayout-S")
63
+ output = model.predict("N5C68HPVAI-xQAWTxpbA6.jpeg", 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': '/root/.paddlex/predict_input/N5C68HPVAI-xQAWTxpbA6.jpeg', 'page_index': None, 'boxes': [{'cls_id': 2, 'label': 'text', 'score': 0.9695586562156677, 'coordinate': [33.89038, 646.9188, 359.24533, 849.0932]}, {'cls_id': 2, 'label': 'text', 'score': 0.967388927936554, 'coordinate': [384.86646, 735.1845, 712.85364, 850.4103]}, {'cls_id': 2, 'label': 'text', 'score': 0.9618191123008728, 'coordinate': [386.01096, 495.6391, 712.27875, 695.3851]}, {'cls_id': 2, 'label': 'text', 'score': 0.961749792098999, 'coordinate': [32.8393, 349.90964, 360.12332, 612.03687]}, {'cls_id': 8, 'label': 'table', 'score': 0.9275020360946655, 'coordinate': [438.0261, 106.43789, 663.54443, 313.9396]}, {'cls_id': 8, 'label': 'table', 'score': 0.9272584319114685, 'coordinate': [74.408966, 107.16657, 319.52042, 300.95004]}, {'cls_id': 2, 'label': 'text', 'score': 0.7687780261039734, 'coordinate': [386.9146, 20.052937, 711.3798, 75.4542]}, {'cls_id': 2, 'label': 'text', 'score': 0.7498785853385925, 'coordinate': [34.74602, 19.907455, 359.0445, 76.057304]}, {'cls_id': 0, 'label': 'paragraph_title', 'score': 0.7419086694717407, 'coordinate': [386.08258, 715.97784, 525.2569, 729.5398]}, {'cls_id': 0, 'label': 'paragraph_title', 'score': 0.7388646602630615, 'coordinate': [35.2029, 331.77637, 141.53833, 344.5923]}, {'cls_id': 0, 'label': 'paragraph_title', 'score': 0.6813259124755859, 'coordinate': [37.83614, 629.0971, 185.95276, 640.6417]}, {'cls_id': 2, 'label': 'text', 'score': 0.6515917778015137, 'coordinate': [385.31564, 346.86404, 712.0084, 460.2663]}, {'cls_id': 0, 'label': 'paragraph_title', 'score': 0.5848217606544495, 'coordinate': [384.1938, 477.32938, 706.8187, 491.30426]}]}}
74
+ ```
75
+
76
+ The visualized image is as follows:
77
+
78
+ ![image/jpeg](https://cdn-uploads.huggingface.co/production/uploads/63d7b8ee07cd1aa3c49a2026/uYUJouAHxLx0FC0vjsQpC.jpeg)
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 scenarios.
85
+
86
+ #### PP-StructureV3
87
+
88
+ Layout analysis is a technique used to extract structured information from document images. PP-StructureV3 includes the following six modules:
89
+ * Layout Detection Module
90
+ * General OCR Sub-pipeline
91
+ * Document Image Preprocessing Sub-pipeline (Optional)
92
+ * Table Recognition Sub-pipeline (Optional)
93
+ * Seal Recognition Sub-pipeline (Optional)
94
+ * Formula Recognition Sub-pipeline (Optional)
95
+
96
+ You can quickly experience the PP-StructureV3 pipeline with a single command.
97
+
98
+ ```bash
99
+ paddleocr pp_structurev3 --layout_detection_model_name PP-DocLayout-S -i https://cdn-uploads.huggingface.co/production/uploads/63d7b8ee07cd1aa3c49a2026/KP10tiSZfAjMuwZUSLtRp.png
100
+ ```
101
+
102
+ You can experience the inference of the pipeline with just a few lines of code. Taking the PP-StructureV3 pipeline as an example:
103
+
104
+ ```python
105
+ from paddleocr import PPStructureV3
106
+
107
+ pipeline = PPStructureV3(layout_detection_model_name="PP-DocLayout-S")
108
+ # ocr = PPStructureV3(use_doc_orientation_classify=True) # Use use_doc_orientation_classify to enable/disable document orientation classification model
109
+ # ocr = PPStructureV3(use_doc_unwarping=True) # Use use_doc_unwarping to enable/disable document unwarping module
110
+ # ocr = PPStructureV3(use_textline_orientation=True) # Use use_textline_orientation to enable/disable textline orientation classification model
111
+ # ocr = PPStructureV3(device="gpu") # Use device to specify GPU for model inference
112
+ output = pipeline.predict("./KP10tiSZfAjMuwZUSLtRp.png")
113
+ for res in output:
114
+ res.print() ## Print the structured prediction output
115
+ res.save_to_json(save_path="output") ## Save the current image's structured result in JSON format
116
+ res.save_to_markdown(save_path="output") ## Save the current image's result in Markdown format
117
+ ```
118
+
119
+ The default model used in pipeline is `PP-DocLayout_plus-L`, so it is needed that specifing to `PP-DocLayout-S` by argument `layout_detection_model_name`. And you can also use the local model file by argument `layout_detection_model_dir`.
120
+ 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).
121
+
122
+ ## Links
123
+
124
+ [PaddleOCR Repo](https://github.com/paddlepaddle/paddleocr)
125
+
126
+ [PaddleOCR Documentation](https://paddlepaddle.github.io/PaddleOCR/latest/en/index.html)
127
+