Skip to content

Obtaining ONNX Models

PaddleOCR provides a rich collection of pre-trained models, all stored in PaddlePaddle's static graph format. To use these models in ONNX format during deployment, you can convert them using the Paddle2ONNX plugin provided by PaddleX. For more information about PaddleX and its relationship with PaddleOCR, refer to Differences and Connections Between PaddleOCR and PaddleX.

First, install the Paddle2ONNX plugin for PaddleX using the following command via the PaddleX CLI:

paddlex --install paddle2onnx

Then, execute the following command to complete the model conversion:

paddlex \
    --paddle2onnx \  # Use the paddle2onnx feature
    --paddle_model_dir /your/paddle_model/dir \  # Specify the directory containing the Paddle model
    --onnx_model_dir /your/onnx_model/output/dir \  # Specify the output directory for the converted ONNX model
    --opset_version 7  # Specify the ONNX opset version to use

The parameters are described as follows:

Parameter Type Description
paddle_model_dir str The directory containing the Paddle model.
onnx_model_dir str The output directory for the ONNX model. It can be the same as the Paddle model directory. Defaults to onnx.
opset_version int The ONNX opset version to use. If conversion fails with a lower opset version, a higher version will be automatically selected for conversion. Defaults to 7.