简体中文 | English
The text detection module is a crucial component in OCR (Optical Character Recognition) systems, responsible for locating and marking regions containing text within images. The performance of this module directly impacts the accuracy and efficiency of the entire OCR system. The text detection module typically outputs bounding boxes (Bounding Boxes) for text regions, which are then passed on to the text recognition module for further processing.
| Model | Detection Hmean (%) | GPU Inference Time (ms) | CPU Inference Time (ms) | Model Size (M) | Description | |-|-|-|-|-|-| | PP-OCRv4_server_det | 82.69 | 83.3501 | 2434.01 | 109 | The server-side text detection model of PP-OCRv4, featuring higher accuracy and suitable for deployment on high-performance servers | | PP-OCRv4_mobile_det | 77.79 | 10.6923 | 120.177 | 4.7 | The mobile text detection model of PP-OCRv4, optimized for efficiency and suitable for deployment on edge devices |
❗ Before quick integration, please install the PaddleX wheel package. For detailed instructions, refer to the PaddleX Local Installation Guide.
Just a few lines of code can complete the inference of the text detection module, allowing you to easily switch between models under this module. You can also integrate the model inference of the text detection module into your project. Before running the following code, please download the demo image to your local machine.
from paddlex import create_model
model = create_model("PP-OCRv4_mobile_det")
output = model.predict("general_ocr_001.png", batch_size=1)
for res in output:
res.print(json_format=False)
res.save_to_img("./output/")
res.save_to_json("./output/res.json")
For more information on using PaddleX's single-model inference APIs, refer to the PaddleX Single Model Python Script Usage Instructions.
If you seek even higher accuracy from existing models, you can leverage PaddleX's custom development capabilities to develop better text detection models. Before developing text detection models with PaddleX, ensure you have installed the PaddleOCR plugin for PaddleX. The installation process can be found in the PaddleX Local Installation Guide.
Before model training, you need to prepare a dataset for the specific task module. PaddleX provides data validation functionality for each module, and only data that passes validation can be used for model training. Additionally, PaddleX provides demo datasets for each module, which you can use to complete subsequent development. If you wish to use private datasets for model training, refer to the PaddleX Text Detection/Text Recognition Task Module Data Annotation Tutorial.
You can use the following commands to download the demo dataset to a specified folder:
wget https://paddle-model-ecology.bj.bcebos.com/paddlex/data/ocr_det_dataset_examples.tar -P ./dataset
tar -xf ./dataset/ocr_det_dataset_examples.tar -C ./dataset/
A single command can complete data validation:
python main.py -c paddlex/configs/text_detection/PP-OCRv4_mobile_det.yaml \
-o Global.mode=check_dataset \
-o Global.dataset_dir=./dataset/ocr_det_dataset_examples
After executing the above command, PaddleX will validate the dataset, summarize its basic information, and print Check dataset passed ! in the log upon successful completion.
After completing data validation, you can convert the dataset format and re-split the training/validation ratio by modifying the configuration file or appending hyperparameters.
Model training can be completed with a single command. Here's an example of training the PP-OCRv4 mobile text detection model (PP-OCRv4_mobile_det):
python main.py -c paddlex/configs/text_detection/PP-OCRv4_mobile_det.yaml \
-o Global.mode=train \
-o Global.dataset_dir=./dataset/ocr_det_dataset_examples
The steps required are:
.yaml configuration file (here it's PP-OCRv4_mobile_det.yaml)-o Global.mode=train-o Global.dataset_dir
Other related parameters can be set by modifying the Global and Train fields in the .yaml configuration file or adjusted by appending parameters in the command line. For example, to specify training on the first two GPUs: -o Global.device=gpu:0,1; to set the number of training epochs to 10: -o Train.epochs_iters=10. For more modifiable parameters and their detailed explanations, refer to the PaddleX Common Configuration Parameters Documentation.After completing model training and evaluation, you can use the trained model weights for inference predictions or Python integration.
To perform inference predictions via the command line, simply use the following command. Before running the following code, please download the demo image to your local machine.
python main.py -c paddlex/configs/text_detection/PP-OCRv4_mobile_det.yaml \
-o Global.mode=predict \
-o Predict.model_dir="./output/best_accuracy/inference" \
-o Predict.input="general_ocr_001.png"
Similar to model training and evaluation, the following steps are required:
.yaml configuration file path of the model (here it's PP-OCRv4_mobile_det.yaml)-o Global.mode=predict-o Predict.model_dir="./output/best_accuracy/inference"Specify the input data path: -o Predict.inputh="..."
Other related parameters can be set by modifying the fields under Global and Predict in the .yaml configuration file. For details, refer to PaddleX Common Model Configuration File Parameter Description.
Alternatively, you can use the PaddleX wheel package for inference, easily integrating the model into your own projects.
Models can be directly integrated into PaddleX pipelines or into your own projects.
1.Pipeline Integration
The text detection module can be integrated into PaddleX pipelines such as the General OCR Pipeline, Table Recognition Pipeline, and Document Scene Information Extraction Pipeline v3 (PP-ChatOCRv3). Simply replace the model path to update the text detection module of the relevant pipeline.
2.Module Integration
The model weights you produce can be directly integrated into the text detection module. Refer to the Python example code in Quick Integration, and simply replace the model with the path to your trained model.