Skip to content

Text Recognition Module Tutorial

1. Overview

The text recognition module is the core part of the OCR (Optical Character Recognition) system, responsible for extracting text information from text regions in images. The performance of this module directly affects the accuracy and efficiency of the entire OCR system. The text recognition module usually receives the bounding boxes of text regions output by the text detection module as input, and then converts the text in the images into editable and searchable electronic text through complex image processing and deep learning algorithms. The accuracy of text recognition results is crucial for subsequent applications such as information extraction and data mining.

2. List of Supported Models

ModelModel Download Links 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/Pretrained Model 86.38 8.46 / 2.36 31.21 / 31.21 81 PP-OCRv5_rec is a new generation text recognition model. It is designed to efficiently and accurately support the recognition of Simplified Chinese, Traditional Chinese, English, Japanese, as well as complex text scenarios such as handwriting, vertical text, pinyin, and rare characters with a single model. While maintaining recognition performance, it also balances inference speed and model robustness, providing efficient and accurate technical support for document understanding in various scenarios.
PP-OCRv5_mobile_rec Inference Model/Pretrained Model 81.29 5.43 / 1.46 21.20 / 5.32 16
PP-OCRv4_server_rec_doc Inference Model/Pretrained 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, building upon PP-OCRv4_server_rec. It enhances the recognition capabilities for some Traditional Chinese characters, Japanese characters, and special symbols, supporting over 15,000 characters. In addition to improving document-related text recognition, it also enhances general text recognition capabilities.
PP-OCRv4_mobile_rec Inference Model/Pretrained Model 78.74 5.26 / 1.12 17.48 / 3.61 10.5 A lightweight recognition model of PP-OCRv4 with high inference efficiency, suitable for deployment on various hardware devices, including edge devices.
PP-OCRv4_server_rec Inference Model/Pretrained Model 85.19 8.75 / 2.49 36.93 / 36.93 173 The server-side model of PP-OCRv4, offering high inference accuracy and deployable on various servers.
en_PP-OCRv4_mobile_rec Inference Model/Pretrained Model 70.39 4.81 / 1.23 17.20 / 4.18 7.5 An ultra-lightweight English recognition model trained based on the PP-OCRv4 recognition model, supporting English and numeric character recognition.

❗ The above lists the 4 core models mainly supported by the text recognition module. The module supports a total of 20 full models, including multiple multilingual text recognition models. The complete model list is as follows:

