Model Export

August 4, 2022 · View on GitHub

English | 简体中文

Model Export

The trained model needs to be exported as a prediction model before deployment.

This tutorial will show how to export a trained model。

Acquire the Pre-training Model

In this example,BiseNetV2 model will be used. Run the following command or click link to download the pretrained model.

mkdir bisenet && cd bisenet
wget https://paddleseg.bj.bcebos.com/dygraph/cityscapes/bisenet_cityscapes_1024x1024_160k/model.pdparams
cd ..

Export the prediction Model

Make sure you have installed PaddleSeg and are in the PaddleSeg directory.

Run the following command, and the prediction model will be saved in output directory.

export CUDA_VISIBLE_DEVICES=0 # Set a usable GPU.
# If on windows, Run the following command:
# set CUDA_VISIBLE_DEVICES=0
python export.py \
       --config configs/bisenet/bisenet_cityscapes_1024x1024_160k.yml \
       --model_path bisenet/model.pdparams\
       --save_dir output
       --input_shape 1 3 512 1024

Description of Exported Script Parameters

parammeterpurposeis neededdefault
configConfig fileyes-
save_dirSave root path for model and VisualDL log filesnooutput
model_pathPath of pre-training model parametersnoThe value in config file
with_softmaxAdd softmax operator at the end of the network. Since PaddleSeg networking returns Logits by default, you can set it to True if you want the deployment model to get the probability valuenoFalse
without_argmaxWhether or not to add argmax operator at the end of the network. Since PaddleSeg networking returns Logits by default, we add argmax operator at the end of the network by default in order to directly obtain the prediction results for the deployment modelnoFalse
input_shapeSet the input shape of exported model, such as --input_shape 1 3 1024 1024。if input_shape is not provided,the Default input shape of exported model is [-1, 3, -1, -1]no (If the image shape in prediction is consistent, you should set the input_shape)None

If you encounter shape-relevant issue, please try to set the input_shape.

Prediction Model Files

output
  ├── deploy.yaml            # Config file of deployment
  ├── model.pdiparams        # Paramters of static model
  ├── model.pdiparams.info   # Additional information witch is not concerned generally
  └── model.pdmodel          # Static model file

After exporting prediction model, it can be deployed by the following methods.

Deployment scenariosInference libraryTutorial
Server (Nvidia GPU and X86 CPU) Python deploymentPaddle Inferencedoc
Server (Nvidia GPU and X86 CPU) C++ deploymentPaddle Inferencedoc
Mobile deploymentPaddle Litedoc
Service-oriented deploymentPaddle Servingdoc
Web deploymentPaddle JSdoc