Tingquan commited on
Commit
0feae4e
·
verified ·
1 Parent(s): a3b9cc1

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +166 -0
README.md ADDED
@@ -0,0 +1,166 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ ---
4
+
5
+ # PP-OCRv4_mobile_seal_det
6
+
7
+ ## Introduction
8
+
9
+ The mobile-side seal text detection model of PP-OCRv4, on the other hand, offers greater efficiency and is suitable for deployment on end devices. The key accuracy metrics are as follow:
10
+
11
+
12
+ | Model| Hmean (%) |
13
+ | --- | --- |
14
+ |PP-OCRv4_mobile_seal_det | 96.47 |
15
+
16
+
17
+ **Note**: The metric is based on PaddleX Custom Test Dataset, Containing 500 Images of Circular Stamps.
18
+
19
+ ## Quick Start
20
+
21
+ ### Installation
22
+
23
+ 1. PaddlePaddle
24
+
25
+ Please refer to the following commands to install PaddlePaddle using pip:
26
+
27
+ ```bash
28
+ # for CUDA11.8
29
+ python -m pip install paddlepaddle-gpu==3.0.0 -i https://www.paddlepaddle.org.cn/packages/stable/cu118/
30
+
31
+ # for CUDA12.6
32
+ python -m pip install paddlepaddle-gpu==3.0.0 -i https://www.paddlepaddle.org.cn/packages/stable/cu126/
33
+
34
+ # for CPU
35
+ python -m pip install paddlepaddle==3.0.0 -i https://www.paddlepaddle.org.cn/packages/stable/cpu/
36
+ ```
37
+
38
+ For details about PaddlePaddle installation, please refer to the [PaddlePaddle official website](https://www.paddlepaddle.org.cn/en/install/quick).
39
+
40
+ 2. PaddleOCR
41
+
42
+ Install the latest version of the PaddleOCR inference package from PyPI:
43
+
44
+ ```bash
45
+ python -m pip install paddleocr
46
+ ```
47
+
48
+ ### Model Usage
49
+
50
+ You can quickly experience the functionality with a single command:
51
+
52
+ ```bash
53
+ paddleocr seal_text_detection \
54
+ --model_name PP-OCRv4_mobile_seal_det \
55
+ -i https://cdn-uploads.huggingface.co/production/uploads/63d7b8ee07cd1aa3c49a2026/k02u35x60XZmaL9hzeQ0T.png
56
+ ```
57
+
58
+ You can also integrate the model inference of the seal text detection module into your project. Before running the following code, please download the sample image to your local machine.
59
+
60
+ ```python
61
+ from paddleocr import SealTextDetection
62
+ model = SealTextDetection(model_name="PP-OCRv4_mobile_seal_det")
63
+ output = model.predict(input="k02u35x60XZmaL9hzeQ0T.png", batch_size=1)
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/k02u35x60XZmaL9hzeQ0T.png', 'page_index': None, 'dt_polys': [array([[463, 477],
74
+ ...,
75
+ [428, 505]]), array([[297, 444],
76
+ ...,
77
+ [230, 443]]), array([[457, 346],
78
+ ...,
79
+ [267, 345]]), array([[325, 38],
80
+ ...,
81
+ [322, 37]])], 'dt_scores': [0.9912813174046151, 0.9906722305163783, 0.9847175812219835, 0.9914792941713804]}}
82
+ ```
83
+
84
+ The visualized image is as follows:
85
+
86
+ ![image/jpeg](https://cdn-uploads.huggingface.co/production/uploads/63d7b8ee07cd1aa3c49a2026/dMn6pbpIIGG8CqycfqsDb.png)
87
+
88
+ 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/seal_text_detection.html#iii-quick-start).
89
+
90
+ ### Pipeline Usage
91
+
92
+ 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.
93
+
94
+ #### Seal Text Recognition Pipeline
95
+
96
+ Seal text recognition is a technology that automatically extracts and recognizes the content of seals from documents or images. The recognition of seal text is part of document processing and has many applications in various scenarios, such as contract comparison, warehouse entry and exit review, and invoice reimbursement review.And there are 5 modules in the pipeline:
97
+
98
+ * Seal Text Detection Module
99
+ * Text Recognition Module
100
+ * Layout Detection Module (Optional)
101
+ * Document Image Orientation Classification Module (Optional)
102
+ * Text Image Unwarping Module (Optional)
103
+
104
+ Run a single command to quickly experience the OCR pipeline:
105
+
106
+ ```bash
107
+ paddleocr seal_recognition -i https://cdn-uploads.huggingface.co/production/uploads/63d7b8ee07cd1aa3c49a2026/k02u35x60XZmaL9hzeQ0T.png \
108
+ --seal_text_detection_model_name PP-OCRv4_mobile_seal_det \
109
+ --use_doc_orientation_classify False \
110
+ --use_doc_unwarping False \
111
+ --save_path ./output \
112
+ --device gpu:0
113
+ ```
114
+
115
+ Results are printed to the terminal:
116
+
117
+ ```json
118
+ {'res': {'input_path': '/root/.paddlex/predict_input/k02u35x60XZmaL9hzeQ0T.png', 'model_settings': {'use_doc_preprocessor': True, 'use_layout_detection': True}, 'doc_preprocessor_res': {'input_path': None, 'page_index': None, 'model_settings': {'use_doc_orientation_classify': False, 'use_doc_unwarping': False}, 'angle': -1}, 'layout_det_res': {'input_path': None, 'page_index': None, 'boxes': [{'cls_id': 16, 'label': 'seal', 'score': 0.9755404591560364, 'coordinate': [6.19458, 0.17910767, 634.38385, 628.8424]}]}, 'seal_res_list': [{'input_path': None, 'page_index': None, 'model_settings': {'use_doc_preprocessor': False, 'use_textline_orientation': False}, 'dt_polys': [array([[320, 39],
119
+ ...,
120
+ [317, 38]]), array([[456, 348],
121
+ ...,
122
+ [299, 346]]), array([[436, 445],
123
+ ...,
124
+ [188, 443]]), array([[159, 470],
125
+ ...,
126
+ [154, 468]])], 'text_det_params': {'limit_side_len': 736, 'limit_type': 'min', 'thresh': 0.2, 'max_side_limit': 4000, 'box_thresh': 0.6, 'unclip_ratio': 0.5}, 'text_type': 'seal', 'textline_orientation_angles': array([-1, ..., -1]), 'text_rec_score_thresh': 0, 'rec_texts': ['天津君和缘商贸有限公司', '发票专用章', '吗繁物', '5263647368706'], 'rec_scores': array([0.99007857, ..., 0.99880081]), 'rec_polys': [array([[320, 39],
127
+ ...,
128
+ [317, 38]]), array([[456, 348],
129
+ ...,
130
+ [299, 346]]), array([[436, 445],
131
+ ...,
132
+ [188, 443]]), array([[159, 470],
133
+ ...,
134
+ [154, 468]])], 'rec_boxes': array([], dtype=float64)}]}}
135
+ ```
136
+
137
+ If save_path is specified, the visualization results will be saved under `save_path`. The visualization output is shown below:
138
+
139
+ ![image/jpeg](https://cdn-uploads.huggingface.co/production/uploads/63d7b8ee07cd1aa3c49a2026/VVhOMXvWrlrIhTsq97as4.png)
140
+
141
+ The command-line method is for quick experience. For project integration, also only a few codes are needed as well:
142
+
143
+ ```python
144
+ from paddleocr import PaddleOCR
145
+
146
+ ocr = PaddleOCR(
147
+ seal_text_detection_model_name="PP-OCRv4_mobile_seal_det",
148
+ use_doc_orientation_classify=False, # Use use_doc_orientation_classify to enable/disable document orientation classification model
149
+ use_doc_unwarping=False, # Use use_doc_unwarping to enable/disable document unwarping module
150
+ device="gpu:0", # Use device to specify GPU for model inference
151
+ )
152
+ result = ocr.predict("https://cdn-uploads.huggingface.co/production/uploads/63d7b8ee07cd1aa3c49a2026/k02u35x60XZmaL9hzeQ0T.png")
153
+ for res in result:
154
+ res.print()
155
+ res.save_to_img("output")
156
+ res.save_to_json("output")
157
+ ```
158
+
159
+ The default model used in pipeline is `PP-OCRv4_server_seal_det`, so it is needed that specifing to `PP-OCRv4_mobile_seal_det` by argument `seal_text_detection_model_name`. And you can also use the local model file by argument `seal_text_detection_model_dir`. 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/seal_recognition.html#2-quick-start).
160
+
161
+
162
+ ## Links
163
+
164
+ [PaddleOCR Repo](https://github.com/paddlepaddle/paddleocr)
165
+
166
+ [PaddleOCR Documentation](https://paddlepaddle.github.io/PaddleOCR/latest/en/index.html)