Windows uses the model trained by Paddle to deploy under the OpenVino reasoning engine

1. Openvino download

According to the official description of Paddle, there is a problem with converting the current detection model to the openvino format. For the time being, only the segmentation and classification models are supported, and the best openvino version is 2021.3 (it has been tested and has good compatibility).
Openvino 2021.3 download address The installation process can be installed
step by step by referring to the official OpenVino installation steps : after the installation is complete, the directory is as follows: run the directory after installing the inference component:

insert image description here
install.exe
insert image description here

2. Prepare the model

2.1 Export Paddle Inference model

Since Openvino currently only supports older models, here we take the mobilenetv3_large model trained by PaddleX as an example and export it as an inference format model paddle inference:
insert image description here
After installing PaddleX, execute the following command to export the model:

paddlex --export_inference --model_dir=./output/deeplabv3p_r50vd/best_model/ --save_dir=./inference_model

2.2 Convert to ONNX model

Convert paddle inference model to onnx model:

# model_dir需要ResNet50解压后的路径
paddle2onnx --model_dir  E:/Fileresipority/cloth_check/mobilenetv3_large/inference_model/inference_model  --model_filename model.pdmodel     --params_filename model.pdiparams      --save_file model.onnx   --enable_dev_version True

insert image description here
Converted directory:
insert image description here

3. Compile and generate Openvino reasoning files

3.1 Get the deployment code

git clone https://github.com/PaddlePaddle/PaddleX.git

insert image description here

3.2 Environment preparation

1. Download the 3.4.6 version for Windows from the OpenCV official website.
insert image description here
2. Run the downloaded executable file and decompress OpenCV to a specified directory, such as D:\projects\opencv.
3. Configure environment variables, as shown in the following process:
My Computer -> Properties -> Advanced System Settings -> Environment Variables
insert image description here

Find the Path in the system variables (if not, create it yourself), double-click Edit to
create, fill in the opencv path and save it, if E:\Fileresipority\cloth_check\OpenCV\opencv\build\x64\vc15\bin
you are doing a cmake build, there will be a relevant prompt, please pay attention to the output of vs2019.
4. Click to download the gflags dependency package and decompress it to the deps directory

3.3 compile

1. Open Visual Studio 2019 Community, click Continue without code
insert image description here
2. Click: 文件-> 打开-> CMake
Select the path where the C++ prediction code is located (for example E:\Fileresipority\cloth_check\PaddleX-develop\deploy\cpp), and open CMakeList.txt:
insert image description here

  1. When opening the project, it may be built automatically. Since the following dependency path setting is not performed, an error will be reported, and this error can be ignored for now:
    insert image description here

insert image description here

  1. Click Browse to set the compilation options to specify the path of gflag, OpenCV, and OpenVINO (you can also click "Edit JSON" in the upper right corner to directly modify the json file, and then save the point project -> generate cache). Check the GPU and CUDA options that need to use GPU (need to be installed in advance, you can check the articles in other columns of the author):

1. To be on the safe side, set all values ​​to paths separated by "/":
insert image description here

2. Note here, I saw in other articles that if there is the following error :
insert image description here
you need to change the value in OPENCV_DIR "E:/Fileresipority/cloth_check/OpenCV/opencv/build/x64/vc15/bin".

And I set it up as follows, and the following can compile successfully:

insert image description here
3. Check the GPU that requires a GPU:

insert image description here
4. Check OPENVINO:
insert image description here

  1. Save and generate CMake cache
    insert image description here
    设置完成后, click Save and generate CMake cache in the above image to load variables. Then we can see that the output of vs will print the process of CMake generation. If CMake is generated and no error is reported, it means that the generation is completed.
    Found an error:
    insert image description here
    By viewing the error message:
严重性	代码	说明	项目	文件	行	禁止显示状态 
错误		CMake Error at E:\Fileresipority\cloth_check\PaddleX-develop\deploy\cpp\CMakeLists.txt:73 (find_package): 
Found package configuration file: 
 
E:/Fileresipority/cloth_check/OpenCV/opencv/build/OpenCVConfig.cmake 
 
but it set OpenCV_FOUND to FALSE so package "OpenCV" is considered to be 
NOT FOUND.	 PaddleDeploy	E:\Fileresipority\cloth_check\PaddleX-develop\deploy\cpp\CMakeLists.txt	73

It can be found that it is due to the OpenCVConfig.cmake file in

insert image description here

Regenerate after modification, and get the completion of cmake generation to indicate that the generation is successful:
insert image description here
after the generation is successful, E:\Fileresipority\cloth_check\PaddleX-develop\deploy\cpp\out\build\x64-Releasethe generated directory is as follows:
insert image description here

  1. Click 生成-> 全部生成to generate the executable file in the demo.

The following error was found:
insert image description here
Locate the wrong model_infer.cpp file, and found that the path of the header file was wrong. Compare the name of the relevant header file, and locate the file location in the file manager: Then replace the path: The path of the relevant file in transform.h also needs to be replaced: The path of the relevant file in visualize.h also needs to be changed: next, if there is an error, just modify the path of these three lines
insert image description here
insert image description here
insert image description here
in
insert image description here
which
insert image description here
file
insert image description here
:

#include <E:/Fileresipority/cloth_check/OpenCV/opencv/sources/modules/core/include/opencv2/core/core.hpp>
#include <E:/Fileresipority/cloth_check/OpenCV/opencv/sources/modules/highgui/include/opencv2/highgui/highgui.hpp>
#include <E:/Fileresipority/cloth_check/OpenCV/opencv/sources/modules/imgproc/include/opencv2/imgproc/imgproc.hpp>

The core.hpp file needs to be changed to the .hpp file here:
insert image description here
The problematic path in core.h should also be modified:
insert image description here

After the modification, click to regenerate all, but still encounter an error:
insert image description here
related issues are being communicated with Baidu engineers, to be continued...

Guess you like

Origin blog.csdn.net/m0_46339652/article/details/128746961