multi_languages_en.md 7.98 KB
Newer Older
tink2123's avatar
tink2123 committed
1
2
3
4
# Multi-language model

**Recent Update**

tink2123's avatar
tink2123 committed
5
6
7
8
9
10
11
12
13
14
15
- 2021.4.9 supports the detection and recognition of 80 languages
- 2021.4.9 supports **lightweight high-precision** English model detection and recognition

PaddleOCR aims to create a rich, leading, and practical OCR tool library, which not only provides
Chinese and English models in general scenarios, but also provides models specifically trained
in English scenarios. And multilingual models covering [80 languages](#language_abbreviations).

Among them, the English model supports the detection and recognition of uppercase and lowercase
letters and common punctuation, and the recognition of space characters is optimized:

<div align="center">
tink2123's avatar
tink2123 committed
16
    <img src="../imgs_results/multi_lang/img_12.jpg" width="900" height="300">
tink2123's avatar
tink2123 committed
17
18
19
20
21
22
23
</div>

The multilingual models cover Latin, Arabic, Traditional Chinese, Korean, Japanese, etc.:

<div align="center">
    <img src="../imgs_results/multi_lang/japan_2.jpg" width="600" height="300">
    <img src="../imgs_results/multi_lang/french_0.jpg" width="300" height="300">
tink2123's avatar
tink2123 committed
24
25
    <img src="../imgs_results/multi_lang/korean_0.jpg" width="500" height="300">
    <img src="../imgs_results/multi_lang/arabic_0.jpg" width="300" height="300">
tink2123's avatar
tink2123 committed
26
27
28
29
30
</div>

This document will briefly introduce how to use the multilingual model.

- [1 Installation](#Install)
fanruinet's avatar
fanruinet committed
31
32
    - [1.1 Paddle installation](#paddleinstallation)
    - [1.2 PaddleOCR package installation](#paddleocr_package_install)
tink2123's avatar
tink2123 committed
33
34
35

- [2 Quick Use](#Quick_Use)
    - [2.1 Command line operation](#Command_line_operation)
fanruinet's avatar
fanruinet committed
36
    - [2.2 Run with Python script](#python_Script_running)
tink2123's avatar
tink2123 committed
37
- [3 Custom Training](#Custom_Training)
tink2123's avatar
tink2123 committed
38
- [4 Inference and Deployment](#inference)
tink2123's avatar
tink2123 committed
39
- [4 Supported languages and abbreviations](#language_abbreviations)
tink2123's avatar
tink2123 committed
40
41
42
43
44

<a name="Install"></a>
## 1 Installation

<a name="paddle_install"></a>
fanruinet's avatar
fanruinet committed
45
### 1.1 Paddle installation
tink2123's avatar
tink2123 committed
46
47
48
49
50
```
# cpu
pip install paddlepaddle

# gpu
tink2123's avatar
tink2123 committed
51
pip install paddlepaddle-gpu
tink2123's avatar
tink2123 committed
52
53
54
```

<a name="paddleocr_package_install"></a>
fanruinet's avatar
fanruinet committed
55
### 1.2 PaddleOCR package installation
tink2123's avatar
tink2123 committed
56
57
58
59


pip install
```
tink2123's avatar
tink2123 committed
60
pip install "paddleocr>=2.0.6" # 2.0.6 version is recommended
tink2123's avatar
tink2123 committed
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
```
Build and install locally
```
python3 setup.py bdist_wheel
pip3 install dist/paddleocr-x.x.x-py3-none-any.whl # x.x.x is the version number of paddleocr
```

<a name="Quick_use"></a>
## 2 Quick use

<a name="Command_line_operation"></a>
### 2.1 Command line operation

View help information

```
paddleocr -h
```

* Whole image prediction (detection + recognition)

fanruinet's avatar
fanruinet committed
82
83
PaddleOCR currently supports 80 languages, which can be specified by the --lang parameter.
The supported languages are listed in the [table](#language_abbreviations).
tink2123's avatar
tink2123 committed
84
85

``` bash
tink2123's avatar
tink2123 committed
86
paddleocr --image_dir doc/imgs_en/254.jpg --lang=en
tink2123's avatar
tink2123 committed
87
```
tink2123's avatar
tink2123 committed
88
89
90
91
<div align="center">
    <img src="../imgs_en/254.jpg" width="300" height="600">
    <img src="../imgs_results/multi_lang/img_02.jpg" width="600" height="600">
</div>
tink2123's avatar
tink2123 committed
92

fanruinet's avatar
fanruinet committed
93
The result is a list. Each item contains a text box, text and recognition confidence
tink2123's avatar
tink2123 committed
94
```text
tink2123's avatar
tink2123 committed
95
96
97
98
99
100
101
[('PHO CAPITAL', 0.95723116), [[66.0, 50.0], [327.0, 44.0], [327.0, 76.0], [67.0, 82.0]]]
[('107 State Street', 0.96311164), [[72.0, 90.0], [451.0, 84.0], [452.0, 116.0], [73.0, 121.0]]]
[('Montpelier Vermont', 0.97389287), [[69.0, 132.0], [501.0, 126.0], [501.0, 158.0], [70.0, 164.0]]]
[('8022256183', 0.99810505), [[71.0, 175.0], [363.0, 170.0], [364.0, 202.0], [72.0, 207.0]]]
[('REG 07-24-201706:59 PM', 0.93537045), [[73.0, 299.0], [653.0, 281.0], [654.0, 318.0], [74.0, 336.0]]]
[('045555', 0.99346405), [[509.0, 331.0], [651.0, 325.0], [652.0, 356.0], [511.0, 362.0]]]
[('CT1', 0.9988654), [[535.0, 367.0], [654.0, 367.0], [654.0, 406.0], [535.0, 406.0]]]
tink2123's avatar
tink2123 committed
102
103
104
......
```

tink2123's avatar
tink2123 committed
105
* Recognition
tink2123's avatar
tink2123 committed
106
107

```bash
tink2123's avatar
tink2123 committed
108
paddleocr --image_dir doc/imgs_words_en/word_308.png --det false --lang=en
tink2123's avatar
tink2123 committed
109
110
```

tink2123's avatar
tink2123 committed
111
![](https://raw.githubusercontent.com/PaddlePaddle/PaddleOCR/release/2.1/doc/imgs_words_en/word_308.png)
tink2123's avatar
tink2123 committed
112

fanruinet's avatar
fanruinet committed
113
The result is a 2-tuple, which contains the recognition result and recognition confidence
tink2123's avatar
tink2123 committed
114
115

```text
tink2123's avatar
tink2123 committed
116
(0.99879867, 'LITTLE')
tink2123's avatar
tink2123 committed
117
118
```

tink2123's avatar
tink2123 committed
119
* Detection
tink2123's avatar
tink2123 committed
120
121
122
123
124

```
paddleocr --image_dir PaddleOCR/doc/imgs/11.jpg --rec false
```

fanruinet's avatar
fanruinet committed
125
The result is a list. Each item represents the coordinates of a text box.
tink2123's avatar
tink2123 committed
126
127
128
129
130
131
132
133
134

```
[[26.0, 457.0], [137.0, 457.0], [137.0, 477.0], [26.0, 477.0]]
[[25.0, 425.0], [372.0, 425.0], [372.0, 448.0], [25.0, 448.0]]
[[128.0, 397.0], [273.0, 397.0], [273.0, 414.0], [128.0, 414.0]]
......
```

<a name="python_script_running"></a>
fanruinet's avatar
fanruinet committed
135
### 2.2 Run with Python script
tink2123's avatar
tink2123 committed
136

fanruinet's avatar
fanruinet committed
137
PPOCR is able to run with Python scripts for easy integration with your own code:
tink2123's avatar
tink2123 committed
138
139
140
141
142
143
144
145
146
147

* Whole image prediction (detection + recognition)

```
from paddleocr import PaddleOCR, draw_ocr

# Also switch the language by modifying the lang parameter
ocr = PaddleOCR(lang="korean") # The model file will be downloaded automatically when executed for the first time
img_path ='doc/imgs/korean_1.jpg'
result = ocr.ocr(img_path)
tink2123's avatar
tink2123 committed
148
149
150
# Recognition and detection can be performed separately through parameter control
# result = ocr.ocr(img_path, det=False)  Only perform recognition
# result = ocr.ocr(img_path, rec=False)  Only perform detection
tink2123's avatar
tink2123 committed
151
152
153
154
155
156
157
158
159
160
# Print detection frame and recognition result
for line in result:
    print(line)

# Visualization
from PIL import Image
image = Image.open(img_path).convert('RGB')
boxes = [line[0] for line in result]
txts = [line[1][0] for line in result]
scores = [line[1][1] for line in result]
tink2123's avatar
tink2123 committed
161
im_show = draw_ocr(image, boxes, txts, scores, font_path='/path/to/PaddleOCR/doc/fonts/korean.ttf')
tink2123's avatar
tink2123 committed
162
163
164
165
166
im_show = Image.fromarray(im_show)
im_show.save('result.jpg')
```

Visualization of results:
tink2123's avatar
tink2123 committed
167
![](https://raw.githubusercontent.com/PaddlePaddle/PaddleOCR/release/2.1/doc/imgs_results/korean.jpg)
tink2123's avatar
tink2123 committed
168
169


fanruinet's avatar
fanruinet committed
170
PPOCR also supports direction classification. For more detailed usage, please refer to: [whl package instructions](whl_en.md).
tink2123's avatar
tink2123 committed
171
172
173
174

<a name="Custom_training"></a>
## 3 Custom training

fanruinet's avatar
fanruinet committed
175
PPOCR supports using your own data for custom training or fine-tune, where the recognition model can refer to [French configuration file](../../configs/rec/multi_language/rec_french_lite_train.yml)
tink2123's avatar
tink2123 committed
176
177
Modify the training data path, dictionary and other parameters.

tink2123's avatar
tink2123 committed
178
179
For specific data preparation and training process, please refer to: [Text Detection](../doc_en/detection_en.md), [Text Recognition](../doc_en/recognition_en.md), more functions such as predictive deployment,
For functions such as data annotation, you can read the complete [Document Tutorial](../../README.md).
tink2123's avatar
tink2123 committed
180

tink2123's avatar
tink2123 committed
181
182
183
184
185

<a name="inference"></a>
## 4 Inference and Deployment

In addition to installing the whl package for quick forecasting,
fanruinet's avatar
fanruinet committed
186
PPOCR also provides a variety of forecasting deployment methods.
tink2123's avatar
tink2123 committed
187
188
189
190
191
192
193
194
195
196
197
198
199
200
If necessary, you can read related documents:

- [Python Inference](./inference_en.md)
- [C++ Inference](../../deploy/cpp_infer/readme_en.md)
- [Serving](../../deploy/hubserving/readme_en.md)
- [Mobile](https://github.com/PaddlePaddle/PaddleOCR/blob/develop/deploy/lite/readme_en.md)
- [Benchmark](./benchmark_en.md)


<a name="language_abbreviations"></a>
## 5 Support languages and abbreviations

| Language  | Abbreviation | | Language  | Abbreviation |
| ---  | --- | --- | ---  | --- |
Leif's avatar
Leif committed
201
202
203
204
205
206
207
|Chinese & English|ch| |Arabic|ar|
|English|en| |Hindi|hi|
|French|fr| |Uyghur|ug|
|German|german| |Persian|fa|
|Japan|japan| |Urdu|ur|
|Korean|korean| | Serbian(latin) |rs_latin|
|Chinese Traditional |chinese_cht| |Occitan |oc|
tink2123's avatar
tink2123 committed
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
| Italian |it| |Marathi|mr|
|Spanish |es| |Nepali|ne|
| Portuguese|pt| |Serbian(cyrillic)|rs_cyrillic|
|Russia|ru||Bulgarian |bg|
|Ukranian|uk| |Estonian |et|
|Belarusian|be| |Irish |ga|
|Telugu |te| |Croatian |hr|
|Saudi Arabia|sa| |Hungarian |hu|
|Tamil |ta| |Indonesian|id|
|Afrikaans |af| |Icelandic|is|
|Azerbaijani  |az||Kurdish|ku|
|Bosnian|bs| |Lithuanian |lt|
|Czech|cs| |Latvian |lv|
|Welsh |cy| |Maori|mi|
|Danish|da| |Malay|ms|
|Maltese |mt| |Adyghe |ady|
|Dutch |nl| |Kabardian |kbd|
|Norwegian |no| |Avar |ava|
|Polish |pl| |Dargwa |dar|
|Romanian |ro| |Ingush |inh|
|Slovak |sk| |Lak |lbe|
|Slovenian |sl| |Lezghian |lez|
|Albanian |sq| |Tabassaran |tab|
|Swedish |sv| |Bihari |bh|
|Swahili |sw| |Maithili |mai|
|Tagalog |tl| |Angika |ang|
|Turkish |tr| |Bhojpuri |bho|
|Uzbek |uz| |Magahi |mah|
|Vietnamese |vi| |Nagpur |sck|
|Mongolian |mn| |Newari |new|
|Abaza |abq| |Goan Konkani|gom|