liuhlightning Tingquan commited on
Commit
8ca6cc9
·
0 Parent(s):

Duplicate from PaddlePaddle/PP-OCRv4_mobile_det

Browse files

Co-authored-by: Tingquan Gao <Tingquan@users.noreply.huggingface.co>

Files changed (6) hide show
  1. .gitattributes +36 -0
  2. README.md +176 -0
  3. config.json +111 -0
  4. inference.json +0 -0
  5. inference.pdiparams +3 -0
  6. inference.yml +53 -0
.gitattributes ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ inference.pdiparams filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,176 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ library_name: PaddleOCR
4
+ language:
5
+ - en
6
+ - zh
7
+ pipeline_tag: image-to-text
8
+ tags:
9
+ - OCR
10
+ - PaddlePaddle
11
+ - PaddleOCR
12
+ - textline_detection
13
+ ---
14
+
15
+ # PP-OCRv4_mobile_det
16
+
17
+ ## Introduction
18
+
19
+ PP-OCRv4_mobile_det is one of the PP-OCRv4_det series models, a set of text detection models developed by the PaddleOCR team. This mobile-optimized text detection model offers higher efficiency, making it ideal for deployment on edge devices. Its key accuracy metrics are as follows:
20
+
21
+ | Handwritten Chinese | Handwritten English | Printed Chinese | Printed English | Traditional Chinese | Ancient Text | Japanese | General Scenario | Pinyin | Rotation | Distortion | Artistic Text | Average |
22
+ | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
23
+ | 0.583 | 0.369 | 0.872 | 0.773 | 0.663 | 0.231 | 0.634 | 0.710 | 0.430 | 0.299 | 0.715 | 0.549 | 0.624 |
24
+
25
+ ## Quick Start
26
+
27
+ ### Installation
28
+
29
+ 1. PaddlePaddle
30
+
31
+ Please refer to the following commands to install PaddlePaddle using pip:
32
+
33
+ ```bash
34
+ # for CUDA11.8
35
+ python -m pip install paddlepaddle-gpu==3.0.0 -i https://www.paddlepaddle.org.cn/packages/stable/cu118/
36
+
37
+ # for CUDA12.6
38
+ python -m pip install paddlepaddle-gpu==3.0.0 -i https://www.paddlepaddle.org.cn/packages/stable/cu126/
39
+
40
+ # for CPU
41
+ python -m pip install paddlepaddle==3.0.0 -i https://www.paddlepaddle.org.cn/packages/stable/cpu/
42
+ ```
43
+
44
+ For details about PaddlePaddle installation, please refer to the [PaddlePaddle official website](https://www.paddlepaddle.org.cn/en/install/quick).
45
+
46
+ 2. PaddleOCR
47
+
48
+ Install the latest version of the PaddleOCR inference package from PyPI:
49
+
50
+ ```bash
51
+ python -m pip install paddleocr
52
+ ```
53
+
54
+ ### Model Usage
55
+
56
+ You can quickly experience the functionality with a single command:
57
+
58
+ ```bash
59
+ paddleocr text_detection \
60
+ --model_name PP-OCRv4_mobile_det \
61
+ -i https://cdn-uploads.huggingface.co/production/uploads/681c1ecd9539bdde5ae1733c/3ul2Rq4Sk5Cn-l69D695U.png
62
+ ```
63
+
64
+ You can also integrate the model inference of the text detection module into your project. Before running the following code, please download the sample image to your local machine.
65
+
66
+ ```python
67
+ from paddleocr import TextDetection
68
+ model = TextDetection(model_name="PP-OCRv4_mobile_det")
69
+ output = model.predict(input="3ul2Rq4Sk5Cn-l69D695U.png", batch_size=1)
70
+ for res in output:
71
+ res.print()
72
+ res.save_to_img(save_path="./output/")
73
+ res.save_to_json(save_path="./output/res.json")
74
+ ```
75
+
76
+ After running, the obtained result is as follows:
77
+
78
+ ```json
79
+ {'res': {'input_path': '/root/.paddlex/predict_input/3ul2Rq4Sk5Cn-l69D695U.png', 'page_index': None, 'dt_polys': array([[[ 637, 1432],
80
+ ...,
81
+ [ 637, 1454]],
82
+
83
+ ...,
84
+
85
+ [[ 356, 107],
86
+ ...,
87
+ [ 356, 130]]], dtype=int16), 'dt_scores': [0.8305358711080322, 0.6912752452425651, ..., 0.848925772091929]}}
88
+ ```
89
+
90
+ The visualized image is as follows:
91
+
92
+ ![image/jpeg](https://cdn-uploads.huggingface.co/production/uploads/681c1ecd9539bdde5ae1733c/DnuBmbm8nDkuj_lLNS5fm.jpeg)
93
+
94
+ 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_detection.html#iii-quick-start).
95
+
96
+ ### Pipeline Usage
97
+
98
+ 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.
99
+
100
+ #### PP-OCRv4
101
+
102
+ The general OCR pipeline is used to solve text recognition tasks by extracting text information from images and outputting it in text form. And there are 5 modules in the pipeline:
103
+ * Document Image Orientation Classification Module (Optional)
104
+ * Text Image Unwarping Module (Optional)
105
+ * Text Line Orientation Classification Module (Optional)
106
+ * Text Detection Module
107
+ * Text Recognition Module
108
+
109
+ Run a single command to quickly experience the OCR pipeline:
110
+
111
+ ```bash
112
+ paddleocr ocr -i https://cdn-uploads.huggingface.co/production/uploads/681c1ecd9539bdde5ae1733c/3ul2Rq4Sk5Cn-l69D695U.png \
113
+ --text_detection_model_name PP-OCRv4_mobile_det \
114
+ --text_recognition_model_name PP-OCRv4_mobile_rec \
115
+ --use_doc_orientation_classify False \
116
+ --use_doc_unwarping False \
117
+ --use_textline_orientation False \
118
+ --save_path ./output \
119
+ --device gpu:0
120
+ ```
121
+
122
+ Results are printed to the terminal:
123
+
124
+ ```json
125
+ {'res': {'input_path': '/root/.paddlex/predict_input/3ul2Rq4Sk5Cn-l69D695U.png', 'page_index': None, 'model_settings': {'use_doc_preprocessor': True, 'use_textline_orientation': False}, 'doc_preprocessor_res': {'input_path': None, 'page_index': None, 'model_settings': {'use_doc_orientation_classify': False, 'use_doc_unwarping': False}, 'angle': -1}, 'dt_polys': array([[[ 356, 105],
126
+ ...,
127
+ [ 356, 129]],
128
+
129
+ ...,
130
+
131
+ [[ 630, 1432],
132
+ ...,
133
+ [ 630, 1451]]], dtype=int16), 'text_det_params': {'limit_side_len': 64, 'limit_type': 'min', 'thresh': 0.3, 'max_side_limit': 4000, 'box_thresh': 0.6, 'unclip_ratio': 1.5}, 'text_type': 'general', 'textline_orientation_angles': array([-1, ..., -1]), 'text_rec_score_thresh': 0.0, 'rec_texts': ['AlgorithmsfortheMarkovEntropyDecomposition', 'AndrewJ.FerrisandDavidPoulin', 'DepartementdePhysique,UniversitedeSherbrooke,Quebec,J1K2R1,Canada', '(Dated:October 31,2018)', 'TheMarkoventropydecomposition(MED)isarecently-proposed,cluster-basedsimulationmethodforfi-', 'nite temperature quantum systems with arbitrary geometry. In this paper, we detail numerical algorithms for', 'performingtherequiredsteps oftheMED,principallysolvingaminimizationproblemwithapreconditioned', '2107', "Newton's algorithm, as well as how to extract global susceptibilities and thermal responses. We demonstrate", 'thepowerof themethodwiththespin-1/2XXZmodelonthe2Dsquarelattice,includingtheextractionof', 'criticalpointsanddetailsofeachphase.Althoughthemethodsharessomequalitativesimilaritieswithexact-', 'diagonalization,we show the MED is both more accurate and significantly more fexible', '', 'PACS numbers: 05.10.a, 02.50.Ng, 03.67.a, 74.40.Kb', '6', '1', 'INTRODUCTION', 'This approximation becomes exactin the case of a1Dquan', 'tum (or classical)Markov chain[10],and leads to an expo', 'g', 'Althoughtheequationsgoverningquantummany-body', 'nentialreduction of costfor exact entropy calculationswhen', 'C', 'systemsares', 'simpletowritedown,findingsolutionsforthe', 'theglobaldensitymatrixisahigher-dimensionalMarkovnet-', 'H', 'majorityof systems remainsincrediblydifficult.Modern', 'work state[12,13].', 'physicsfinds itself inneedof new tools tocompute theemer-', 'Thesecond approximationused intheMEDapproach is', 'gent behavioroflarge,many-body systems.', 'relatedtotheN-representibilityproblem.Givenasetoflo', '', 'T', 'Therehasbeen a greatvariety of tools developed totackle', 'calbut overlappingreduceddensitymatrices{pi},itis avery', 'many-body problems,but in general, large 2D and 3D quan-', 'challengingproblemtodetermineifthereexistsaglobalden', '1', 'tumsystemsremainhardtodealwith.N', 'Mostsystemsare', 'sityoperatorwhichispositivesemi-definiteandwhosepartial', 'thoughttobenon-integrable,soexactanalyticsolutionsare', 'trace agreeswitheachpi.This problemis QMA-hard(the', 'notusuallyexpected.Directnumericaldiagonalizationcanbe', 'quantum analogue of NP)[14,15],and is hopelessly diffi', 'performedforrelativelysmallsystems', 'howevertheemer', 'cult toenforce.Thus,the second approximationemployed', 'gentbehaviorofasysteminthethermodynamiclimitmaybe', 'involves ignoringglobal consistency with apositive opera', 'difficulttoextract,especiallyins', 'systemswithlargecorrelation', 'tor,whilerequiringlocal consistency on any overlappingre', 'lengths.MonteCarloapproachesaretechnicallyexact(upto', 'gionsbetweenthep.Atthezero-temperaturelimit,theMED', 'samplingerror),butsufferfromtheso-calledsignproblem', 'approachbecomesanalogoustothevariationalnth-orderre-', 'forfermionic,frustrated,or dynamical problems.Thus we are', 'duceddensitymatrix', 'approach,wherepositivityisenforced', 'limited to search for clever approximations to solve the ma-', 'on allreduceddensitymatricesofsizen[16-18].', 'jorityofmany-bodyproblems', 'TheMEDapproachisanextremelyflexibleclustermethod', 'Over thepastcentury,hundredsof suchapproximations', 'applicabletobothtranslationallyinvariantsystemsofanydi', 'havebeenproposed,andwewillmentionjustafewnotable', 'mensioninthethermodynamiclimit,aswellasfinitesystems', 'examplesapplicabletoquantumlatticemodels.Mean-field', 'or systems without translationalinvariance(e.g.disordered', 'theoryiss', 'simplea', 'andfrequentlyarrivesatthecorrectquali', 'lattices,orharmonicallyt', 'trappeda', 'atomsinopticallattices)', 'tativedescription,butoftenfailswhencorrelationsareim', 'The free energy given by MED is guaranteed to lower bound', 'portant. Density-matrix renormalisation group (DMRG)[1]', 'the true free energy,which in turn lower-bounds the ground', 'is efficient and extremely accurate atsolving1Dproblems', 'stateenergy—t', 'thusprovidinganaturalcomplementtovaria', 'butthecomputationalcostgrowsexponentiallywithsystem', 'tional approacheswhichupper-bound thegroundstateenergy', 'sizeintwo-or higher-dimensions[2,3].F', 'Relatedtensor', 'Theabilitytoprovidearigorousground-stateenergywindow', 'networktechniquesdesignedfor2Dsystemsarestillinthein', 'is apowerfulvalidation tool,creating avery compellingrea-', 'infancy[4-6].Series-expansionmethods[7]canbesuccess-', 'son tousethis approach', 'ful,but may diverge or otherwise converge slowly,obscuring', 'Inthispaperwepaperwepresent apedagogicalintroduc', 'thestateincertainregimes.', 'Thereexistavarietyofcluster', 'tiontoMED,includingnumericalimplementationissuesand', 'basedtechniques,suchasdynamical-mean-fieldtheory[8]', 'applicationsto2Dquantumlatticemodelsinthethermody', 'anddensity-matrixembedding[9]', 'namiclimit.In Sec.I', 'II,wegiveabrief', 'derivationofthe', 'Herewe discuss theso-calledMarkoventropydecompo-', 'Markoventropydecomposition.SectionII outlines arobust', 'sition(MED),recentlyproposed byPoulin&Hastings [10]', 'numericalstrategyfor optimizingtheclusters thatmakeup', '(and analogoustoaslightlyearlier classical algorithm[11])', 'thedecomposition.InSec.IVweshowhowwecanextend', 'Thisisaself-consistentclustermethodforfinite temperature', 'thesealgorithmstoextractnon-trivialinformation,suchas', 'systems that takes advantage of an approximation of the(von', 'specificheat andsusceptibilities.Wepresentan application of', 'Neumann)entropy.In[1o],it was shown that the entropy', 'themethod to the spin-1/2XXZmodelon a 2Dsquarelattice', 'persitecanberigorouslyupperboundedusingonlylocalin-', 'inSec.V,describinghowtocharacterizethephasediagram', 'formation—alocal,reduced density matrix on Nsites,say.', '', 'and determine criticalpoints,before concluding inSec.VI.'], 'rec_scores': array([0.9952876 , ..., 0.95561302]), 'rec_polys': array([[[ 356, 105],
134
+ ...,
135
+ [ 356, 129]],
136
+
137
+ ...,
138
+
139
+ [[ 630, 1432],
140
+ ...,
141
+ [ 630, 1451]]], dtype=int16), 'rec_boxes': array([[ 356, ..., 130],
142
+ ...,
143
+ [ 630, ..., 1451]], dtype=int16)}}
144
+ ```
145
+
146
+ If save_path is specified, the visualization results will be saved under `save_path`. The visualization output is shown below:
147
+
148
+ ![image/jpeg](https://cdn-uploads.huggingface.co/production/uploads/681c1ecd9539bdde5ae1733c/g6n-H2VFG5ZYD0J8YnVfh.jpeg)
149
+
150
+ The command-line method is for quick experience. For project integration, also only a few codes are needed as well:
151
+
152
+ ```python
153
+ from paddleocr import PaddleOCR
154
+
155
+ ocr = PaddleOCR(
156
+ text_detection_model_name="PP-OCRv4_mobile_det",
157
+ text_recognition_model_name="PP-OCRv4_mobile_rec",
158
+ use_doc_orientation_classify=False, # Disables document orientation classification model via this parameter
159
+ use_doc_unwarping=False, # Disables text image rectification model via this parameter
160
+ use_textline_orientation=False, # Disables text line orientation classification model via this parameter
161
+ )
162
+ result = ocr.predict("./3ul2Rq4Sk5Cn-l69D695U.png")
163
+ for res in result:
164
+ res.print()
165
+ res.save_to_img("output")
166
+ res.save_to_json("output")
167
+ ```
168
+
169
+ 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/OCR.html#2-quick-start).
170
+
171
+
172
+ ## Links
173
+
174
+ [PaddleOCR Repo](https://github.com/paddlepaddle/paddleocr)
175
+
176
+ [PaddleOCR Documentation](https://paddlepaddle.github.io/PaddleOCR/latest/en/index.html)
config.json ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "Global": {
3
+ "model_name": "PP-OCRv4_mobile_det"
4
+ },
5
+ "Hpi": {
6
+ "backend_configs": {
7
+ "paddle_infer": {
8
+ "trt_dynamic_shapes": {
9
+ "x": [
10
+ [
11
+ 1,
12
+ 3,
13
+ 32,
14
+ 32
15
+ ],
16
+ [
17
+ 1,
18
+ 3,
19
+ 736,
20
+ 736
21
+ ],
22
+ [
23
+ 1,
24
+ 3,
25
+ 4000,
26
+ 4000
27
+ ]
28
+ ]
29
+ }
30
+ },
31
+ "tensorrt": {
32
+ "dynamic_shapes": {
33
+ "x": [
34
+ [
35
+ 1,
36
+ 3,
37
+ 32,
38
+ 32
39
+ ],
40
+ [
41
+ 1,
42
+ 3,
43
+ 736,
44
+ 736
45
+ ],
46
+ [
47
+ 1,
48
+ 3,
49
+ 4000,
50
+ 4000
51
+ ]
52
+ ]
53
+ }
54
+ }
55
+ }
56
+ },
57
+ "PreProcess": {
58
+ "transform_ops": [
59
+ {
60
+ "DecodeImage": {
61
+ "channel_first": false,
62
+ "img_mode": "BGR"
63
+ }
64
+ },
65
+ {
66
+ "DetLabelEncode": null
67
+ },
68
+ {
69
+ "DetResizeForTest": {
70
+ "resize_long": 960
71
+ }
72
+ },
73
+ {
74
+ "NormalizeImage": {
75
+ "mean": [
76
+ 0.485,
77
+ 0.456,
78
+ 0.406
79
+ ],
80
+ "order": "hwc",
81
+ "scale": "1./255.",
82
+ "std": [
83
+ 0.229,
84
+ 0.224,
85
+ 0.225
86
+ ]
87
+ }
88
+ },
89
+ {
90
+ "ToCHWImage": null
91
+ },
92
+ {
93
+ "KeepKeys": {
94
+ "keep_keys": [
95
+ "image",
96
+ "shape",
97
+ "polys",
98
+ "ignore_tags"
99
+ ]
100
+ }
101
+ }
102
+ ]
103
+ },
104
+ "PostProcess": {
105
+ "name": "DBPostProcess",
106
+ "thresh": 0.3,
107
+ "box_thresh": 0.6,
108
+ "max_candidates": 1000,
109
+ "unclip_ratio": 1.5
110
+ }
111
+ }
inference.json ADDED
The diff for this file is too large to render. See raw diff
 
inference.pdiparams ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:54a85087b4d31fa3ea4e4aba100169a1ec3e3274cd3352b9068b3cfccbca7829
3
+ size 4692937
inference.yml ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Global:
2
+ model_name: PP-OCRv4_mobile_det
3
+ Hpi:
4
+ backend_configs:
5
+ paddle_infer:
6
+ trt_dynamic_shapes: &id001
7
+ x:
8
+ - - 1
9
+ - 3
10
+ - 32
11
+ - 32
12
+ - - 1
13
+ - 3
14
+ - 736
15
+ - 736
16
+ - - 1
17
+ - 3
18
+ - 4000
19
+ - 4000
20
+ tensorrt:
21
+ dynamic_shapes: *id001
22
+ PreProcess:
23
+ transform_ops:
24
+ - DecodeImage:
25
+ channel_first: false
26
+ img_mode: BGR
27
+ - DetLabelEncode: null
28
+ - DetResizeForTest:
29
+ resize_long: 960
30
+ - NormalizeImage:
31
+ mean:
32
+ - 0.485
33
+ - 0.456
34
+ - 0.406
35
+ order: hwc
36
+ scale: 1./255.
37
+ std:
38
+ - 0.229
39
+ - 0.224
40
+ - 0.225
41
+ - ToCHWImage: null
42
+ - KeepKeys:
43
+ keep_keys:
44
+ - image
45
+ - shape
46
+ - polys
47
+ - ignore_tags
48
+ PostProcess:
49
+ name: DBPostProcess
50
+ thresh: 0.3
51
+ box_thresh: 0.6
52
+ max_candidates: 1000
53
+ unclip_ratio: 1.5