Tingquan commited on
Commit
37f2279
·
verified ·
1 Parent(s): 99e3068

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +175 -0
README.md ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ ---
4
+
5
+ # PicoDet-S_layout_3cls
6
+
7
+ ## Introduction
8
+
9
+ A high-efficiency layout area localization model trained on a self-built dataset of Chinese and English papers, magazines, and research reports using PicoDet-S. It supports 3 types of layout areas: table, figure, and seal.
10
+
11
+ | Model| mAP(0.5) (%) |
12
+ | --- | --- |
13
+ |PicoDet-S_layout_3cls | 88.2 |
14
+
15
+ **Note**: Paddleocr's self built layout area detection data set contains 1154 common document type images such as Chinese and English papers, magazines and research 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
+ ### Model Usage
47
+
48
+ You can quickly experience the functionality with a single command:
49
+
50
+ ```bash
51
+ paddleocr layout_detection --model_name PicoDet-S_layout_3cls --threshold 0.6 -i https://cdn-uploads.huggingface.co/production/uploads/63d7b8ee07cd1aa3c49a2026/N5C68HPVAI-xQAWTxpbA6.jpeg
52
+ ```
53
+
54
+ You can also integrate the model inference of the LayoutDetection module into your project. Before running the following code, please download the sample image to your local machine.
55
+
56
+ ```python
57
+ from paddleocr import LayoutDetection
58
+
59
+ model = LayoutDetection(model_name="PicoDet-S_layout_3cls")
60
+ output = model.predict("N5C68HPVAI-xQAWTxpbA6.jpeg", batch_size=1, layout_nms=True)
61
+ for res in output:
62
+ res.print()
63
+ res.save_to_img(save_path="./output/")
64
+ res.save_to_json(save_path="./output/res.json")
65
+ ```
66
+
67
+ After running, the obtained result is as follows:
68
+
69
+ ```json
70
+ {'res': {'input_path': '/root/.paddlex/predict_input/N5C68HPVAI-xQAWTxpbA6.jpeg', 'page_index': None, 'boxes': [{'cls_id': 1, 'label': 'table', 'score': 0.9367532134056091, 'coordinate': [74.82668, 106.17916, 322.33493, 300.35388]}, {'cls_id': 1, 'label': 'table', 'score': 0.9143182039260864, 'coordinate': [437.6252, 105.94054, 664.5405, 315.0713]}]}}
71
+ ```
72
+
73
+ The visualized image is as follows:
74
+
75
+ ![image/jpeg](https://cdn-uploads.huggingface.co/production/uploads/63d7b8ee07cd1aa3c49a2026/Smz6s33SNQDwgGumNrLMu.jpeg)
76
+
77
+ 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).
78
+
79
+ ### Pipeline Usage
80
+
81
+ 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.
82
+
83
+ #### PP-ChatOCRv4-doc
84
+
85
+ PP-ChatOCRv4-doc is a unique document and image intelligent analysis solution from PaddlePaddle, combining LLM, MLLM, and OCR technologies to address complex document information extraction challenges such as layout analysis, rare characters, multi-page PDFs, tables, and seal recognition. Integrated with ERNIE Bot, it fuses massive data and knowledge, achieving high accuracy and wide applicability.
86
+
87
+ The Document Scene Information Extraction v4 pipeline includes modules for Layout Region Detection, Table Structure Recognition, Table Classification, Table Cell Localization, Text Detection, Text Recognition, Seal Text Detection, Text Image Rectification, and Document Image Orientation Classification.
88
+
89
+
90
+ You can quickly experience the PP-ChatOCRv4-doc pipeline with a single command.
91
+
92
+ ```bash
93
+ paddleocr pp_chatocrv4_doc -i vehicle_certificate-1.png -k 驾驶室准乘人数 --qianfan_api_key your_api_key --layout_detection_model_name PicoDet-S_layout_3cls
94
+
95
+ ```
96
+
97
+ If save_path is specified, the visualization results will be saved under `save_path`.
98
+
99
+ The command-line method is for quick experience. For project integration, also only a few codes are needed as well:
100
+
101
+
102
+ ```python
103
+ from paddleocr import PPChatOCRv4Doc
104
+
105
+ chat_bot_config = {
106
+ "module_name": "chat_bot",
107
+ "model_name": "ernie-3.5-8k",
108
+ "base_url": "https://qianfan.baidubce.com/v2",
109
+ "api_type": "openai",
110
+ "api_key": "api_key", # your api_key
111
+ }
112
+
113
+ retriever_config = {
114
+ "module_name": "retriever",
115
+ "model_name": "embedding-v1",
116
+ "base_url": "https://qianfan.baidubce.com/v2",
117
+ "api_type": "qianfan",
118
+ "api_key": "api_key", # your api_key
119
+ }
120
+
121
+ mllm_chat_bot_config = {
122
+ "module_name": "chat_bot",
123
+ "model_name": "PP-DocBee2",
124
+ "base_url": "http://127.0.0.1:8080/", # your local mllm service url
125
+ "api_type": "openai",
126
+ "api_key": "api_key", # your api_key
127
+ }
128
+
129
+ pipeline = PPChatOCRv4Doc(
130
+ layout_detection_model_name="PicoDet-S_layout_3cls",
131
+ )
132
+
133
+ visual_predict_res = pipeline.visual_predict(
134
+ input="vehicle_certificate-1.png",
135
+ use_doc_orientation_classify=False,
136
+ use_doc_unwarping=False,
137
+ use_common_ocr=True,
138
+ use_seal_recognition=True,
139
+ use_table_recognition=True,
140
+ )
141
+
142
+ visual_info_list = []
143
+ for res in visual_predict_res:
144
+ visual_info_list.append(res["visual_info"])
145
+ layout_parsing_result = res["layout_parsing_result"]
146
+
147
+ vector_info = pipeline.build_vector(
148
+ visual_info_list, flag_save_bytes_vector=True, retriever_config=retriever_config
149
+ )
150
+ mllm_predict_res = pipeline.mllm_pred(
151
+ input="vehicle_certificate-1.png",
152
+ key_list=["驾驶室准乘人数"],
153
+ mllm_chat_bot_config=mllm_chat_bot_config,
154
+ )
155
+ mllm_predict_info = mllm_predict_res["mllm_res"]
156
+ chat_result = pipeline.chat(
157
+ key_list=["驾驶室准乘人数"],
158
+ visual_info=visual_info_list,
159
+ vector_info=vector_info,
160
+ mllm_predict_info=mllm_predict_info,
161
+ chat_bot_config=chat_bot_config,
162
+ retriever_config=retriever_config,
163
+ )
164
+ print(chat_result)
165
+ ```
166
+
167
+ The default model used in pipeline is `RT-DETR-H_layout_3cls`, so it is needed that specifing to `PicoDet-S_layout_3cls` 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/PP-ChatOCRv4.html#2-quick-start).
168
+
169
+
170
+
171
+ ## Links
172
+
173
+ [PaddleOCR Repo](https://github.com/paddlepaddle/paddleocr)
174
+
175
+ [PaddleOCR Documentation](https://paddlepaddle.github.io/PaddleOCR/latest/en/index.html)