mirror of https://github.com/opencv/opencv.git
Open Source Computer Vision Library
https://opencv.org/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
WJJ1995
8fa8d471af
|
3 years ago | |
---|---|---|
.. | ||
data | 3 years ago | |
README.md | 3 years ago | |
paddle_humanseg.py | 3 years ago | |
paddle_resnet50.py | 3 years ago |
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
.