Upload folder using huggingface_hub
Browse files
README.md
ADDED
@@ -0,0 +1,166 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: apache-2.0
|
3 |
+
---
|
4 |
+
|
5 |
+
# PP-OCRv4_server_det
|
6 |
+
|
7 |
+
## Introduction
|
8 |
+
|
9 |
+
PP-OCRv4_server_det is one of the PP-OCRv4_det series models, a set of text detection models developed by the PaddleOCR team. This server-side text detection model offers higher accuracy and is suitable for deployment on high-performance servers. Its key accuracy metrics are as follows:
|
10 |
+
|
11 |
+
| Handwritten Chinese | Handwritten English | Printed Chinese | Printed English | Traditional Chinese | Ancient Text | Japanese | General Scenario | Pinyin | Rotation | Distortion | Artistic Text | Average |
|
12 |
+
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
|
13 |
+
| 0.706 | 0.249 | 0.888 | 0.690 | 0.759 | 0.473 | 0.685 | 0.715 | 0.542 | 0.366 | 0.775 | 0.583 | 0.662 |
|
14 |
+
|
15 |
+
## Quick Start
|
16 |
+
|
17 |
+
### Installation
|
18 |
+
|
19 |
+
1. PaddlePaddle
|
20 |
+
|
21 |
+
Please refer to the following commands to install PaddlePaddle using pip:
|
22 |
+
|
23 |
+
```bash
|
24 |
+
# for CUDA11.8
|
25 |
+
python -m pip install paddlepaddle-gpu==3.0.0 -i https://www.paddlepaddle.org.cn/packages/stable/cu118/
|
26 |
+
|
27 |
+
# for CUDA12.6
|
28 |
+
python -m pip install paddlepaddle-gpu==3.0.0 -i https://www.paddlepaddle.org.cn/packages/stable/cu126/
|
29 |
+
|
30 |
+
# for CPU
|
31 |
+
python -m pip install paddlepaddle==3.0.0 -i https://www.paddlepaddle.org.cn/packages/stable/cpu/
|
32 |
+
```
|
33 |
+
|
34 |
+
For details about PaddlePaddle installation, please refer to the [PaddlePaddle official website](https://www.paddlepaddle.org.cn/en/install/quick).
|
35 |
+
|
36 |
+
2. PaddleOCR
|
37 |
+
|
38 |
+
Install the latest version of the PaddleOCR inference package from PyPI:
|
39 |
+
|
40 |
+
```bash
|
41 |
+
python -m pip install paddleocr
|
42 |
+
```
|
43 |
+
|
44 |
+
### Model Usage
|
45 |
+
|
46 |
+
You can quickly experience the functionality with a single command:
|
47 |
+
|
48 |
+
```bash
|
49 |
+
paddleocr text_detection \
|
50 |
+
--model_name PP-OCRv4_server_det \
|
51 |
+
-i https://cdn-uploads.huggingface.co/production/uploads/681c1ecd9539bdde5ae1733c/3ul2Rq4Sk5Cn-l69D695U.png
|
52 |
+
```
|
53 |
+
|
54 |
+
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.
|
55 |
+
|
56 |
+
```python
|
57 |
+
from paddleocr import TextDetection
|
58 |
+
model = TextDetection(model_name="PP-OCRv4_server_det")
|
59 |
+
output = model.predict(input="3ul2Rq4Sk5Cn-l69D695U.png", batch_size=1)
|
60 |
+
for res in output:
|
61 |
+
res.print()
|
62 |
+
res.save_to_img(save_path="./output/")
|
63 |
+
res.save_to_json(save_path="./output/res.json")
|
64 |
+
```
|
65 |
+
|
66 |
+
After running, the obtained result is as follows:
|
67 |
+
|
68 |
+
```json
|
69 |
+
{'res': {'input_path': '/root/.paddlex/predict_input/3ul2Rq4Sk5Cn-l69D695U.png', 'page_index': None, 'dt_polys': array([[[ 627, 1432],
|
70 |
+
...,
|
71 |
+
[ 627, 1449]],
|
72 |
+
|
73 |
+
...,
|
74 |
+
|
75 |
+
[[ 354, 106],
|
76 |
+
...,
|
77 |
+
[ 354, 127]]], dtype=int16), 'dt_scores': [0.9421815230284514, 0.8528662776681952, ..., 0.8209321007152185]}}
|
78 |
+
```
|
79 |
+
|
80 |
+
The visualized image is as follows:
|
81 |
+
|
82 |
+

|
83 |
+
|
84 |
+
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).
|
85 |
+
|
86 |
+
### Pipeline Usage
|
87 |
+
|
88 |
+
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.
|
89 |
+
|
90 |
+
#### PP-OCRv4
|
91 |
+
|
92 |
+
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:
|
93 |
+
* Document Image Orientation Classification Module (Optional)
|
94 |
+
* Text Image Unwarping Module (Optional)
|
95 |
+
* Text Line Orientation Classification Module (Optional)
|
96 |
+
* Text Detection Module
|
97 |
+
* Text Recognition Module
|
98 |
+
|
99 |
+
Run a single command to quickly experience the OCR pipeline:
|
100 |
+
|
101 |
+
```bash
|
102 |
+
paddleocr ocr -i https://cdn-uploads.huggingface.co/production/uploads/681c1ecd9539bdde5ae1733c/3ul2Rq4Sk5Cn-l69D695U.png \
|
103 |
+
--text_detection_model_name PP-OCRv4_server_det \
|
104 |
+
--text_recognition_model_name PP-OCRv4_server_rec \
|
105 |
+
--use_doc_orientation_classify False \
|
106 |
+
--use_doc_unwarping False \
|
107 |
+
--use_textline_orientation False \
|
108 |
+
--save_path ./output \
|
109 |
+
--device gpu:0
|
110 |
+
```
|
111 |
+
|
112 |
+
Results are printed to the terminal:
|
113 |
+
|
114 |
+
```json
|
115 |
+
{'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([[[ 355, 109],
|
116 |
+
...,
|
117 |
+
[ 355, 126]],
|
118 |
+
|
119 |
+
...,
|
120 |
+
|
121 |
+
[[ 631, 1431],
|
122 |
+
...,
|
123 |
+
[ 631, 1450]]], 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,JlK2Rl,Canada', '(Dated:October31,2018)', 'TheMarkoventropydecomposition', '(MED)is a recently-proposed, cluster-based simulation method for fi-', 'nite temperature quantum systems with arbitrary geometry. In this p', 'paper,wedetail numerical algorithms for', 'performing the required steps of the MED,principally solving a minimization problem with a', 'preconditioned', 'astea1ocrtratnrtpccc', "Newton's", 'algorithm,as well as how to extract global susceptibilities and thermal responses.', 'Wedemonstrate', 'the power of the method with the spin-l/2 XXZ model on the 2D squarelattice, including the extraction of', 'critical points and details of each phase. Although the method shares some qualitative similarities with exact-', 'diagonalization,we show the MED is both more accurate and significantly more flexible.', 'PACSnumbers:05.10.-a, 02.50.Ng,03.67.-a,74.40.Kb', 'I.INTRODUCTION', 'This approximation becomes exact in the case of a 1D', 'quan-', 'tum(orclassical)', 'Markov chain', '[10],and leads to an', 'expo-', 'Although', 'the', 'equations', 'governing', 'quantum many-body', 'nentialreduction', '1 of cost for exact entropy calculations when', 'systems are', 'simplet', 'writedown,findin', 'solutions', 'sforthe', 'the global density matrix is a higher-dimensional Markov net-', 'majority', 'of', 'systems', 'remains incredibly', 'difficult.', 'Modern', 'workstate', '[12,13].', 'physics finds itself in need of new', 'tools to compute the emer-', 'The second approximation used in the MED approach is', 'gentbehavior of large, many-body', 'ysystems.', 'related to the V-representibility problem. Given a set of lo-', 'Therehasbeen', 'greatvariety', 'r oftools developed to tackle', 'calbutoverlapping', 'reduced density', 'matrices{pi},it is avery', 'many-bodyproblems', 's,butin', 'general,large', '2D', 'and3D', 'quan-', 'challenging', 'problemto determinei', 'ifthereexists', 'globalden-', 'tum', 'systems', 'remain', 'hard', 'deal', 'with.', 'Most', 'systems', 'are', 'sity operator which is positive semi-definite and whose partial', 'thought to be non-integrable, so exact analytic solutions are', 'trace agrees', 'with', 'each', 'p.This', 'problemisQMA-hard', '(the', 'notusually expected.Direct numerical diagonalization canbe', 'quantum analogue of NP)', '[14,', '151.', 'and is hopelessly', 'diffi-', 'performedforrelatively', 'small', 'wstems', '-howevertheemer-', 'cultto', 'enforce.', 'Thus', 'the', 'second', 'pproximationemployed', 'gentbehaviorofas', 'ystem in thethermodynamiclimitmaybe', 'involves ignoringglobal consistency', 'with a', 'positive', 'opera-', 'difficult to extract, especially in s', 'ystemswithlarge', 'correlation', 'tor,while', 'requiring', 'localconsistenc', 'on any overlapping re-', 'lengths.MonteCarlo', 'approaches are technically', '/exact(upto', 'gionsbetween thep.Atthezero-temperaturelimit,theMED', 'sampling', 'error),but', 'suffer', 'fromthe', 'so-called', 'ign', 'problem', 'approach becomes analogous to the', 'ariationalnth-orderre-', '111', 'for fermionic, frustrated, or dynamical problems. Thus', 'weare', 'duceddensity', 'matrix', 'approach,', 'where', 'positivity is enforced', 'limitedto', 'search for clever', ' approximations to solve the ma-', 'on all reduced density', 'matrices of size', '[16-18].', ' jority of many-body problems.', 'The MED approach is an extremely flexible cluster method,', 'Overthe', 'pastcentury', 'hundredsof such', 'approximations', 'applicable to both translationally', 'y invariant systems of any di-', 'havebeen', 'proposed,', ' and we will mention just a few notable', 'mension in the thermodynamic limit.', 'as well asfinite', 'ystems', 'examples', 'applicable', 'quantum lattice', 'odels.Mean-field', 'or systems', 'without translational invariance (e.g.', 'disordered', 'theory', 'is simple and frequently', 'arrives', 'at the correct', 'quali-', 'lattices,', 'or harmonically', 'trappedatomsin', 'optical lattices).', 'tative description,but', 'often fails', 'swhen', 'correlations', 'are im-', 'Thefreeenergygivenby', 'MEDis', '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 at solving', '1D', 'problems,', 'stateenergy', '—thus', 'providing a natural complement to varia-', 'butthe computational cost', 'grows exponentially', 'ywithsystem', 'tionalapproacheswhich upper-boundthe', 'ground state energy.', 'size in two- or higher-dimensions', '[2,3].', 'Related tensor-', 'The ability to provide a rigorous', 's ground-stateenergywindow', 'networktechniquesdesigned for2D', 'ystemsarestill intheir', 'is apowerful validation tool, creating', 'averycompellingrea-', 'infancy [4-6]. Series-expansion methods', '7', 'canbe success-', 'son to use this approach.', 'ful, but may diverge', 'orotherwise converge', 'eslowly,obscuring', 'In this paper we paper we present a pedagogical introduc-', 'thestatein', '1certain', 'regimes. There exist', 'variety', 'of cluster-', 'tion toMED, includingnumericalimplementation issues and', 'based techniques', 'such as', 'dynamical-mean-field theory[8]', 'applications', 'to 2D quantum lattice', 'models in the thermody-', 'anddensity', '7-matrix', 'embedding[9].', 'namiclimit.', 'In Sec.II,we', 'give a brief derivation', 'ofthe', 'Herewe', 'discuss the so-called Markov entropy decompo-', 'Markov entropy decomposition.', 'SectionIlloutlinesarobust', 'sition (MED),recently', 'proposedby', 'Poulin&Hastings', '[10]', 'numerical strategy for', 'optimizing', 'the clusters that make up', '(andanalogous to a slightly', 'earlier', ' classical algorithm', '[11])', 'thedecomposition.', 'InSec.IVw', 'show how we can extend', 'This is', 'a self-consistent', 'cluster method for finite temperature', 'thesealgorithmsto', 'extract non-trivial', 'information,suchas', 'systems that takes advantage of an ', 'approximationofthe(von', 'specific heat and susceptibilities.We present an application of', 'Neumann)entropy.', 'In[10],itwas', 'shown that the entropy', 'the method to the spin-1/2 XXZmodel on a 2D squarelattice', 'per site can be rigorously upper bounded using only local in-', 'in Sec.V,describing how to characterize the phase diagram', 'formation—alocal.reduceddensity', 'matrix onN sites,say.', 'and determine critical points, before concluding in Sec.VI.'], 'rec_scores': array([0.98928159, ..., 0.98077077]), 'rec_polys': array([[[ 355, 109],
|
124 |
+
...,
|
125 |
+
[ 355, 126]],
|
126 |
+
|
127 |
+
...,
|
128 |
+
|
129 |
+
[[ 631, 1431],
|
130 |
+
...,
|
131 |
+
[ 631, 1450]]], dtype=int16), 'rec_boxes': array([[ 355, ..., 126],
|
132 |
+
...,
|
133 |
+
[ 631, ..., 1450]], dtype=int16)}}
|
134 |
+
```
|
135 |
+
|
136 |
+
If save_path is specified, the visualization results will be saved under `save_path`. The visualization output is shown below:
|
137 |
+
|
138 |
+

|
139 |
+
|
140 |
+
The command-line method is for quick experience. For project integration, also only a few codes are needed as well:
|
141 |
+
|
142 |
+
```python
|
143 |
+
from paddleocr import PaddleOCR
|
144 |
+
|
145 |
+
ocr = PaddleOCR(
|
146 |
+
text_detection_model_name="PP-OCRv4_server_det",
|
147 |
+
text_recognition_model_name="PP-OCRv4_server_rec",
|
148 |
+
use_doc_orientation_classify=False, # Disables document orientation classification model via this parameter
|
149 |
+
use_doc_unwarping=False, # Disables text image rectification model via this parameter
|
150 |
+
use_textline_orientation=False, # Disables text line orientation classification model via this parameter
|
151 |
+
)
|
152 |
+
result = ocr.predict("./general_ocr.png")
|
153 |
+
for res in result:
|
154 |
+
res.print()
|
155 |
+
res.save_to_img("output")
|
156 |
+
res.save_to_json("output")
|
157 |
+
```
|
158 |
+
|
159 |
+
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).
|
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)
|