👉Model List Details * PP-OCRv5 Multi-Scenario Models
ModelModel Download Links 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) Introduction
PP-OCRv5_server_rec Inference Model/Pretrained Model 86.38 64.70 93.29 60.35 8.46 / 2.36 31.21 / 31.21 81 PP-OCRv5_rec is a new generation text recognition model. It is designed to efficiently and accurately support the recognition of Simplified Chinese, Traditional Chinese, English, Japanese, as well as complex text scenarios such as handwriting, vertical text, pinyin, and rare characters with a single model. While maintaining recognition performance, it also balances inference speed and model robustness, providing efficient and accurate technical support for document understanding in various scenarios.
PP-OCRv5_mobile_rec Inference Model/Pretrained Model 81.29 66.00 83.55 54.65 5.43 / 1.46 21.20 / 5.32 16
* Chinese Recognition Models
ModelModel Download Links 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/Pretrained 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, building upon PP-OCRv4_server_rec. It enhances the recognition capabilities for some Traditional Chinese characters, Japanese characters, and special symbols, supporting over 15,000 characters. In addition to improving document-related text recognition, it also enhances general text recognition capabilities.
PP-OCRv4_mobile_rec Inference Model/Pretrained Model 78.74 5.26 / 1.12 17.48 / 3.61 10.5 A lightweight recognition model of PP-OCRv4 with high inference efficiency, suitable for deployment on various hardware devices, including edge devices.
PP-OCRv4_server_rec Inference Model/Pretrained Model 85.19 8.75 / 2.49 36.93 / 36.93 173 The server-side model of PP-OCRv4, offering high inference accuracy and deployable on various servers.
PP-OCRv3_mobile_rec Inference Model/Pretrained Model 72.96 3.89 / 1.16 8.72 / 3.56 10.3 A lightweight recognition model of PP-OCRv3 with high inference efficiency, suitable for deployment on various hardware devices, including edge devices.
ModelModel Download Links 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/Pretrained Model 68.81 10.38 / 8.31 66.52 / 30.83 80.5 SVTRv2 is a server-side text recognition model developed by the OpenOCR team of the Vision and Learning Lab (FVL) at Fudan University. It won the first prize in the PaddleOCR Algorithm Model Challenge - Task 1: OCR End-to-End Recognition Task, with a 6% improvement in end-to-end recognition accuracy on Leaderboard A compared to PP-OCRv4.
ModelModel Download Links 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/Pretrained Model 65.07 6.29 / 1.57 20.64 / 5.40 22.1 RepSVTR is a mobile-side text recognition model based on SVTRv2. It won the first prize in the PaddleOCR Algorithm Model Challenge - Task 1: OCR End-to-End Recognition Task, with a 2.5% improvement in end-to-end recognition accuracy on Leaderboard B compared to PP-OCRv4, while maintaining similar inference speed.
* English Recognition Models
ModelModel Download Links 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-OCRv4_mobile_rec Inference Model/Pretrained Model 70.39 4.81 / 1.23 17.20 / 4.18 7.5 An ultra-lightweight English recognition model trained based on the PP-OCRv4 recognition model, supporting English and numeric character recognition.
en_PP-OCRv3_mobile_rec Inference Model/Pretrained Model 70.69 3.56 / 0.78 8.44 / 5.78 17.3 An ultra-lightweight English recognition model trained based on the PP-OCRv3 recognition model, supporting English and numeric character recognition.
* Multilingual Recognition Models
ModelModel Download Links 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.
korean_PP-OCRv3_mobile_rec Inference Model/Pretrained Model 60.21 3.73 / 0.98 8.76 / 2.91 9.6 An ultra-lightweight Korean recognition model trained based on the PP-OCRv3 recognition model, supporting Korean and numeric character recognition.
japan_PP-OCRv3_mobile_rec Inference Model/Pretrained Model 45.69 3.86 / 1.01 8.62 / 2.92 9.8 An ultra-lightweight Japanese recognition model trained based on the PP-OCRv3 recognition model, supporting Japanese and numeric character recognition.
chinese_cht_PP-OCRv3_mobile_rec Inference Model/Pretrained Model 82.06 3.90 / 1.16 9.24 / 3.18 10.8 An ultra-lightweight Traditional Chinese recognition model trained based on the PP-OCRv3 recognition model, supporting Traditional Chinese and numeric character recognition.
te_PP-OCRv3_mobile_rec Inference Model/Pretrained Model 95.88 3.59 / 0.81 8.28 / 6.21 8.7 An ultra-lightweight Telugu recognition model trained based on the PP-OCRv3 recognition model, supporting Telugu and numeric character recognition.
ka_PP-OCRv3_mobile_rec Inference Model/Pretrained Model 96.96 3.49 / 0.89 8.63 / 2.77 17.4 An ultra-lightweight Kannada recognition model trained based on the PP-OCRv3 recognition model, supporting Kannada and numeric character recognition.
ta_PP-OCRv3_mobile_rec Inference Model/Pretrained Model 76.83 3.49 / 0.86 8.35 / 3.41 8.7 An ultra-lightweight Tamil recognition model trained based on the PP-OCRv3 recognition model, supporting Tamil and numeric character recognition.
latin_PP-OCRv3_mobile_rec Inference Model/Pretrained Model 76.93 3.53 / 0.78 8.50 / 6.83 8.7 An ultra-lightweight Latin recognition model trained based on the PP-OCRv3 recognition model, supporting Latin and numeric character recognition.
arabic_PP-OCRv3_mobile_rec Inference Model/Pretrained Model 73.55 3.60 / 0.83 8.44 / 4.69 17.3 An ultra-lightweight Arabic alphabet recognition model trained based on the PP-OCRv3 recognition model, supporting Arabic alphabet and numeric character recognition.
cyrillic_PP-OCRv3_mobile_rec Inference Model/Pretrained Model 94.28 3.56 / 0.79 8.22 / 2.76 8.7 An ultra-lightweight Cyrillic alphabet recognition model trained based on the PP-OCRv3 recognition model, supporting Cyrillic alphabet and numeric character recognition.
devanagari_PP-OCRv3_mobile_rec Inference Model/Pretrained Model 96.44 3.60 / 0.78 6.95 / 2.87 8.7 An ultra-lightweight Devanagari alphabet recognition model trained based on the PP-OCRv3 recognition model, supporting Devanagari alphabet and numeric character recognition.
Test Environment Description:
  • Performance Test Environment
    • Test Dataset:
    • Hardware Configuration:
      • GPU: NVIDIA Tesla T4
      • CPU: Intel Xeon Gold 6271C @ 2.60GHz
    • Software Environment:
      • Ubuntu 20.04 / CUDA 11.8 / cuDNN 8.9 / TensorRT 8.6.1.6
      • paddlepaddle 3.0.0 / paddleocr 3.0.3
  • Explanation of Inference Modes
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 precision type and acceleration strategy FP32 Precision / 8 Threads Selection of the optimal backend (Paddle/OpenVINO/TRT, etc.)

