--- comments: true --- # Text Recognition Module Tutorial ## I. Overview The text recognition module is the core component of an OCR (Optical Character Recognition) system, responsible for extracting text information from text regions within images. The performance of this module directly impacts the accuracy and efficiency of the entire OCR system. The text recognition module typically receives bounding boxes of text regions output by the text detection module as input. Through complex image processing and deep learning algorithms, it converts the text in images into editable and searchable electronic text. The accuracy of text recognition results is crucial for subsequent applications such as information extraction and data mining. ## II. Supported Model List > The inference time only includes the model inference time and does not include the time for pre- or post-processing.
| Model | Model Download Link | Recognition Avg Accuracy(%) | GPU Inference Time (ms) [Normal Mode / High-Performance Mode] |
CPU Inference Time (ms) [Normal Mode / High-Performance Mode] |
Model Storage Size (MB) | Introduction |
|---|---|---|---|---|---|---|
| PP-OCRv5_server_rec | Inference Model/Training Model | 86.38 | 8.46 / 2.36 | 31.21 / 31.21 | 81 | PP-OCRv5_rec is a next-generation text recognition model. This model is dedicated to efficiently and accurately supporting four major languages—Simplified Chinese, Traditional Chinese, English, and Japanese—with a single model. It supports complex text scenarios, including handwritten, vertical text, pinyin, and rare characters. While maintaining recognition accuracy, it also balances inference speed and model robustness, providing efficient and precise technical support for document understanding in various scenarios. |
| PP-OCRv5_mobile_rec | Inference Model/Training Model | 81.29 | 5.43 / 1.46 | 21.20 / 5.32 | 16 | |
| PP-OCRv4_server_rec_doc | Inference Model/Training Model | 86.58 | 8.69 / 2.78 | 37.93 / 37.93 | 182 | PP-OCRv4_server_rec_doc is trained on a mixed dataset of more Chinese document data and PP-OCR training data based on PP-OCRv4_server_rec. It has added the ability to recognize some traditional Chinese characters, Japanese, and special characters, and can support the recognition of more than 15,000 characters. In addition to improving the text recognition capability related to documents, it also enhances the general text recognition capability. |
| PP-OCRv4_mobile_rec | Inference Model/Training Model | 78.74 | 5.26 / 1.12 | 17.48 / 3.61 | 10.5 | The lightweight recognition model of PP-OCRv4 has high inference efficiency and can be deployed on various hardware devices, including edge devices. |
| PP-OCRv4_server_rec | Inference Model/Training Model | 85.19 | 8.75 / 2.49 | 36.93 / 36.93 | 173 | The server-side model of PP-OCRv4 offers high inference accuracy and can be deployed on various types of servers. |
| en_PP-OCRv4_mobile_rec | Inference Model/Training Model | 70.39 | 4.81 / 1.23 | 17.20 / 4.18 | 7.5 | The ultra-lightweight English recognition model, trained based on the PP-OCRv4 recognition model, supports the recognition of English letters and numbers. |
| Model | Model Download Link | Chinese Recognition Avg Accuracy (%) | English Recognition Avg Accuracy (%) | Traditional Chinese Recognition Avg Accuracy (%) | Japanese Recognition Avg Accuracy (%) | GPU Inference Time (ms) [Normal Mode / High-Performance Mode] |
CPU Inference Time (ms) [Normal Mode / High-Performance Mode] |
Model Storage Size (MB) | Description |
|---|---|---|---|---|---|---|---|---|---|
| PP-OCRv5_server_rec | Inference Model/Training Model | 86.38 | 64.70 | 93.29 | 60.35 | 8.46 / 2.36 | 31.21 / 31.21 | 81 | PP-OCRv5_rec is a next-generation text recognition model. This model efficiently and accurately supports four major languages with a single model: Simplified Chinese, Traditional Chinese, English, and Japanese. It recognizes complex text scenarios including handwritten, vertical text, pinyin, and rare characters. While maintaining recognition accuracy, it balances inference speed and model robustness, providing efficient and precise technical support for document understanding in various scenarios. |
| PP-OCRv5_mobile_rec | Inference Model/Training Model | 81.29 | 66.00 | 83.55 | 54.65 | 5.43 / 1.46 | 21.20 / 5.32 | 16 |
| Model | Model Download Link | Recognition Avg Accuracy(%) | GPU Inference Time (ms) [Normal Mode / High-Performance Mode] |
CPU Inference Time (ms) [Normal Mode / High-Performance Mode] |
Model Storage Size (MB) | Introduction |
|---|---|---|---|---|---|---|
| PP-OCRv4_server_rec_doc | Inference Model/Training Model | 86.58 | 8.69 / 2.78 | 37.93 / 37.93 | 182 | PP-OCRv4_server_rec_doc is trained on a mixed dataset of more Chinese document data and PP-OCR training data based on PP-OCRv4_server_rec. It has added the recognition capabilities for some traditional Chinese characters, Japanese, and special characters. The number of recognizable characters is over 15,000. In addition to the improvement in document-related text recognition, it also enhances the general text recognition capability. |
| PP-OCRv4_mobile_rec | Inference Model/Training Model | 78.74 | 5.26 / 1.12 | 17.48 / 3.61 | 10.5 | The lightweight recognition model of PP-OCRv4 has high inference efficiency and can be deployed on various hardware devices, including edge devices. |
| PP-OCRv4_server_rec | Inference Model/Training Model | 85.19 | 8.75 / 2.49 | 36.93 / 36.93 | 173 | The server-side model of PP-OCRv4 offers high inference accuracy and can be deployed on various types of servers. |
| PP-OCRv3_mobile_rec | Inference Model/Training Model | 72.96 | 3.89 / 1.16 | 8.72 / 3.56 | 10.3 | PP-OCRv3’s lightweight recognition model is designed for high inference efficiency and can be deployed on a variety of hardware devices, including edge devices. |
| Model | Model Download Link | Recognition Avg Accuracy(%) | GPU Inference Time (ms) [Normal Mode / High-Performance Mode] |
CPU Inference Time (ms) [Normal Mode / High-Performance Mode] |
Model Storage Size (MB) | Introduction |
|---|---|---|---|---|---|---|
| ch_SVTRv2_rec | Inference Model/Training Model | 68.81 | 10.38 / 8.31 | 66.52 / 30.83 | 80.5 | SVTRv2 is a server text recognition model developed by the OpenOCR team of Fudan University's Visual and Learning Laboratory (FVL). It won the first prize in the PaddleOCR Algorithm Model Challenge - Task One: OCR End-to-End Recognition Task. The end-to-end recognition accuracy on the A list is 6% higher than that of PP-OCRv4. |
| Model | Model Download Link | Recognition Avg Accuracy(%) | GPU Inference Time (ms) [Normal Mode / High-Performance Mode] |
CPU Inference Time (ms) [Normal Mode / High-Performance Mode] |
Model Storage Size (MB) | Introduction |
|---|---|---|---|---|---|---|
| ch_RepSVTR_rec | Inference Model/Training Model | 65.07 | 6.29 / 1.57 | 20.64 / 5.40 | 48.8 | The RepSVTR text recognition model is a mobile text recognition model based on SVTRv2. It won the first prize in the PaddleOCR Algorithm Model Challenge - Task One: OCR End-to-End Recognition Task. The end-to-end recognition accuracy on the B list is 2.5% higher than that of PP-OCRv4, with the same inference speed. |
| Model | Model Download Link | Recognition Avg Accuracy(%) | GPU Inference Time (ms) [Normal Mode / High-Performance Mode] |
CPU Inference Time (ms) [Normal Mode / High-Performance Mode] |
Model Storage Size (MB) | Introduction |
|---|---|---|---|---|---|---|
| en_PP-OCRv5_mobile_rec | Inference Model/Training Model | 85.25 | - | - | 7.5 | The ultra-lightweight English recognition model trained based on the PP-OCRv5 recognition model supports the recognition of English and numbers. |
| en_PP-OCRv4_mobile_rec | Inference Model/Training Model | 70.39 | 4.81 / 1.23 | 17.20 / 4.18 | 7.5 | The ultra-lightweight English recognition model trained based on the PP-OCRv4 recognition model supports the recognition of English and numbers. |
| en_PP-OCRv3_mobile_rec | Inference Model/Training Model | 70.69 | 3.56 / 0.78 | 8.44 / 5.78 | 17.3 | The ultra-lightweight English recognition model trained based on the PP-OCRv3 recognition model supports the recognition of English and numbers. |
| Model | Model Download Link | Recognition Avg Accuracy(%) | GPU Inference Time (ms) [Normal Mode / High-Performance Mode] |
CPU Inference Time (ms) [Normal Mode / High-Performance Mode] |
Model Storage Size (MB) | Introduction |
|---|---|---|---|---|---|---|
| korean_PP-OCRv5_mobile_rec | Inference Model/Pre-trained Model | 90.45 | 5.43 / 1.46 | 21.20 / 5.32 | 14 | An ultra-lightweight Korean text recognition model trained based on the PP-OCRv5 recognition framework. Supports Korean, English and numeric text recognition. |
| latin_PP-OCRv5_mobile_rec | Inference Model/Pre-trained Model | 84.7 | 5.43 / 1.46 | 21.20 / 5.32 | 14 | A Latin-script text recognition model trained based on the PP-OCRv5 recognition framework. Supports most Latin alphabet languages and numeric text recognition. |
| eslav_PP-OCRv5_mobile_rec | Inference Model/Pre-trained Model | 85.8 | 5.43 / 1.46 | 21.20 / 5.32 | 14 | An East Slavic language recognition model trained based on the PP-OCRv5 recognition framework. Supports East Slavic languages, English and numeric text recognition. |
| th_PP-OCRv5_mobile_rec | Inference Model/Training Model | 82.68 | - | - | 7.5 | The Thai recognition model trained based on the PP-OCRv5 recognition model supports recognition of Thai, English, and numbers. |
| el_PP-OCRv5_mobile_rec | Inference Model/Training Model | 89.28 | - | - | 7.5 | The Greek recognition model trained based on the PP-OCRv5 recognition model supports recognition of Greek, English, and numbers. |
| arabic_PP-OCRv5_mobile_rec | Inference Model/Pretrained Model | 81.27 | - | - | 7.6 | Ultra-lightweight Arabic character recognition model trained based on the PP-OCRv5 recognition model, supports Arabic letters and number recognition |
| cyrillic_PP-OCRv5_mobile_rec | Inference Model/Pretrained Model | 80.27 | - | - | 7.7 | Ultra-lightweight Cyrillic character recognition model trained based on the PP-OCRv5 recognition model, supports Cyrillic letters and number recognition |
| devanagari_PP-OCRv5_mobile_rec | Inference Model/Pretrained Model | 84.96 | - | - | 7.5 | Ultra-lightweight Devanagari script recognition model trained based on the PP-OCRv5 recognition model, supports Hindi, Sanskrit and other Devanagari letters, as well as number recognition |
| te_PP-OCRv5_mobile_rec | Inference Model/Pretrained Model | 87.65 | - | - | 7.5 | Ultra-lightweight Telugu script recognition model trained based on the PP-OCRv5 recognition model, supports Telugu script and number recognition |
| ta_PP-OCRv5_mobile_rec | Inference Model/Pretrained Model | 94.2 | - | - | 7.5 | Ultra-lightweight Tamil script recognition model trained based on the PP-OCRv5 recognition model, supports Tamil script and number recognition |
| korean_PP-OCRv3_mobile_rec | Inference Model/Training Model | 60.21 | 3.73 / 0.98 | 8.76 / 2.91 | 9.6 | The ultra-lightweight Korean recognition model trained based on the PP-OCRv3 recognition model supports the recognition of Korean and numbers. |
| japan_PP-OCRv3_mobile_rec | Inference Model/Training Model | 45.69 | 3.86 / 1.01 | 8.62 / 2.92 | 9.8 | The ultra-lightweight Japanese recognition model trained based on the PP-OCRv3 recognition model supports the recognition of Japanese and numbers. |
| chinese_cht_PP-OCRv3_mobile_rec | Inference Model/Training Model | 82.06 | 3.90 / 1.16 | 9.24 / 3.18 | 10.8 | The ultra-lightweight Traditional Chinese recognition model trained based on the PP-OCRv3 recognition model supports the recognition of Traditional Chinese and numbers. |
| te_PP-OCRv3_mobile_rec | Inference Model/Training Model | 95.88 | 3.59 / 0.81 | 8.28 / 6.21 | 8.7 | The ultra-lightweight Telugu recognition model trained based on the PP-OCRv3 recognition model supports the recognition of Telugu and numbers. |
| ka_PP-OCRv3_mobile_rec | Inference Model/Training Model | 96.96 | 3.49 / 0.89 | 8.63 / 2.77 | 17.4 | The ultra-lightweight Kannada recognition model trained based on the PP-OCRv3 recognition model supports the recognition of Kannada and numbers. |
| ta_PP-OCRv3_mobile_rec | Inference Model/Training Model | 76.83 | 3.49 / 0.86 | 8.35 / 3.41 | 8.7 | The ultra-lightweight Tamil recognition model trained based on the PP-OCRv3 recognition model supports the recognition of Tamil and numbers. |
| latin_PP-OCRv3_mobile_rec | Inference Model/Training Model | 76.93 | 3.53 / 0.78 | 8.50 / 6.83 | 8.7 | The ultra-lightweight Latin recognition model trained based on the PP-OCRv3 recognition model supports the recognition of Latin script and numbers. |
| arabic_PP-OCRv3_mobile_rec | Inference Model/Training Model | 73.55 | 3.60 / 0.83 | 8.44 / 4.69 | 17.3 | The ultra-lightweight Arabic script recognition model trained based on the PP-OCRv3 recognition model supports the recognition of Arabic script and numbers. |
| cyrillic_PP-OCRv3_mobile_rec | Inference Model/Training Model | 94.28 | 3.56 / 0.79 | 8.22 / 2.76 | 8.7 | The ultra-lightweight cyrillic alphabet recognition model trained based on the PP-OCRv3 recognition model supports the recognition of cyrillic letters and numbers. |
| devanagari_PP-OCRv3_mobile_rec | Inference Model/Training Model | 96.44 | 3.60 / 0.78 | 6.95 / 2.87 | 7.9 | The ultra-lightweight Devanagari script recognition model trained based on the PP-OCRv3 recognition model supports the recognition of Devanagari script and numbers. |
| Mode | GPU Configuration | CPU Configuration | Acceleration Technology Combination |
|---|---|---|---|
| Normal Mode | FP32 Precision / No TRT Acceleration | FP32 Precision / 8 Threads | PaddleInference |
| High-Performance Mode | Optimal combination of pre-selected precision types and acceleration strategies | FP32 Precision / 8 Threads | Pre-selected optimal backend (Paddle/OpenVINO/TRT, etc.) |
The explanations for the methods, parameters, etc., are as follows:
* The `create_model` instantiates the text recognition model (here, `PP-OCRv4_mobile_rec` is taken as an example), and the specific instructions are as follows:
| Parameter | Parameter Description | Parameter Type | Options | Default Value |
|---|---|---|---|---|
model_name |
Name of the model | str |
All model names supported by PaddleX | None |
model_dir |
Path to store the model | str |
None | None |
device |
The device used for model inference | str |
It supports specifying specific GPU card numbers, such as "gpu:0", other hardware card numbers, such as "npu:0", or CPU, such as "cpu". | gpu:0 |
use_hpip |
Whether to enable the high-performance inference plugin | bool |
None | False |
hpi_config |
High-performance inference configuration | dict | None |
None | None |
| Parameter | Parameter Description | Parameter Type | Options | Default Value |
|---|---|---|---|---|
input |
Data to be predicted, supporting multiple input types | Python Var/str/list |
|
None |
batch_size |
Batch size | int |
Any integer | 1 |
| Method | Method Description | Parameter | Parameter Type | Parameter Description | Default Value |
|---|---|---|---|---|---|
print |
Print the result to the terminal | format_json |
bool |
Whether to format the output content using json indentation |
True |
indent |
int |
JSON formatting setting, only effective when format_json is True |
4 | ||
ensure_ascii |
bool |
JSON formatting setting, only effective when format_json is True |
False |
||
save_to_json |
Save the result as a JSON file | save_path |
str |
The path where the file is saved. If it is a directory, the saved file name is consistent with the input file name | None |
indent |
int |
JSON formatting setting | 4 | ||
ensure_ascii |
bool |
JSON formatting setting | False |
||
save_to_img |
Save the result as an image file | save_path |
str |
The path where the file is saved. If it is a directory, the saved file name is consistent with the input file name | None |
| Attribute | Attribute Description |
|---|---|
json |
Get the prediction result in json format |
img |
Get the visualization image in dict format |
The specific content of the validation result file is:
{
"done_flag": true,
"check_pass": true,
"attributes": {
"train_samples": 4468,
"train_sample_paths": [
"check_dataset\/demo_img\/train_word_1.png",
"check_dataset\/demo_img\/train_word_2.png",
"check_dataset\/demo_img\/train_word_3.png",
"check_dataset\/demo_img\/train_word_4.png",
"check_dataset\/demo_img\/train_word_5.png",
"check_dataset\/demo_img\/train_word_6.png",
"check_dataset\/demo_img\/train_word_7.png",
"check_dataset\/demo_img\/train_word_8.png",
"check_dataset\/demo_img\/train_word_9.png",
"check_dataset\/demo_img\/train_word_10.png"
],
"val_samples": 2077,
"val_sample_paths": [
"check_dataset\/demo_img\/val_word_1.png",
"check_dataset\/demo_img\/val_word_2.png",
"check_dataset\/demo_img\/val_word_3.png",
"check_dataset\/demo_img\/val_word_4.png",
"check_dataset\/demo_img\/val_word_5.png",
"check_dataset\/demo_img\/val_word_6.png",
"check_dataset\/demo_img\/val_word_7.png",
"check_dataset\/demo_img\/val_word_8.png",
"check_dataset\/demo_img\/val_word_9.png",
"check_dataset\/demo_img\/val_word_10.png"
]
},
"analysis": {
"histogram": "check_dataset\/histogram.png"
},
"dataset_path": "ocr_rec_dataset_examples",
"show_type": "image",
"dataset_type": "MSTextRecDataset"
}
In the above validation result, check_pass being true indicates that the dataset format meets the requirements. Explanations for other indicators are as follows:
attributes.train_samples: The number of training set samples in this dataset is 4468;attributes.val_samples: The number of validation set samples in this dataset is 2077;attributes.train_sample_paths: A list of relative paths to the visualized training set samples in this dataset;attributes.val_sample_paths: A list of relative paths to the visualized validation set samples in this dataset;
Additionally, the dataset validation also analyzes the distribution of character length ratios in the dataset and generates a distribution histogram (histogram.png):
(1) Dataset Format Conversion
Text recognition does not currently support data conversion.
(2) Dataset Splitting
The parameters for dataset splitting can be set by modifying the CheckDataset section in the configuration file. Examples of some parameters in the configuration file are as follows:
CheckDataset:split:enable: Whether to re-split the dataset. Set to True to enable dataset splitting, default is False;train_percent: If re-splitting the dataset, set the percentage of the training set. The type is any integer between 0-100, and it must sum up to 100 with val_percent;
For example, if you want to re-split the dataset with a 90% training set and a 10% validation set, modify the configuration file as follows:......
CheckDataset:
......
split:
enable: True
train_percent: 90
val_percent: 10
......
Then execute the command:
python main.py -c paddlex/configs/modules/text_recognition/PP-OCRv4_mobile_rec.yaml \
-o Global.mode=check_dataset \
-o Global.dataset_dir=./dataset/ocr_rec_dataset_examples
After data splitting, the original annotation files will be renamed to xxx.bak in the original path.
The above parameters also support setting through appending command line arguments:
python main.py -c paddlex/configs/modules/text_recognition/PP-OCRv4_mobile_rec.yaml \
-o Global.mode=check_dataset \
-o Global.dataset_dir=./dataset/ocr_rec_dataset_examples \
-o CheckDataset.split.enable=True \
-o CheckDataset.split.train_percent=90 \
-o CheckDataset.split.val_percent=10
output. If you need to specify a save path, you can set it through the -o Global.output field in the configuration file.After completing the model training, all outputs are saved in the specified output directory (default is ./output/), typically including:
train_result.json: Training result record file, recording whether the training task was completed normally, as well as the output weight metrics, related file paths, etc.;
train.log: Training log file, recording changes in model metrics and loss during training;config.yaml: Training configuration file, recording the hyperparameter configuration for this training session;.pdparams, .pdema, .pdopt.pdstate, .pdiparams, .json: Model weight-related files, including network parameters, optimizer, EMA, static graph network parameters, static graph network structure, etc.;.json file) from protobuf(the former.pdmodel file) to be compatible with PIR and more flexible and scalable.When evaluating the model, you need to specify the model weights file path. Each configuration file has a default weight save path. If you need to change it, simply append the command line parameter to set it, such as -o Evaluate.weight_path=./output/best_model/best_model.pdparams.
After completing the model evaluation, an evaluate_result.json file will be produced, which records the evaluation results, specifically, whether the evaluation task was completed successfully and the model's evaluation metrics, including acc、norm_edit_dis;