quickstart_en.md 7.2 KB
Newer Older
littletomatodonkey's avatar
littletomatodonkey 已提交
1 2 3 4 5 6 7

# Quick start of Chinese OCR model

## 1. Prepare for the environment

Please refer to [quick installation](./installation_en.md) to configure the PaddleOCR operating environment.

littletomatodonkey's avatar
littletomatodonkey 已提交
8
* Note: Support the use of PaddleOCR through whl package installation,pelease refer  [PaddleOCR Package](https://github.com/PaddlePaddle/PaddleOCR/blob/develop/doc/doc_en/whl_en.md).
littletomatodonkey's avatar
littletomatodonkey 已提交
9 10 11

## 2.inference models

12
The detection and recognition models on the mobile and server sides are as follows. For more models  (including multiple languages), please refer to [PP-OCR v1.1 series model list](../doc_ch/models_list.md)
littletomatodonkey's avatar
littletomatodonkey 已提交
13

littletomatodonkey's avatar
littletomatodonkey 已提交
14 15 16

| Model introduction    | Model name     |  Recommended scene      | Detection model | Direction Classifier | Recognition model |
| ------------ | --------------- | ----------------|---- | ---------- | -------- |
T
tink2123 已提交
17 18
| Ultra-lightweight Chinese OCR model(8.1M) | ch_ppocr_mobile_v1.1_xx |Mobile-side/Server-side|[inference model](https://paddleocr.bj.bcebos.com/20-09-22/mobile/det/ch_ppocr_mobile_v1.1_det_infer.tar) / [pretrained model](https://paddleocr.bj.bcebos.com/20-09-22/mobile/det/ch_ppocr_mobile_v1.1_det_train.tar)|[inference model](https://paddleocr.bj.bcebos.com/20-09-22/cls/ch_ppocr_mobile_v1.1_cls_infer.tar) / [pretrained model](https://paddleocr.bj.bcebos.com/20-09-22/cls/ch_ppocr_mobile_v1.1_cls_train.tar) |[inference model](https://paddleocr.bj.bcebos.com/20-09-22/mobile/rec/ch_ppocr_mobile_v1.1_rec_infer.tar) / [pretrained model](https://paddleocr.bj.bcebos.com/20-09-22/mobile/rec/ch_ppocr_mobile_v1.1_rec_pre.tar)      |
| Universal Chinese OCR model(155.1M)   |ch_ppocr_server_v1.1_xx|Server-side |[inference model](https://paddleocr.bj.bcebos.com/20-09-22/server/det/ch_ppocr_server_v1.1_det_infer.tar) / [pretrained model](https://paddleocr.bj.bcebos.com/20-09-22/server/det/ch_ppocr_server_v1.1_det_train.tar)          |[inference model](https://paddleocr.bj.bcebos.com/20-09-22/cls/ch_ppocr_mobile_v1.1_cls_infer.tar) / [pretrained model](https://paddleocr.bj.bcebos.com/20-09-22/cls/ch_ppocr_mobile_v1.1_cls_train.tar)    |[inference model](https://paddleocr.bj.bcebos.com/20-09-22/server/rec/ch_ppocr_server_v1.1_rec_infer.tar) / [pretrained model](https://paddleocr.bj.bcebos.com/20-09-22/server/rec/ch_ppocr_server_v1.1_rec_pre.tar)  |
littletomatodonkey's avatar
littletomatodonkey 已提交
19

littletomatodonkey's avatar
littletomatodonkey 已提交
20
* If `wget` is not installed in the windows environment, you can copy the link to the browser to download when downloading the model, then uncompress it and place it in the corresponding directory.
littletomatodonkey's avatar
littletomatodonkey 已提交
21 22 23 24 25 26 27 28 29

Copy the download address of the `inference model` for detection and recognition in the table above, and uncompress them.

```
mkdir inference && cd inference
# Download the detection model and unzip
wget {url/of/detection/inference_model} && tar xf {name/of/detection/inference_model/package}
# Download the recognition model and unzip
wget {url/of/recognition/inference_model} && tar xf {name/of/recognition/inference_model/package}
littletomatodonkey's avatar
littletomatodonkey 已提交
30 31
# Download the direction classifier model and unzip
wget {url/of/classification/inference_model} && tar xf {name/of/classification/inference_model/package}
littletomatodonkey's avatar
littletomatodonkey 已提交
32 33 34 35 36 37 38 39
cd ..
```

Take the ultra-lightweight model as an example:

```
mkdir inference && cd inference
# Download the detection model of the ultra-lightweight Chinese OCR model and uncompress it
littletomatodonkey's avatar
littletomatodonkey 已提交
40
wget https://paddleocr.bj.bcebos.com/20-09-22/mobile/det/ch_ppocr_mobile_v1.1_det_infer.tar && tar xf ch_ppocr_mobile_v1.1_det_infer.tar
littletomatodonkey's avatar
littletomatodonkey 已提交
41
# Download the recognition model of the ultra-lightweight Chinese OCR model and uncompress it
littletomatodonkey's avatar
littletomatodonkey 已提交
42 43
wget https://paddleocr.bj.bcebos.com/20-09-22/mobile/rec/ch_ppocr_mobile_v1.1_rec_infer.tar && tar xf ch_ppocr_mobile_v1.1_rec_infer.tar
# Download the direction classifier model of the ultra-lightweight Chinese OCR model and uncompress it
littletomatodonkey's avatar
littletomatodonkey 已提交
44
wget https://paddleocr.bj.bcebos.com/20-09-22/cls/ch_ppocr_mobile_v1.1_cls_infer.tar && tar xf ch_ppocr_mobile_v1.1_cls_infer.tar
littletomatodonkey's avatar
littletomatodonkey 已提交
45 46 47 48 49 50 51
cd ..
```

After decompression, the file structure should be as follows:

```
|-inference
littletomatodonkey's avatar
littletomatodonkey 已提交
52 53 54 55
    |-ch_ppocr_mobile_v1.1_det_infer
        |- model
        |- params
    |-ch_ppocr_mobile_v1.1_rec_infer
littletomatodonkey's avatar
littletomatodonkey 已提交
56 57
        |- model
        |- params
littletomatodonkey's avatar
littletomatodonkey 已提交
58
    |-ch_ppocr_mobile_v1.1_cls_infer
littletomatodonkey's avatar
littletomatodonkey 已提交
59 60 61 62 63 64 65
        |- model
        |- params
    ...
```

## 3. Single image or image set prediction

littletomatodonkey's avatar
littletomatodonkey 已提交
66
* The following code implements text detection and recognition process. When performing prediction, you need to specify the path of a single image or image set through the parameter `image_dir`, the parameter `det_model_dir` specifies the path to detect the inference model, the parameter `rec_model_dir` specifies the path to identify the inference model, the parameter `use_angle_cls` specifies whether to use the direction classifier, the parameter `cls_model_dir` specifies the path to identify the direction classifier model, the parameter `use_space_char` specifies whether to predict the space char. The visual results are saved to the `./inference_results` folder by default.
littletomatodonkey's avatar
littletomatodonkey 已提交
67 68 69 70 71 72



```bash

# Predict a single image specified by image_dir
littletomatodonkey's avatar
littletomatodonkey 已提交
73
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
littletomatodonkey's avatar
littletomatodonkey 已提交
74 75

# Predict imageset specified by image_dir
littletomatodonkey's avatar
littletomatodonkey 已提交
76
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
littletomatodonkey's avatar
littletomatodonkey 已提交
77 78

# If you want to use the CPU for prediction, you need to set the use_gpu parameter to False
littletomatodonkey's avatar
littletomatodonkey 已提交
79
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
littletomatodonkey's avatar
littletomatodonkey 已提交
80 81 82 83 84 85 86 87
```

- Universal Chinese OCR model

Please follow the above steps to download the corresponding models and update the relevant parameters, The example is as follows.

```
# Predict a single image specified by image_dir
littletomatodonkey's avatar
littletomatodonkey 已提交
88
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
littletomatodonkey's avatar
littletomatodonkey 已提交
89 90
```

littletomatodonkey's avatar
littletomatodonkey 已提交
91 92 93
* Note
    - If you want to use the recognition model which does not support space char recognition, please update the source code to the latest version and add parameters `--use_space_char=False`.
    - If you do not want to use direction classifier, please update the source code to the latest version and add parameters `--use_angle_cls=False`.
littletomatodonkey's avatar
littletomatodonkey 已提交
94 95 96 97 98 99 100


For more text detection and recognition tandem reasoning, please refer to the document tutorial
: [Inference with Python inference engine](./inference_en.md)

In addition, the tutorial also provides other deployment methods for the Chinese OCR model:
- [Server-side C++ inference](../../deploy/cpp_infer/readme_en.md)
L
littletomatodonkey 已提交
101
- [Service deployment](../../deploy/hubserving/readme_en.md)
littletomatodonkey's avatar
littletomatodonkey 已提交
102
- [End-to-end deployment](../../deploy/lite/readme_en.md)