opencv/samples/dnn/dnn_model_runner/dnn_conversion/paddlepaddle
WJJ1995 8fa8d471af
Merge pull request #20290 from wjj19950828:add_paddle_humanseg_demo
Add paddle humanseg demo

* fixed onnx resize op bug

* add humanseg demo for PaddlePaddle sample

* update README.md and flake8 format

* update func name

* update README.md for enviroment setup

* update README.md in the way install paddle2onnx

* update README.md

* update README.md

* add paddleseg in requirements.txt

* deal with comments

* replace picture
2021-09-27 21:59:09 +00:00
..
data Merge pull request #20290 from wjj19950828:add_paddle_humanseg_demo 2021-09-27 21:59:09 +00:00
paddle_humanseg.py Merge pull request #20290 from wjj19950828:add_paddle_humanseg_demo 2021-09-27 21:59:09 +00:00
paddle_resnet50.py Merge pull request #20290 from wjj19950828:add_paddle_humanseg_demo 2021-09-27 21:59:09 +00:00
README.md Merge pull request #20290 from wjj19950828:add_paddle_humanseg_demo 2021-09-27 21:59:09 +00:00

Run PaddlePaddle model using OpenCV

These two demonstrations show how to inference PaddlePaddle model using OpenCV.

Environment Setup

pip install paddlepaddle-gpu
pip install paddlehub
pip install paddle2onnx

1. Run PaddlePaddle ResNet50 using OpenCV

Run PaddlePaddle model demo

Run the code sample as follows:

python paddle_resnet50.py

There are three parts to the process:

  1. Export PaddlePaddle ResNet50 model to onnx format.
  2. Use cv2.dnn.readNetFromONNX to load the model file.
  3. Preprocess image file and do the inference.

2. Run PaddleSeg Portrait Segmentation using OpenCV

Convert to ONNX Model

1. Get Paddle Inference model

For more details, please refer to PaddleSeg.

wget https://x2paddle.bj.bcebos.com/inference/models/humanseg_hrnet18_small_v1.zip
unzip humanseg_hrnet18_small_v1.zip

Notes:

  • The exported model must have a fixed input shape, as dynamic is not supported at this moment.

2. Convert to ONNX model using paddle2onnx

To convert the model, use the following command:

paddle2onnx --model_dir humanseg_hrnet18_small_v1 \
            --model_filename model.pdmodel \
            --params_filename model.pdiparams \
            --opset_version 11 \
            --save_file humanseg_hrnet18_tiny.onnx

The converted model can be found in the current directory by the name humanseg_hrnet18_tiny.onnx .

Run PaddleSeg Portrait Segmentation demo

Run the code sample as follows:

python paddle_humanseg.py

There are three parts to the process:

  1. Use cv2.dnn.readNetFromONNX to load the model file.
  2. Preprocess image file and do inference.
  3. Postprocess image file and visualize.

The resulting file can be found at data/result_test_human.jpg .

Portrait segmentation visualization