"vscode:/vscode.git/clone" did not exist on "1d05ebdc340ff99b7dd1bfc08a1ebb2e6cf833ec"
quickstart.md 6.63 KB
Newer Older
dyning's avatar
dyning committed
1

dyning's avatar
dyning committed
2
# 中文OCR模型快速使用
dyning's avatar
dyning committed
3
4
5
6
7

## 1.环境配置

请先参考[快速安装](./installation.md)配置PaddleOCR运行环境。

8
*注意:也可以通过 whl 包安装使用PaddleOCR,具体参考[Paddleocr Package使用说明](./whl.md)。*
dyning's avatar
dyning committed
9

dyning's avatar
dyning committed
10
11
## 2.inference模型下载

WenmuZhou's avatar
WenmuZhou committed
12
* 移动端和服务器端的检测与识别模型如下,更多模型下载(包括多语言),可以参考[PP-OCR v2.0 系列模型下载](../doc_ch/models_list.md)
dyning's avatar
dyning committed
13

WenmuZhou's avatar
WenmuZhou committed
14
15
| 模型简介     | 模型名称     |推荐场景          | 检测模型 | 方向分类器 | 识别模型 |
| ------------ | --------------- | ----------------|---- | ---------- | -------- |
WenmuZhou's avatar
WenmuZhou committed
16
| 中英文超轻量OCR模型(8.1M) | ch_ppocr_mobile_v2.0_xx |移动端&服务器端|[推理模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_det_infer.tar) / [预训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_det_train.tar)|[推理模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_cls_infer.tar) / [预训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_cls_train.tar) |[推理模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_rec_infer.tar) / [预训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_rec_pre.tar)      |
WenmuZhou's avatar
WenmuZhou committed
17
| 中英文通用OCR模型(143M)   | ch_ppocr_server_v2.0_xx |服务器端 |[推理模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_server_v2.0_det_infer.tar) / [预训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_server_v2.0_det_train.tar)          |[推理模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_cls_infer.tar) / [预训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_cls_train.tar)    |[推理模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_server_v2.0_rec_infer.tar) / [预训练模型](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_server_v2.0_rec_pre.tar)  |
WenmuZhou's avatar
WenmuZhou committed
18
19
20


* windows 环境下如果没有安装wget,下载模型时可将链接复制到浏览器中下载,并解压放置在相应目录下
dyning's avatar
dyning committed
21
22
23
24
25
26
27
28
29

复制上表中的检测和识别的`inference模型`下载地址,并解压

```
mkdir inference && cd inference
# 下载检测模型并解压
wget {url/of/detection/inference_model} && tar xf {name/of/detection/inference_model/package}
# 下载识别模型并解压
wget {url/of/recognition/inference_model} && tar xf {name/of/recognition/inference_model/package}
WenmuZhou's avatar
WenmuZhou committed
30
31
# 下载方向分类器模型并解压
wget {url/of/classification/inference_model} && tar xf {name/of/classification/inference_model/package}
dyning's avatar
dyning committed
32
33
34
35
36
37
38
39
cd ..
```

以超轻量级模型为例:

```
mkdir inference && cd inference
# 下载超轻量级中文OCR模型的检测模型并解压
WenmuZhou's avatar
WenmuZhou committed
40
wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_det_infer.tar && tar xf ch_ppocr_mobile_v2.0_det_infer.tar
dyning's avatar
dyning committed
41
# 下载超轻量级中文OCR模型的识别模型并解压
WenmuZhou's avatar
WenmuZhou committed
42
wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_rec_infer.tar && tar xf ch_ppocr_mobile_v2.0_rec_infer.tar
WenmuZhou's avatar
WenmuZhou committed
43
# 下载超轻量级中文OCR模型的文本方向分类器模型并解压
WenmuZhou's avatar
WenmuZhou committed
44
wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_cls_infer.tar && tar xf ch_ppocr_mobile_v2.0_cls_infer.tar
dyning's avatar
dyning committed
45
46
47
48
49
50
cd ..
```

解压完毕后应有如下文件结构:

```
WenmuZhou's avatar
WenmuZhou committed
51
52
53
54
55
56
57
58
59
60
61
62
├── ch_ppocr_mobile_v2.0_cls_infer
│   ├── inference.pdiparams
│   ├── inference.pdiparams.info
│   └── inference.pdmodel
├── ch_ppocr_mobile_v2.0_det_infer
│   ├── inference.pdiparams
│   ├── inference.pdiparams.info
│   └── inference.pdmodel
├── ch_ppocr_mobile_v2.0_rec_infer
    ├── inference.pdiparams
    ├── inference.pdiparams.info
    └── inference.pdmodel
dyning's avatar
dyning committed
63
64
65
66
```

