recognition_en.md 19 KB
Newer Older
xxxpsyduck's avatar
xxxpsyduck committed
1
## TEXT RECOGNITION
Khanh Tran's avatar
Khanh Tran committed
2

WenmuZhou's avatar
WenmuZhou committed
3
4
5
6
7
- [1 DATA PREPARATION](#DATA_PREPARATION)
    - [1.1 Costom Dataset](#Costom_Dataset)
    - [1.2 Dataset Download](#Dataset_download)
    - [1.3 Dictionary](#Dictionary)  
    - [1.4 Add Space Category](#Add_space_category)
WenmuZhou's avatar
WenmuZhou committed
8

WenmuZhou's avatar
WenmuZhou committed
9
10
11
12
- [2 TRAINING](#TRAINING)
    - [2.1 Data Augmentation](#Data_Augmentation)
    - [2.2 Training](#Training)
    - [2.3 Multi-language](#Multi_language)
WenmuZhou's avatar
WenmuZhou committed
13

WenmuZhou's avatar
WenmuZhou committed
14
- [3 EVALUATION](#EVALUATION)
WenmuZhou's avatar
WenmuZhou committed
15

WenmuZhou's avatar
WenmuZhou committed
16
17
- [4 PREDICTION](#PREDICTION)
    - [4.1 Training engine prediction](#Training_engine_prediction)
WenmuZhou's avatar
WenmuZhou committed
18
19

<a name="DATA_PREPARATION"></a>
xxxpsyduck's avatar
xxxpsyduck committed
20
### DATA PREPARATION
Khanh Tran's avatar
Khanh Tran committed
21
22


WenmuZhou's avatar
WenmuZhou committed
23
24
25
PaddleOCR supports two data formats:
- `LMDB` is used to train data sets stored in lmdb format;
- `general data` is used to train data sets stored in text files:
Khanh Tran's avatar
Khanh Tran committed
26
27
28
29
30
31

Please organize the dataset as follows:

The default storage path for training data is `PaddleOCR/train_data`, if you already have a dataset on your disk, just create a soft link to the dataset directory:

```
WenmuZhou's avatar
WenmuZhou committed
32
# linux and mac os
33
ln -sf <path/to/dataset> <path/to/paddle_ocr>/train_data/dataset
WenmuZhou's avatar
WenmuZhou committed
34
35
# windows
mklink /d <path/to/paddle_ocr>/train_data/dataset <path/to/dataset>
Khanh Tran's avatar
Khanh Tran committed
36
37
```

WenmuZhou's avatar
WenmuZhou committed
38
<a name="Costom_Dataset"></a>
WenmuZhou's avatar
WenmuZhou committed
39
#### 1.1 Costom dataset
Khanh Tran's avatar
Khanh Tran committed
40
41
42
43
44

If you want to use your own data for training, please refer to the following to organize your data.

- Training set

WenmuZhou's avatar
WenmuZhou committed
45
It is recommended to put the training images in the same folder, and use a txt file (rec_gt_train.txt) to store the image path and label. The contents of the txt file are as follows:
Khanh Tran's avatar
Khanh Tran committed
46
47
48
49
50
51

* Note: by default, the image path and image label are split with \t, if you use other methods to split, it will cause training error

```
" Image file name           Image annotation "

WenmuZhou's avatar
WenmuZhou committed
52
53
train_data/rec/train/word_001.jpg   简单可依赖
train_data/rec/train/word_002.jpg   用科技让复杂的世界更简单
WenmuZhou's avatar
WenmuZhou committed
54
...
Khanh Tran's avatar
Khanh Tran committed
55
56
57
58
59
60
```

The final training set should have the following file structure:

```
|-train_data
WenmuZhou's avatar
WenmuZhou committed
61
  |-rec
WenmuZhou's avatar
WenmuZhou committed
62
63
64
65
66
67
    |- rec_gt_train.txt
    |- train
        |- word_001.png
        |- word_002.jpg
        |- word_003.jpg
        | ...
Khanh Tran's avatar
Khanh Tran committed
68
69
70
71
72
73
74
75
```

- Test set

Similar to the training set, the test set also needs to be provided a folder containing all images (test) and a rec_gt_test.txt. The structure of the test set is as follows:

```
|-train_data
WenmuZhou's avatar
WenmuZhou committed
76
  |-rec
Khanh Tran's avatar
Khanh Tran committed
77
78
79
80
81
82
83
84
    |-ic15_data
        |- rec_gt_test.txt
        |- test
            |- word_001.jpg
            |- word_002.jpg
            |- word_003.jpg
            | ...
```
WenmuZhou's avatar
WenmuZhou committed
85
86
87
88
89
90
91
92

<a name="Dataset_download"></a>
#### 1.2 Dataset download

If you do not have a dataset locally, you can download it on the official website [icdar2015](http://rrc.cvc.uab.es/?ch=4&com=downloads). Also refer to [DTRB](https://github.com/clovaai/deep-text-recognition-benchmark#download-lmdb-dataset-for-traininig-and-evaluation-from-here) ,download the lmdb format dataset required for benchmark

If you want to reproduce the paper indicators of SRN, you need to download offline [augmented data](https://pan.baidu.com/s/1-HSZ-ZVdqBF2HaBZ5pRAKA), extraction code: y3ry. The augmented data is obtained by rotation and perturbation of mjsynth and synthtext. Please unzip the data to {your_path}/PaddleOCR/train_data/data_lmdb_Release/training/path.

93
94
If you want to reproduce the paper SAR, you need to download extra dataset [SynthAdd](https://pan.baidu.com/share/init?surl=uV0LtoNmcxbO-0YA7Ch4dg), extraction code: 627x. Besides, icdar2013, icdar2015, cocotext, IIIT5k datasets are also used to train. For specific details, please refer to the paper SAR.

WenmuZhou's avatar
WenmuZhou committed
95
96
97
98
99
100
101
102
103
PaddleOCR provides label files for training the icdar2015 dataset, which can be downloaded in the following ways:

```
# Training set label
wget -P ./train_data/ic15_data  https://paddleocr.bj.bcebos.com/dataset/rec_gt_train.txt
# Test Set Label
wget -P ./train_data/ic15_data  https://paddleocr.bj.bcebos.com/dataset/rec_gt_test.txt
```

WenmuZhou's avatar
WenmuZhou committed
104
<a name="Dictionary"></a>
WenmuZhou's avatar
WenmuZhou committed
105
#### 1.3 Dictionary
Khanh Tran's avatar
Khanh Tran committed
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121

Finally, a dictionary ({word_dict_name}.txt) needs to be provided so that when the model is trained, all the characters that appear can be mapped to the dictionary index.

Therefore, the dictionary needs to contain all the characters that you want to be recognized correctly. {word_dict_name}.txt needs to be written in the following format and saved in the `utf-8` encoding format:

```
l
d
a
d
r
n
```

In `word_dict.txt`, there is a single word in each line, which maps characters and numeric indexes together, e.g "and" will be mapped to [2 5 1]

WenmuZhou's avatar
WenmuZhou committed
122
123
PaddleOCR has built-in dictionaries, which can be used on demand.

Khanh Tran's avatar
Khanh Tran committed
124
125
`ppocr/utils/ppocr_keys_v1.txt` is a Chinese dictionary with 6623 characters.

WenmuZhou's avatar
WenmuZhou committed
126
127
128
129
`ppocr/utils/ic15_dict.txt` is an English dictionary with 63 characters

`ppocr/utils/dict/french_dict.txt` is a French dictionary with 118 characters

130
`ppocr/utils/dict/japan_dict.txt` is a Japanese dictionary with 4399 characters
WenmuZhou's avatar
WenmuZhou committed
131

tink2123's avatar
tink2123 committed
132
`ppocr/utils/dict/korean_dict.txt` is a Korean dictionary with 3636 characters
WenmuZhou's avatar
WenmuZhou committed
133

tink2123's avatar
tink2123 committed
134
135
`ppocr/utils/dict/german_dict.txt` is a German dictionary with 131 characters

tink2123's avatar
tink2123 committed
136
`ppocr/utils/en_dict.txt` is a English dictionary with 96 characters
WenmuZhou's avatar
WenmuZhou committed
137

138

WenmuZhou's avatar
WenmuZhou committed
139
The current multi-language model is still in the demo stage and will continue to optimize the model and add languages. **You are very welcome to provide us with dictionaries and fonts in other languages**,
littletomatodonkey's avatar
fix doc  
littletomatodonkey committed
140
If you like, you can submit the dictionary file to [dict](../../ppocr/utils/dict) and we will thank you in the Repo.
Khanh Tran's avatar
Khanh Tran committed
141
142
143
144


To customize the dict file, please modify the `character_dict_path` field in `configs/rec/rec_icdar15_train.yml` and set `character_type` to `ch`.

tink2123's avatar
tink2123 committed
145
146
147
148
- Custom dictionary

If you need to customize dic file, please add character_dict_path field in configs/rec/rec_icdar15_train.yml to point to your dictionary path. And set character_type to ch.

WenmuZhou's avatar
WenmuZhou committed
149
<a name="Add_space_category"></a>
WenmuZhou's avatar
WenmuZhou committed
150
#### 1.4 Add space category
tink2123's avatar
tink2123 committed
151

xmy0916's avatar
xmy0916 committed
152
If you want to support the recognition of the `space` category, please set the `use_space_char` field in the yml file to `True`.
tink2123's avatar
tink2123 committed
153
154
155

**Note: use_space_char only takes effect when character_type=ch**

WenmuZhou's avatar
WenmuZhou committed
156
<a name="TRAINING"></a>
WenmuZhou's avatar
WenmuZhou committed
157
### 2 TRAINING
Khanh Tran's avatar
Khanh Tran committed
158
159
160
161
162
163
164
165

PaddleOCR provides training scripts, evaluation scripts, and prediction scripts. In this section, the CRNN recognition model will be used as an example:

First download the pretrain model, you can download the trained model to finetune on the icdar2015 data:

```
cd PaddleOCR/
# Download the pre-trained model of MobileNetV3
tink2123's avatar
tink2123 committed
166
wget -P ./pretrain_models/ https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/rec_mv3_none_bilstm_ctc_v2.0_train.tar
Khanh Tran's avatar
Khanh Tran committed
167
168
# Decompress model parameters
cd pretrain_models
tink2123's avatar
tink2123 committed
169
tar -xf rec_mv3_none_bilstm_ctc_v2.0_train.tar && rm -rf rec_mv3_none_bilstm_ctc_v2.0_train.tar
Khanh Tran's avatar
Khanh Tran committed
170
171
172
173
174
```

Start training:

```
xmy0916's avatar
xmy0916 committed
175
# GPU training Support single card and multi-card training, specify the card number through --gpus
tink2123's avatar
tink2123 committed
176
# Training icdar15 English data and The training log will be automatically saved as train.log under "{save_model_dir}"
xmy0916's avatar
xmy0916 committed
177
python3 -m paddle.distributed.launch --gpus '0,1,2,3'  tools/train.py -c configs/rec/rec_icdar15_train.yml
Khanh Tran's avatar
Khanh Tran committed
178
```
WenmuZhou's avatar
WenmuZhou committed
179
<a name="Data_Augmentation"></a>
WenmuZhou's avatar
WenmuZhou committed
180
#### 2.1 Data Augmentation
tink2123's avatar
tink2123 committed
181

littletomatodonkey's avatar
littletomatodonkey committed
182
PaddleOCR provides a variety of data augmentation methods. All the augmentation methods are enabled by default.
tink2123's avatar
tink2123 committed
183

littletomatodonkey's avatar
littletomatodonkey committed
184
The default perturbation methods are: cvtColor, blur, jitter, Gasuss noise, random crop, perspective, color reverse, TIA augmentation.
tink2123's avatar
tink2123 committed
185

littletomatodonkey's avatar
littletomatodonkey committed
186
Each disturbance method is selected with a 40% probability during the training process. For specific code implementation, please refer to: [rec_img_aug.py](../../ppocr/data/imaug/rec_img_aug.py)
tink2123's avatar
tink2123 committed
187

WenmuZhou's avatar
WenmuZhou committed
188
<a name="Training"></a>
WenmuZhou's avatar
WenmuZhou committed
189
#### 2.2 Training
tink2123's avatar
tink2123 committed
190

Khanh Tran's avatar
Khanh Tran committed
191
192
193
194
195
196
197
198
199
PaddleOCR supports alternating training and evaluation. You can modify `eval_batch_step` in `configs/rec/rec_icdar15_train.yml` to set the evaluation frequency. By default, it is evaluated every 500 iter and the best acc model is saved under `output/rec_CRNN/best_accuracy` during the evaluation process.

If the evaluation set is large, the test will be time-consuming. It is recommended to reduce the number of evaluations, or evaluate after training.

* Tip: You can use the `-c` parameter to select multiple model configurations under the `configs/rec/` path for training. The recognition algorithms supported by PaddleOCR are:


| Configuration file |  Algorithm |   backbone |   trans   |   seq      |     pred     |
| :--------: |  :-------:   | :-------:  |   :-------:   |   :-----:   |  :-----:   |
xmy0916's avatar
xmy0916 committed
200
201
| [rec_chinese_lite_train_v2.0.yml](../../configs/rec/ch_ppocr_v2.0/rec_chinese_lite_train_v2.0.yml) |  CRNN |   Mobilenet_v3 small 0.5 |  None   |  BiLSTM |  ctc  |
| [rec_chinese_common_train_v2.0.yml](../../configs/rec/ch_ppocr_v2.0/rec_chinese_common_train_v2.0.yml) |  CRNN | ResNet34_vd |  None   |  BiLSTM |  ctc  |
Khanh Tran's avatar
Khanh Tran committed
202
| rec_chinese_lite_train.yml |  CRNN |   Mobilenet_v3 small 0.5 |  None   |  BiLSTM |  ctc  |
WenmuZhou's avatar
WenmuZhou committed
203
| rec_chinese_common_train.yml |  CRNN |   ResNet34_vd |  None   |  BiLSTM |  ctc  |
Khanh Tran's avatar
Khanh Tran committed
204
205
206
207
208
| rec_icdar15_train.yml |  CRNN |   Mobilenet_v3 large 0.5 |  None   |  BiLSTM |  ctc  |
| rec_mv3_none_bilstm_ctc.yml |  CRNN |   Mobilenet_v3 large 0.5 |  None   |  BiLSTM |  ctc  |
| rec_mv3_none_none_ctc.yml |  Rosetta |   Mobilenet_v3 large 0.5 |  None   |  None |  ctc  |
| rec_r34_vd_none_bilstm_ctc.yml |  CRNN |   Resnet34_vd |  None   |  BiLSTM |  ctc  |
| rec_r34_vd_none_none_ctc.yml |  Rosetta |   Resnet34_vd |  None   |  None |  ctc  |
LDOUBLEV's avatar
LDOUBLEV committed
209
210
| rec_mv3_tps_bilstm_att.yml |  CRNN |   Mobilenet_v3 |  TPS   |  BiLSTM |  att  |
| rec_r34_vd_tps_bilstm_att.yml |  CRNN |   Resnet34_vd |  TPS   |  BiLSTM |  att  |
tink2123's avatar
tink2123 committed
211
| rec_r50fpn_vd_none_srn.yml    | SRN | Resnet50_fpn_vd    | None    | rnn | srn |
Topdu's avatar
Topdu committed
212
| rec_mtb_nrtr.yml    | NRTR | nrtr_mtb    | None    | transformer encoder | transformer decoder |
andyjpaddle's avatar
andyjpaddle committed
213
| rec_r31_sar.yml               | SAR | ResNet31 | None | LSTM encoder | LSTM decoder |
Khanh Tran's avatar
Khanh Tran committed
214
215


WenmuZhou's avatar
WenmuZhou committed
216
For training Chinese data, it is recommended to use
xmy0916's avatar
xmy0916 committed
217
[rec_chinese_lite_train_v2.0.yml](../../configs/rec/ch_ppocr_v2.0/rec_chinese_lite_train_v2.0.yml). If you want to try the result of other algorithms on the Chinese data set, please refer to the following instructions to modify the configuration file:
Khanh Tran's avatar
Khanh Tran committed
218
co
xmy0916's avatar
xmy0916 committed
219
Take `rec_chinese_lite_train_v2.0.yml` as an example:
Khanh Tran's avatar
Khanh Tran committed
220
221
222
```
Global:
  ...
xmy0916's avatar
xmy0916 committed
223
224
  # Add a custom dictionary, such as modify the dictionary, please point the path to the new dictionary
  character_dict_path: ppocr/utils/ppocr_keys_v1.txt
Khanh Tran's avatar
Khanh Tran committed
225
226
227
  # Modify character type
  character_type: ch
  ...
228
  # Whether to recognize spaces
xmy0916's avatar
xmy0916 committed
229
  use_space_char: True
Khanh Tran's avatar
Khanh Tran committed
230

231
232
233
234

Optimizer:
  ...
  # Add learning rate decay strategy
xmy0916's avatar
xmy0916 committed
235
236
237
238
239
240
241
242
243
  lr:
    name: Cosine
    learning_rate: 0.001
  ...

...

Train:
  dataset:
MissPenguin's avatar
MissPenguin committed
244
    # Type of dataset,we support LMDBDataSet and SimpleDataSet
xmy0916's avatar
xmy0916 committed
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
    name: SimpleDataSet
    # Path of dataset
    data_dir: ./train_data/
    # Path of train list
    label_file_list: ["./train_data/train_list.txt"]
    transforms:
      ...
      - RecResizeImg:
          # Modify image_shape to fit long text
          image_shape: [3, 32, 320]
      ...
  loader:
    ...
    # Train batch_size for Single card
    batch_size_per_card: 256
    ...

Eval:
  dataset:
MissPenguin's avatar
MissPenguin committed
264
    # Type of dataset,we support LMDBDataSet and SimpleDataSet
xmy0916's avatar
xmy0916 committed
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
    name: SimpleDataSet
    # Path of dataset
    data_dir: ./train_data
    # Path of eval list
    label_file_list: ["./train_data/val_list.txt"]
    transforms:
      ...
      - RecResizeImg:
          # Modify image_shape to fit long text
          image_shape: [3, 32, 320]
      ...
  loader:
    # Eval batch_size for Single card
    batch_size_per_card: 256
    ...
Khanh Tran's avatar
Khanh Tran committed
280
281
282
```
**Note that the configuration file for prediction/evaluation must be consistent with the training.**

WenmuZhou's avatar
WenmuZhou committed
283
<a name="Multi_language"></a>
WenmuZhou's avatar
WenmuZhou committed
284
#### 2.3 Multi-language
WenmuZhou's avatar
WenmuZhou committed
285

tink2123's avatar
tink2123 committed
286
PaddleOCR currently supports 80 (except Chinese) language recognition. A multi-language configuration file template is
tink2123's avatar
tink2123 committed
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
314
315
316
317
318
319
320
321
322
323
provided under the path `configs/rec/multi_languages`: [rec_multi_language_lite_train.yml](../../configs/rec/multi_language/rec_multi_language_lite_train.yml)

There are two ways to create the required configuration file::

1. Automatically generated by script

[generate_multi_language_configs.py](../../configs/rec/multi_language/generate_multi_language_configs.py) Can help you generate configuration files for multi-language models

- Take Italian as an example, if your data is prepared in the following format:
    ```
    |-train_data
        |- it_train.txt # train_set label
        |- it_val.txt # val_set label
        |- data
            |- word_001.jpg
            |- word_002.jpg
            |- word_003.jpg
            | ...
    ```

    You can use the default parameters to generate a configuration file:

    ```bash
    # The code needs to be run in the specified directory
    cd PaddleOCR/configs/rec/multi_language/
    # Set the configuration file of the language to be generated through the -l or --language parameter.
    # This command will write the default parameters into the configuration file
    python3 generate_multi_language_configs.py -l it
    ```

- If your data is placed in another location, or you want to use your own dictionary, you can generate the configuration file by specifying the relevant parameters:

    ```bash
    # -l or --language field is required
    # --train to modify the training set
    # --val to modify the validation set
    # --data_dir to modify the data set directory
tink2123's avatar
tink2123 committed
324
    # --dict to modify the dict path
tink2123's avatar
tink2123 committed
325
326
327
328
329
330
331
332
333
334
335
    # -o to modify the corresponding default parameters
    cd PaddleOCR/configs/rec/multi_language/
    python3 generate_multi_language_configs.py -l it \  # language
    --train {path/of/train_label.txt} \ # path of train_label
    --val {path/of/val_label.txt} \     # path of val_label
    --data_dir {train_data/path} \      # root directory of training data
    --dict {path/of/dict} \             # path of dict
    -o Global.use_gpu=False             # whether to use gpu
    ...

    ```
tink2123's avatar
tink2123 committed
336
Italian is made up of Latin letters, so after executing the command, you will get the rec_latin_lite_train.yml.
tink2123's avatar
tink2123 committed
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367

2. Manually modify the configuration file

   You can also manually modify the following fields in the template:

   ```
    Global:
      use_gpu: True
      epoch_num: 500
      ...
      character_type: it  # language
      character_dict_path:  {path/of/dict} # path of dict

   Train:
      dataset:
        name: SimpleDataSet
        data_dir: train_data/ # root directory of training data
        label_file_list: ["./train_data/train_list.txt"] # train label path
      ...

   Eval:
      dataset:
        name: SimpleDataSet
        data_dir: train_data/ # root directory of val data
        label_file_list: ["./train_data/val_list.txt"] # val label path
      ...

   ```

Currently, the multi-language algorithms supported by PaddleOCR are:

tink2123's avatar
tink2123 committed
368
| Configuration file |  Algorithm name |   backbone |   trans   |   seq      |     pred     |  language | character_type |
tink2123's avatar
tink2123 committed
369
370
| :--------: |  :-------:   | :-------:  |   :-------:   |   :-----:   |  :-----:   | :-----:  | :-----:  |
| rec_chinese_cht_lite_train.yml |  CRNN |   Mobilenet_v3 small 0.5 |  None   |  BiLSTM |  ctc  | chinese traditional  | chinese_cht|
tink2123's avatar
tink2123 committed
371
| rec_en_lite_train.yml |  CRNN |   Mobilenet_v3 small 0.5 |  None   |  BiLSTM |  ctc  | English(Case sensitive)   | EN |
tink2123's avatar
tink2123 committed
372
373
374
375
| rec_french_lite_train.yml |  CRNN |   Mobilenet_v3 small 0.5 |  None   |  BiLSTM |  ctc  | French |  french |
| rec_ger_lite_train.yml |  CRNN |   Mobilenet_v3 small 0.5 |  None   |  BiLSTM |  ctc  | German   | german |
| rec_japan_lite_train.yml |  CRNN |   Mobilenet_v3 small 0.5 |  None   |  BiLSTM |  ctc  | Japanese | japan |
| rec_korean_lite_train.yml |  CRNN |   Mobilenet_v3 small 0.5 |  None   |  BiLSTM |  ctc  | Korean  | korean |
tink2123's avatar
tink2123 committed
376
377
378
379
| rec_latin_lite_train.yml |  CRNN |   Mobilenet_v3 small 0.5 |  None   |  BiLSTM |  ctc  | Latin  | latin |
| rec_arabic_lite_train.yml |  CRNN |   Mobilenet_v3 small 0.5 |  None   |  BiLSTM |  ctc  | arabic |  ar |
| rec_cyrillic_lite_train.yml |  CRNN |   Mobilenet_v3 small 0.5 |  None   |  BiLSTM |  ctc  | cyrillic   | cyrillic |
| rec_devanagari_lite_train.yml |  CRNN |   Mobilenet_v3 small 0.5 |  None   |  BiLSTM |  ctc  | devanagari  | devanagari |
tink2123's avatar
tink2123 committed
380

tink2123's avatar
tink2123 committed
381
For more supported languages, please refer to : [Multi-language model](https://github.com/PaddlePaddle/PaddleOCR/blob/release/2.1/doc/doc_en/multi_languages_en.md#4-support-languages-and-abbreviations)
WenmuZhou's avatar
WenmuZhou committed
382

littletomatodonkey's avatar
littletomatodonkey committed
383
384
385
The multi-language model training method is the same as the Chinese model. The training data set is 100w synthetic data. A small amount of fonts and test data can be downloaded using the following two methods.
* [Baidu Netdisk](https://pan.baidu.com/s/1bS_u207Rm7YbY33wOECKDA),Extraction code:frgi.
* [Google drive](https://drive.google.com/file/d/18cSWX7wXSy4G0tbKJ0d9PuIaiwRLHpjA/view)
WenmuZhou's avatar
WenmuZhou committed
386
387
388
389
390
391
392
393

If you want to finetune on the basis of the existing model effect, please refer to the following instructions to modify the configuration file:

Take `rec_french_lite_train` as an example:

```
Global:
  ...
xmy0916's avatar
xmy0916 committed
394
  # Add a custom dictionary, such as modify the dictionary, please point the path to the new dictionary
WenmuZhou's avatar
WenmuZhou committed
395
396
  character_dict_path: ./ppocr/utils/dict/french_dict.txt
  ...
xmy0916's avatar
xmy0916 committed
397
  # Whether to recognize spaces
xmy0916's avatar
xmy0916 committed
398
  use_space_char: True
xmy0916's avatar
xmy0916 committed
399

WenmuZhou's avatar
WenmuZhou committed
400
...
xmy0916's avatar
xmy0916 committed
401
402
403

Train:
  dataset:
MissPenguin's avatar
MissPenguin committed
404
    # Type of dataset,we support LMDBDataSet and SimpleDataSet
xmy0916's avatar
xmy0916 committed
405
406
407
408
409
410
411
412
413
    name: SimpleDataSet
    # Path of dataset
    data_dir: ./train_data/
    # Path of train list
    label_file_list: ["./train_data/french_train.txt"]
    ...

Eval:
  dataset:
MissPenguin's avatar
MissPenguin committed
414
    # Type of dataset,we support LMDBDataSet and SimpleDataSet
xmy0916's avatar
xmy0916 committed
415
416
417
418
419
420
    name: SimpleDataSet
    # Path of dataset
    data_dir: ./train_data
    # Path of eval list
    label_file_list: ["./train_data/french_val.txt"]
    ...
WenmuZhou's avatar
WenmuZhou committed
421
```
Khanh Tran's avatar
Khanh Tran committed
422

WenmuZhou's avatar
WenmuZhou committed
423
<a name="EVALUATION"></a>
WenmuZhou's avatar
WenmuZhou committed
424
### 3 EVALUATION
Khanh Tran's avatar
Khanh Tran committed
425

WenmuZhou's avatar
WenmuZhou committed
426
The evaluation dataset can be set by modifying the `Eval.dataset.label_file_list` field in the `configs/rec/rec_icdar15_train.yml` file.
Khanh Tran's avatar
Khanh Tran committed
427
428
429

```
# GPU evaluation, Global.checkpoints is the weight to be tested
WenmuZhou's avatar
WenmuZhou committed
430
python3 -m paddle.distributed.launch --gpus '0' tools/eval.py -c configs/rec/rec_icdar15_train.yml -o Global.checkpoints={path/to/weights}/best_accuracy
Khanh Tran's avatar
Khanh Tran committed
431
432
```

WenmuZhou's avatar
WenmuZhou committed
433
<a name="PREDICTION"></a>
WenmuZhou's avatar
WenmuZhou committed
434
### 4 PREDICTION
Khanh Tran's avatar
Khanh Tran committed
435

WenmuZhou's avatar
WenmuZhou committed
436
<a name="Training_engine_prediction"></a>
WenmuZhou's avatar
WenmuZhou committed
437
#### 4.1 Training engine prediction
Khanh Tran's avatar
Khanh Tran committed
438
439
440
441
442
443
444

Using the model trained by paddleocr, you can quickly get prediction through the following script.

The default prediction picture is stored in `infer_img`, and the weight is specified via `-o Global.checkpoints`:

```
# Predict English results
WenmuZhou's avatar
WenmuZhou committed
445
python3 tools/infer_rec.py -c configs/rec/ch_ppocr_v2.0/rec_chinese_lite_train_v2.0.yml -o Global.pretrained_model={path/to/weights}/best_accuracy Global.load_static_weights=false Global.infer_img=doc/imgs_words/en/word_1.jpg
Khanh Tran's avatar
Khanh Tran committed
446
447
448
449
```

Input image:

450
![](../imgs_words/en/word_1.png)
Khanh Tran's avatar
Khanh Tran committed
451
452
453
454
455

Get the prediction result of the input image:

```
infer_img: doc/imgs_words/en/word_1.png
tink2123's avatar
tink2123 committed
456
        result: ('joint', 0.9998967)
Khanh Tran's avatar
Khanh Tran committed
457
458
```

xmy0916's avatar
xmy0916 committed
459
The configuration file used for prediction must be consistent with the training. For example, you completed the training of the Chinese model with `python3 tools/train.py -c configs/rec/ch_ppocr_v2.0/rec_chinese_lite_train_v2.0.yml`, you can use the following command to predict the Chinese model:
Khanh Tran's avatar
Khanh Tran committed
460
461
462

```
# Predict Chinese results
WenmuZhou's avatar
WenmuZhou committed
463
python3 tools/infer_rec.py -c configs/rec/ch_ppocr_v2.0/rec_chinese_lite_train_v2.0.yml -o Global.pretrained_model={path/to/weights}/best_accuracy Global.load_static_weights=false Global.infer_img=doc/imgs_words/ch/word_1.jpg
Khanh Tran's avatar
Khanh Tran committed
464
465
466
467
```

Input image:

468
![](../imgs_words/ch/word_1.jpg)
Khanh Tran's avatar
Khanh Tran committed
469
470
471
472
473

Get the prediction result of the input image:

```
infer_img: doc/imgs_words/ch/word_1.jpg
tink2123's avatar
tink2123 committed
474
        result: ('韩国小馆', 0.997218)
Khanh Tran's avatar
Khanh Tran committed
475
```