3. Quick Start

❗ Before starting, please install the PaddleOCR wheel package. For details, please refer to the Installation Guide.

You can quickly experience it with one command:

paddleocr text_recognition -i https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/general_ocr_rec_001.png

Note: The official PaddleOCR models are downloaded from HuggingFace by default. If you cannot access HuggingFace, you can change the model source to BOS by setting the environment variable PADDLE_PDX_MODEL_SOURCE="BOS". More mainstream model sources will be supported in the future.

You can also integrate the model inference of the text recognition module into your project. Before running the following code, please download the sample image to your local machine.

from paddleocr import TextRecognition
model = TextRecognition(model_name="PP-OCRv5_server_rec")
output = model.predict(input="general_ocr_rec_001.png", batch_size=1)
for res in output:
    res.print()
    res.save_to_img(save_path="./output/")
    res.save_to_json(save_path="./output/res.json")

After running, the result is as follows:

{'res': {'input_path': 'general_ocr_rec_001.png', 'page_index': None, 'rec_text': '绿洲仕格维花园公寓', 'rec_score': 0.9823867082595825}}

The meanings of the parameters in the result are as follows: - input_path: The path of the input text line image to be predicted - page_index: If the input is a PDF file, it indicates which page of the PDF the current text line is from; otherwise, it is None - rec_text: The predicted text of the text line image - rec_score: The confidence score of the predicted text for the text line image

The visualized image is as follows:

Descriptions of related methods and parameters are as follows:

  • Instantiate the text recognition model using TextRecognition (using PP-OCRv5_server_rec as an example), as follows:
Parameter Description Type Default
model_name If set to None, PP-OCRv5_server_rec is used. str|None None
model_dir Model storage path. str|None None
device Device for inference.
Examples: "cpu", "gpu", "npu", "gpu:0", "gpu:0,1".
If multiple devices are specified, inference will be performed in parallel.
By default, GPU 0 is used; if unavailable, CPU is used.
str|None None
enable_hpi Whether to enable high performance inference. bool False
use_tensorrt Whether to enable the TensorRT subgraph engine of Paddle Inference.
For Paddle with CUDA 11.8, the compatible TensorRT version is 8.x (x>=6), recommended 8.6.1.6.
For Paddle with CUDA 12.6, the compatible TensorRT version is 10.x (x>=5), recommended 10.5.0.18.
bool False
precision Precision for TensorRT when using the Paddle Inference TensorRT subgraph engine.
Options: fp32, fp16.
str "fp32"
enable_mkldnn Whether to enable MKL-DNN acceleration for inference. If MKL-DNN is unavailable or the model does not support it, acceleration will not be used even if this flag is set. bool True
mkldnn_cache_capacity MKL-DNN cache capacity. int 10
cpu_threads Number of threads to use for inference on CPUs. int 10
input_shape Input image size for the model in the format (C, H, W). tuple|None None
  • Call the predict() method of the text recognition model for inference. This method returns a list of results. In addition, this module also provides the predict_iter() method. The two methods are completely consistent in terms of parameter acceptance and result return. The difference is that predict_iter() returns a generator, which can process and obtain prediction results step by step. It is suitable for scenarios where large datasets need to be processed or memory savings are desired. You can choose either of these two methods according to your actual needs. The parameters of the predict() method include input and batch_size, with specific descriptions as follows:
Parameter Description Type Default
input Data to be predicted, supporting multiple input types, required.
  • Python Var: Image data represented by numpy.ndarray
  • str: Local path of image file or PDF file: /root/data/img.jpg; URL link: Network URL of image file or PDF file: Example; Local directory: The directory should contain the images to be predicted, such as /root/data/ (currently, prediction of PDF files in the directory is not supported, PDF files need to be specified to a specific file path)
  • list: The elements of the list should be data of the above types, such as [numpy.ndarray, numpy.ndarray], ["/root/data/img1.jpg", "/root/data/img2.jpg"], ["/root/data1", "/root/data2"]