## 3.单张图像或者图像集合预测

67
以下代码实现了文本检测、方向分类器和识别串联推理,在执行预测时,需要通过参数image_dir指定单张图像或者图像集合的路径、参数`det_model_dir`指定检测inference模型的路径、参数`rec_model_dir`指定识别inference模型的路径、参数`use_angle_cls`指定是否使用方向分类器、参数`cls_model_dir`指定方向分类器inference模型的路径、参数`use_space_char`指定是否预测空格字符。可视化识别结果默认保存到`./inference_results`文件夹里面。
dyning's avatar
dyning committed
68
69
70
71

```bash

# 预测image_dir指定的单张图像
WenmuZhou's avatar
WenmuZhou committed
72
python3 tools/infer/predict_system.py --image_dir="./doc/imgs/11.jpg" --det_model_dir="./inference/ch_ppocr_mobile_v2.0_det_infer/"  --rec_model_dir="./inference/ch_ppocr_mobile_v2.0_rec_infer/" --cls_model_dir="./inference/ch_ppocr_mobile_v2.0_cls_infer/" --use_angle_cls=True --use_space_char=True
dyning's avatar
dyning committed
73
74

# 预测image_dir指定的图像集合
WenmuZhou's avatar
WenmuZhou committed
75
python3 tools/infer/predict_system.py --image_dir="./doc/imgs/" --det_model_dir="./inference/ch_ppocr_mobile_v2.0_det_infer/"  --rec_model_dir="./inference/ch_ppocr_mobile_v2.0_rec_infer/" --cls_model_dir="./inference/ch_ppocr_mobile_v2.0_cls_infer/" --use_angle_cls=True --use_space_char=True
dyning's avatar
dyning committed
76
77

# 如果想使用CPU进行预测,需设置use_gpu参数为False
WenmuZhou's avatar
WenmuZhou committed
78
python3 tools/infer/predict_system.py --image_dir="./doc/imgs/11.jpg" --det_model_dir="./inference/ch_ppocr_mobile_v2.0_det_infer/"  --rec_model_dir="./inference/ch_ppocr_mobile_v2.0_rec_infer/" --cls_model_dir="./inference/ch_ppocr_mobile_v2.0_cls_infer/" --use_angle_cls=True --use_space_char=True --use_gpu=False
dyning's avatar
dyning committed
79
80
```

tink2123's avatar
tink2123 committed
81
82
83
- 通用中文OCR模型

请按照上述步骤下载相应的模型,并且更新相关的参数,示例如下:
WenmuZhou's avatar
WenmuZhou committed
84
85

```bash
dyning's avatar
dyning committed
86
# 预测image_dir指定的单张图像
WenmuZhou's avatar
WenmuZhou committed
87
python3 tools/infer/predict_system.py --image_dir="./doc/imgs/11.jpg" --det_model_dir="./inference/ch_ppocr_server_v2.0_det_infer/"  --rec_model_dir="./inference/ch_ppocr_server_v2.0_rec_infer/" --cls_model_dir="./inference/ch_ppocr_mobile_v2.0_cls_infer/" --use_angle_cls=True --use_space_char=True
dyning's avatar
dyning committed
88
89
```

WenmuZhou's avatar
WenmuZhou committed
90
91
92
* 注意:
    - 如果希望使用不支持空格的识别模型,在预测的时候需要注意:请将代码更新到最新版本,并添加参数 `--use_space_char=False`
    - 如果不希望使用方向分类器,在预测的时候需要注意:请将代码更新到最新版本,并添加参数 `--use_angle_cls=False`
tink2123's avatar
tink2123 committed
93

dyning's avatar
dyning committed
94

dyning's avatar
dyning committed
95
更多的文本检测、识别串联推理使用方式请参考文档教程中[基于Python预测引擎推理](./inference.md)
dyning's avatar
dyning committed
96
97

此外,文档教程中也提供了中文OCR模型的其他预测部署方式:
dyning's avatar
dyning committed
98
- [基于C++预测引擎推理](../../deploy/cpp_infer/readme.md)
MissPenguin's avatar
MissPenguin committed
99
- [服务部署](../../deploy/hubserving)
MissPenguin's avatar
MissPenguin committed
100
- [端侧部署(目前只支持静态图)](https://github.com/PaddlePaddle/PaddleOCR/tree/develop/deploy/lite)