Table of contents
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:
install.exe
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:
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
Converted directory:
3. Compile and generate Openvino reasoning files
3.1 Get the deployment code
git clone https://github.com/PaddlePaddle/PaddleX.git
3.2 Environment preparation
1. Download the 3.4.6 version for Windows from the OpenCV official website.
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
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
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:
- 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:
- 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 "/":
2. Note here, I saw in other articles that if there is the following error :
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:
3. Check the GPU that requires a GPU:
4. Check OPENVINO:
- Save and generate CMake cache
设置完成后
, 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:
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
Regenerate after modification, and get the completion of cmake generation to indicate that the generation is successful:
after the generation is successful, E:\Fileresipority\cloth_check\PaddleX-develop\deploy\cpp\out\build\x64-Release
the generated directory is as follows:
- Click
生成
->全部生成
to generate the executable file in the demo.
The following error was found:
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
in
which
file
:
#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:
The problematic path in core.h should also be modified:
After the modification, click to regenerate all, but still encounter an error:
related issues are being communicated with Baidu engineers, to be continued...