quickstart.md 5.1 KB
Newer Older
D
dyning 已提交
1

D
dyning 已提交
2
# 中文OCR模型快速使用
D
dyning 已提交
3 4 5 6 7

## 1.环境配置

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

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

D
dyning 已提交
10 11
## 2.inference模型下载

W
WenmuZhou 已提交
12
* 移动端和服务器端的检测与识别模型如下,更多模型下载(包括多语言),可以参考[PP-OCR v1.1 系列模型下载](../doc_ch/models_list.md)
D
dyning 已提交
13

W
WenmuZhou 已提交
14 15
| 模型简介     | 模型名称     |推荐场景          | 检测模型 | 方向分类器 | 识别模型 |
| ------------ | --------------- | ----------------|---- | ---------- | -------- |
16 17
| 中英文超轻量OCR模型(xM) |  |移动端&服务器端|[推理模型](link) / [预训练模型](link)|[推理模型]({}) / [预训练模型]({}) |[推理模型]({}) / [预训练模型]({})      |
| 中英文通用OCR模型(xM)   | |服务器端 |[推理模型]({}) / [预训练模型]({})          |[推理模型]({}) / [预训练模型]({})    |[推理模型]({}) / [预训练模型]({}})  |
W
WenmuZhou 已提交
18 19 20


* windows 环境下如果没有安装wget,下载模型时可将链接复制到浏览器中下载,并解压放置在相应目录下
D
dyning 已提交
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}
W
WenmuZhou 已提交
30 31
# 下载方向分类器模型并解压
wget {url/of/classification/inference_model} && tar xf {name/of/classification/inference_model/package}
D
dyning 已提交
32 33 34 35 36 37 38 39
cd ..
```

以超轻量级模型为例:

```
mkdir inference && cd inference
# 下载超轻量级中文OCR模型的检测模型并解压
40
wget {} && tar xf ch_ppocr_mobile_v1.1_det_infer.tar
D
dyning 已提交
41
# 下载超轻量级中文OCR模型的识别模型并解压
42
wget {} && tar xf ch_ppocr_mobile_v1.1_rec_infer.tar
W
WenmuZhou 已提交
43
# 下载超轻量级中文OCR模型的文本方向分类器模型并解压
44
wget {} && tar xf ch_ppocr_mobile_v1.1_cls_infer.tar
D
dyning 已提交
45 46 47 48 49 50 51
cd ..
```

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

```
|-inference
W
WenmuZhou 已提交
52 53 54 55
    |-ch_ppocr_mobile_v1.1_det_infer
        |- model
        |- params
    |-ch_ppocr_mobile_v1.1_rec_infer
D
dyning 已提交
56 57
        |- model
        |- params
W
WenmuZhou 已提交
58
    |-ch_ppocr_mobile-v1.1_cls_infer
D
dyning 已提交
59 60 61 62 63 64 65
        |- model
        |- params
    ...
```

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

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

```bash

# 预测image_dir指定的单张图像
W
WenmuZhou 已提交
71
python3 tools/infer/predict_system.py --image_dir="./doc/imgs/11.jpg" --det_model_dir="./inference/ch_ppocr_mobile_v1.1_det_infer/"  --rec_model_dir="./inference/ch_ppocr_mobile_v1.1_rec_infer/" --cls_model_dir="./inference/ch_ppocr_mobile_v1.1_cls_infer/" --use_angle_cls=True --use_space_char=True
D
dyning 已提交
72 73

# 预测image_dir指定的图像集合
W
WenmuZhou 已提交
74
python3 tools/infer/predict_system.py --image_dir="./doc/imgs/" --det_model_dir="./inference/ch_ppocr_mobile_v1.1_det_infer/"  --rec_model_dir="./inference/ch_ppocr_mobile_v1.1_rec_infer/" --cls_model_dir="./inference/ch_ppocr_mobile_v1.1_cls_infer/" --use_angle_cls=True --use_space_char=True
D
dyning 已提交
75 76

# 如果想使用CPU进行预测,需设置use_gpu参数为False
W
WenmuZhou 已提交
77
python3 tools/infer/predict_system.py --image_dir="./doc/imgs/11.jpg" --det_model_dir="./inference/ch_ppocr_mobile_v1.1_det_infer/"  --rec_model_dir="./inference/ch_ppocr_mobile_v1.1_rec_infer/" --cls_model_dir="./inference/ch_ppocr_mobile_v1.1_cls_infer/" --use_angle_cls=True --use_space_char=True --use_gpu=False
D
dyning 已提交
78 79
```

T
tink2123 已提交
80 81 82
- 通用中文OCR模型

请按照上述步骤下载相应的模型,并且更新相关的参数,示例如下:
W
WenmuZhou 已提交
83 84

```bash
D
dyning 已提交
85
# 预测image_dir指定的单张图像
W
WenmuZhou 已提交
86
python3 tools/infer/predict_system.py --image_dir="./doc/imgs/11.jpg" --det_model_dir="./inference/ch_ppocr_server_v1.1_det_infer/"  --rec_model_dir="./inference/ch_ppocr_server_v1.1_rec_infer/" --cls_model_dir="./inference/ch_ppocr_mobile_v1.1_cls_infer/" --use_angle_cls=True --use_space_char=True
D
dyning 已提交
87 88
```

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

D
dyning 已提交
93

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

此外,文档教程中也提供了中文OCR模型的其他预测部署方式:
D
dyning 已提交
97
- [基于C++预测引擎推理](../../deploy/cpp_infer/readme.md)
W
WenmuZhou 已提交
98
- [服务部署](../../deploy/pdserving/readme.md)
D
dyning 已提交
99
- [端侧部署](../../deploy/lite/readme.md)