multi_languages.md 8.83 KB
Newer Older
tink2123's avatar
tink2123 committed
1
2
# 多语言模型

tink2123's avatar
tink2123 committed
3
**近期更新**
tink2123's avatar
tink2123 committed
4

tink2123's avatar
tink2123 committed
5
6
- 2021.4.9 支持**80种**语言的检测和识别
- 2021.4.9 支持**轻量高精度**英文模型检测识别
tink2123's avatar
tink2123 committed
7

tink2123's avatar
tink2123 committed
8
9
10
11
PaddleOCR 旨在打造一套丰富、领先、且实用的OCR工具库,不仅提供了通用场景下的中英文模型,也提供了专门在英文场景下训练的模型,
和覆盖[80个语言](#语种缩写)的小语种模型。

其中英文模型支持,大小写字母和常见标点的检测识别,并优化了空格字符的识别:
tink2123's avatar
tink2123 committed
12

tink2123's avatar
tink2123 committed
13
<div align="center">
tink2123's avatar
tink2123 committed
14
    <img src="../imgs_results/multi_lang/en_1.jpg" width="400" height="600">
tink2123's avatar
tink2123 committed
15
16
17
18
19
</div>

小语种模型覆盖了拉丁语系、阿拉伯语系、中文繁体、韩语、日语等等:

<div align="center">
tink2123's avatar
tink2123 committed
20
21
    <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
22
23
</div>

tink2123's avatar
tink2123 committed
24

tink2123's avatar
tink2123 committed
25
26
本文档将简要介绍小语种模型的使用方法。

tink2123's avatar
tink2123 committed
27
28
29
30
31
32
33
34
35
36
37
38
39
- [1 安装](#安装)
    - [1.1 paddle 安装](#paddle安装)
    - [1.2 paddleocr package 安装](#paddleocr_package_安装)  

- [2 快速使用](#快速使用)
    - [2.1 命令行运行](#命令行运行)
     - [2.1.1 整图预测](#bash_检测+识别)
     - [2.1.2 识别预测](#bash_识别)
     - [2.1.3 检测预测](#bash_检测)
    - [2.2 python 脚本运行](#python_脚本运行)
     - [2.2.1 整图预测](#python_检测+识别)
     - [2.2.2 识别预测](#python_识别)
     - [2.2.3 检测预测](#python_检测)
tink2123's avatar
tink2123 committed
40
41
- [3 自定义训练](#自定义训练)
- [4 支持语种及缩写](#语种缩写)
tink2123's avatar
tink2123 committed
42

tink2123's avatar
tink2123 committed
43
<a name="安装"></a>
tink2123's avatar
tink2123 committed
44
45
## 1 安装

tink2123's avatar
tink2123 committed
46
<a name="paddle安装"></a>
tink2123's avatar
tink2123 committed
47
48
49
50
51
52
53
54
### 1.1 paddle 安装
```
# cpu
pip install paddlepaddle

# gpu
pip instll paddlepaddle-gpu
```
tink2123's avatar
tink2123 committed
55
56

<a name="paddleocr_package_安装"></a>
tink2123's avatar
tink2123 committed
57
58
59
60
61
### 1.2 paddleocr package 安装


pip 安装
```
tink2123's avatar
tink2123 committed
62
pip install "paddleocr>=2.0.6" # 推荐使用2.0.6版本
tink2123's avatar
tink2123 committed
63
64
65
66
67
68
```
本地构建并安装
```
python3 setup.py bdist_wheel
pip3 install dist/paddleocr-x.x.x-py3-none-any.whl # x.x.x是paddleocr的版本号
```
tink2123's avatar
tink2123 committed
69
70

<a name="快速使用"></a>
tink2123's avatar
tink2123 committed
71
72
## 2 快速使用

tink2123's avatar
tink2123 committed
73
<a name="命令行运行"></a>
tink2123's avatar
tink2123 committed
74
75
76
77
78
79
80
81
### 2.1 命令行运行

查看帮助信息

```
paddleocr -h
```

tink2123's avatar
tink2123 committed
82
* 整图预测(检测+识别)
tink2123's avatar
tink2123 committed
83
84
85
86
87
88
89

Paddleocr目前支持80个语种,可以通过修改--lang参数进行切换,具体支持的[语种](#语种缩写)可查看表格。

``` bash

paddleocr --image_dir doc/imgs/japan_2.jpg --lang=japan
```
tink2123's avatar
tink2123 committed
90
91
92
93
94

<div align="center">
    <img src="https://raw.githubusercontent.com/PaddlePaddle/PaddleOCR/release/2.1/doc/imgs/japan_2.jpg" width="800">
</div>

tink2123's avatar
tink2123 committed
95
96
97
98
99
100
101
102
103
104

结果是一个list,每个item包含了文本框,文字和识别置信度
```text
[[[671.0, 60.0], [847.0, 63.0], [847.0, 104.0], [671.0, 102.0]], ('もちもち', 0.9993342)]
[[[394.0, 82.0], [536.0, 77.0], [538.0, 127.0], [396.0, 132.0]], ('天然の', 0.9919842)]
[[[880.0, 89.0], [1014.0, 93.0], [1013.0, 127.0], [879.0, 124.0]], ('とろっと', 0.9976762)]
[[[1067.0, 101.0], [1294.0, 101.0], [1294.0, 138.0], [1067.0, 138.0]], ('後味のよい', 0.9988712)]
......
```

tink2123's avatar
tink2123 committed
105
* 识别预测
tink2123's avatar
tink2123 committed
106
107
108
109

```bash
paddleocr --image_dir doc/imgs_words/japan/1.jpg   --det false --lang=japan
```
tink2123's avatar
tink2123 committed
110

tink2123's avatar
tink2123 committed
111
![](https://raw.githubusercontent.com/PaddlePaddle/PaddleOCR/release/2.0/doc/imgs_words/japan/1.jpg)
tink2123's avatar
tink2123 committed
112

tink2123's avatar
tink2123 committed
113
114
115
116
117
118
结果是一个tuple,返回识别结果和识别置信度

```text
('したがって', 0.99965394)
```

tink2123's avatar
tink2123 committed
119
* 检测预测
tink2123's avatar
tink2123 committed
120
121
122
123
124
125
126
127
128
129
130
131
132
133

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

结果是一个list,每个item只包含文本框

```
[[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]]
......
```

tink2123's avatar
tink2123 committed
134
<a name="python_脚本运行"></a>
tink2123's avatar
tink2123 committed
135
136
137
138
### 2.2 python 脚本运行

ppocr 也支持在python脚本中运行,便于嵌入到您自己的代码中:

tink2123's avatar
tink2123 committed
139
* 整图预测(检测+识别)
tink2123's avatar
tink2123 committed
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164

```
from paddleocr import PaddleOCR, draw_ocr

# 同样也是通过修改 lang 参数切换语种
ocr = PaddleOCR(lang="korean") # 首次执行会自动下载模型文件
img_path = 'doc/imgs/korean_1.jpg '
result = ocr.ocr(img_path)
# 打印检测框和识别结果
for line in result:
    print(line)

# 可视化
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]
im_show = draw_ocr(image, boxes, txts, scores, font_path='/path/to/PaddleOCR/doc/korean.ttf')
im_show = Image.fromarray(im_show)
im_show.save('result.jpg')
```

结果可视化:

tink2123's avatar
tink2123 committed
165
166
167
<div align="center">
    <img src="https://raw.githubusercontent.com/PaddlePaddle/PaddleOCR/release/2.1/doc/imgs_results/korean.jpg" width="800">
</div>
tink2123's avatar
tink2123 committed
168

tink2123's avatar
tink2123 committed
169
* 识别预测
tink2123's avatar
tink2123 committed
170
171
172
173
174
175
176
177
178
179

```
from paddleocr import PaddleOCR
ocr = PaddleOCR(lang="german")
img_path = 'PaddleOCR/doc/imgs_words/german/1.jpg'
result = ocr.ocr(img_path, det=False, cls=True)
for line in result:
    print(line)
```

tink2123's avatar
tink2123 committed
180
181

![](../imgs_words/german/1.jpg)
tink2123's avatar
tink2123 committed
182
183
184
185
186
187
188

结果是一个tuple,只包含识别结果和识别置信度

```
('leider auch jetzt', 0.97538936)
```

tink2123's avatar
tink2123 committed
189
* 检测预测
tink2123's avatar
tink2123 committed
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214

```python
from paddleocr import PaddleOCR, draw_ocr
ocr = PaddleOCR() # need to run only once to download and load model into memory
img_path = 'PaddleOCR/doc/imgs_en/img_12.jpg'
result = ocr.ocr(img_path, rec=False)
for line in result:
    print(line)

# 显示结果
from PIL import Image

image = Image.open(img_path).convert('RGB')
im_show = draw_ocr(image, result, txts=None, scores=None, font_path='/path/to/PaddleOCR/doc/fonts/simfang.ttf')
im_show = Image.fromarray(im_show)
im_show.save('result.jpg')
```
结果是一个list,每个item只包含文本框
```bash
[[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]]
......
```

tink2123's avatar
tink2123 committed
215
结果可视化 :
tink2123's avatar
tink2123 committed
216
217
218
219

<div align="center">
    <img src="https://raw.githubusercontent.com/PaddlePaddle/PaddleOCR/release/2.1/doc/imgs_results/whl/12_det.jpg" width="800">
</div>
tink2123's avatar
tink2123 committed
220
221
222

ppocr 还支持方向分类, 更多使用方式请参考:[whl包使用说明](https://github.com/PaddlePaddle/PaddleOCR/blob/release/2.0/doc/doc_ch/whl.md)

tink2123's avatar
tink2123 committed
223
224
<a name="自定义训练"></a>
## 3 自定义训练
tink2123's avatar
tink2123 committed
225
226
227
228
229
230
231
232

ppocr 支持使用自己的数据进行自定义训练或finetune, 其中识别模型可以参考 [法语配置文件](../../configs/rec/multi_language/rec_french_lite_train.yml)
修改训练数据路径、字典等参数。

具体数据准备、训练过程可参考:[文本检测](../doc_ch/detection.md)[文本识别](../doc_ch/recognition.md),更多功能如预测部署、
数据标注等功能可以阅读完整的[文档教程](../../README_ch.md)

<a name="语种缩写"></a>
tink2123's avatar
tink2123 committed
233
## 4 支持语种及缩写
tink2123's avatar
tink2123 committed
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263

| 语种 | 描述 | 缩写 |
| --- | --- | --- |
|中文|chinese and english|ch|
|英文|english|en|
|法文|french|fr|
|德文|german|german|
|日文|japan|japan|
|韩文|korean|korean|
|中文繁体|chinese traditional |ch_tra|
|意大利文| Italian |it|
|西班牙文|Spanish |es|
|葡萄牙文| Portuguese|pt|
|俄罗斯文|Russia|ru|
|阿拉伯文|Arabic|ar|
|印地文|Hindi|hi|
|维吾尔|Uyghur|ug|
|波斯文|Persian|fa|
|乌尔都文|Urdu|ur|
|塞尔维亚文(latin)| Serbian(latin) |rs_latin|
|欧西坦文|Occitan |oc|
|马拉地文|Marathi|mr|
|尼泊尔文|Nepali|ne|
|塞尔维亚文(cyrillic)|Serbian(cyrillic)|rs_cyrillic|
|保加利亚文|Bulgarian |bg|
|乌克兰文|Ukranian|uk|
|白俄罗斯文|Belarusian|be|
|泰卢固文|Telugu |te|
|卡纳达文|Kannada |kn|
|泰米尔文|Tamil |ta|
tink2123's avatar
tink2123 committed
264
|南非荷兰文 |Afrikaans |af|
tink2123's avatar
tink2123 committed
265
|阿塞拜疆文 |Azerbaijani    |az|
tink2123's avatar
tink2123 committed
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
|波斯尼亚文|Bosnian|bs|
|捷克文|Czech|cs|
|威尔士文 |Welsh |cy|
|丹麦文 |Danish|da|
|爱沙尼亚文 |Estonian |et|
|爱尔兰文 |Irish |ga|
|克罗地亚文|Croatian |hr|
|匈牙利文|Hungarian |hu|
|印尼文|Indonesian|id|
|冰岛文 |Icelandic|is|
|库尔德文 |Kurdish|ku|
|立陶宛文|Lithuanian |lt|
|拉脱维亚文 |Latvian |lv|
|毛利文|Maori|mi|
|马来文 |Malay|ms|
|马耳他文 |Maltese |mt|
|荷兰文 |Dutch |nl|
|挪威文 |Norwegian |no|
|波兰文|Polish |pl|
| 罗马尼亚文|Romanian |ro|
| 斯洛伐克文|Slovak |sk|
| 斯洛文尼亚文|Slovenian |sl|
| 阿尔巴尼亚文|Albanian |sq|
| 瑞典文|Swedish |sv|
| 西瓦希里文|Swahili |sw|
| 塔加洛文|Tagalog |tl|
| 土耳其文|Turkish |tr|
| 乌兹别克文|Uzbek |uz|
| 越南文|Vietnamese |vi|
| 蒙古文|Mongolian |mn|
| 阿巴扎文|Abaza |abq|
| 阿迪赫文|Adyghe |ady|
| 卡巴丹文|Kabardian |kbd|
| 阿瓦尔文|Avar |ava|
| 达尔瓦文|Dargwa |dar|
| 因古什文|Ingush |inh|
| 拉克文|Lak |lbe|
| 莱兹甘文|Lezghian |lez|
|塔巴萨兰文 |Tabassaran |tab|
| 比尔哈文|Bihari |bh|
| 迈蒂利文|Maithili |mai|
| 昂加文|Angika |ang|
| 孟加拉文|Bhojpuri |bho|
| 摩揭陀文 |Magahi |mah|
| 那格浦尔文|Nagpur |sck|
| 尼瓦尔文|Newari |new|
| 保加利亚文 |Goan Konkani|gom|
| 沙特阿拉伯文|Saudi Arabia|sa|