Python Var|str|list
batch_size Batch size, can be set to any positive integer. int 1
  • Process the prediction results. The prediction result for each sample is a corresponding Result object, which supports operations such as printing, saving as an image, and saving as a json file:
Method Description Parameter Type Description Default
print() Print the result to the terminal format_json bool Whether to format the output content using JSON indentation True
indent int Specifies the indentation level to beautify the output JSON data, making it more readable. Only effective when format_json is True. 4
ensure_ascii bool Controls whether to escape non-ASCII characters as Unicode. When set to True, all non-ASCII characters will be escaped; False retains the original characters. Only effective when format_json is True. False
save_to_json() Save the result as a file in json format save_path str The file path to save the result. When it is a directory, the saved file name is consistent with the naming of the input file type. None
indent int Specifies the indentation level to beautify the output JSON data, making it more readable. Only effective when format_json is True. 4
ensure_ascii bool Controls whether to escape non-ASCII characters as Unicode. When set to True, all non-ASCII characters will be escaped; False retains the original characters. Only effective when format_json is True. False
save_to_img() Save the result as a file in image format save_path str The file path to save the result. When it is a directory, the saved file name is consistent with the naming of the input file type. None
  • In addition, it also supports obtaining the visualized image with results and the prediction results through attributes, as follows:
Attribute Description
json Obtain the prediction result in json format
img Obtain the visualized image in dict format

4. Secondary Development

If the above models do not perform well in your scenario, you can try the following steps for secondary development. Here, we take training PP-OCRv5_server_rec as an example. For other models, just replace the corresponding configuration file. First, you need to prepare a dataset for text recognition. You can refer to the format of the Text Recognition Demo Data for preparation. After preparation, you can train and export the model as follows. After export, the model can be quickly integrated into the above API. This example uses the Text Recognition Demo Data. Before training the model, please make sure you have installed the dependencies required by PaddleOCR as described in the Installation Guide.

4.1 Dataset and Pre-trained Model Preparation

4.1.1 Prepare the Dataset

# Download the example dataset
wget https://paddle-model-ecology.bj.bcebos.com/paddlex/data/ocr_rec_dataset_examples.tar
tar -xf ocr_rec_dataset_examples.tar

4.1.2 Download the Pre-trained Model

# Download the PP-OCRv5_server_rec pre-trained model
wget https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/PP-OCRv5_server_rec_pretrained.pdparams

4.2 Model Training

PaddleOCR modularizes its code. To train the PP-OCRv5_server_rec recognition model, you need to use its configuration file.

The training commands are as follows:

# Single-GPU training (default training method)
python3 tools/train.py -c configs/rec/PP-OCRv5/PP-OCRv5_server_rec.yml \
   -o Global.pretrained_model=./PP-OCRv5_server_rec_pretrained.pdparams

# Multi-GPU training, specify GPU IDs via the --gpus parameter
python3 -m paddle.distributed.launch --gpus '0,1,2,3'  tools/train.py -c configs/rec/PP-OCRv5/PP-OCRv5_server_rec.yml \
        -o Global.pretrained_model=./PP-OCRv5_server_rec_pretrained.pdparams

4.3 Model Evaluation

You can evaluate the trained weights, such as output/xxx/xxx.pdparams, using the following command:

# Note: Set the path of pretrained_model to a local path. If you use a model you trained and saved yourself, please modify the path and file name to {path/to/weights}/{model_name}.
# Demo test set evaluation
python3 tools/eval.py -c configs/rec/PP-OCRv5/PP-OCRv5_server_rec.yml -o \
Global.pretrained_model=output/xxx/xxx.pdparams

4.4 Model Export

python3 tools/export_model.py -c configs/rec/PP-OCRv5/PP-OCRv5_server_rec.yml -o \
Global.pretrained_model=output/xxx/xxx.pdparams \
Global.save_inference_dir="./PP-OCRv5_server_rec_infer/"

After exporting the model, the static graph model will be stored in ./PP-OCRv5_server_rec_infer/ in the current directory. In this directory, you will see the following files:

./PP-OCRv5_server_rec_infer/
├── inference.json
├── inference.pdiparams
├── inference.yml
At this point, the secondary development is complete. This static graph model can be directly integrated into the PaddleOCR API.

5. FAQ

Comments