mirror of
https://github.com/opencv/opencv.git
synced 2024-12-03 00:10:21 +08:00
8fa8d471af
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 |
||
---|---|---|
.. | ||
data | ||
paddle_humanseg.py | ||
paddle_resnet50.py | ||
README.md |
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:
- Export PaddlePaddle ResNet50 model to onnx format.
- Use
cv2.dnn.readNetFromONNX
to load the model file. - 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:
- Use
cv2.dnn.readNetFromONNX
to load the model file. - Preprocess image file and do inference.
- Postprocess image file and visualize.
The resulting file can be found at data/result_test_human.jpg
.