当前位置:网站首页>Use openvinotm preprocessing API to further improve the reasoning performance of yolov5
Use openvinotm preprocessing API to further improve the reasoning performance of yolov5
2022-06-23 13:36:00 【Intel edge computing community】
summary
stay 《 be based on OpenVINOTM 2022.1 Realization YOLOv5 Reasoning program 》 Detailed in :
- YOLOv5 How to install and export the framework YOLOv5.onnx Model
- OpenVINOTM 2022.1 And how to write YOLOv5 Model inference program
This article will show you how to use OpenVINOTM 2022.1 Preprocessing API, Further improve YOLOv5 The reasoning and computing performance of the model
What is pretreatment API function ?
OpenVINO 2022.1 Previous versions did not provide OpenVINOTM Runtime Native for data preprocessing API function [1], Pictured 1-1 Shown , Developers must use third-party libraries ( for example :OpenCV) To achieve data preprocessing .
|
chart 1-1 OpenVINOTM Runtime Preprocessing API
Assume no pretreatment API, Then the preprocessing operation of input data can only be placed in CPU Implemented on ,CPU After data preprocessing , And then transmit the preprocessed data to iGPU、VPU etc. AI Accelerate computing devices for reasoning .
With pretreatment API after , The preprocessing operations can be integrated into the model execution diagram , such iGPU、VPU Or upcoming Intel Independent graphics cards can perform data preprocessing , Don't need to rely on CPU, Improved execution efficiency , Pictured 1-2 Shown .

chart 1-2 Preprocessing OpenCV vs OpenVINO
Typical operations of data preprocessing
Due to the Shape、Precision Other characteristics , Inconsistent with the requirements of model input tensor , Therefore, pretreatment is required , Transform the input data according to the requirements of the model input tensor , Such as chart 1-3 Shown .
chart 1-3 input data vs Model input tensor
From the picture 1-3 You can see , Typical operations of data preprocessing are :
- Change the shape of the input data :[720, 1280,3] → [1, 3, 640, 640]
- Change the accuracy of the input data :U8 → f32
- Change the color channel order of input data :BGR → RGB
- Change the layout of the input data (layout):HWC → NCHW
- Normalized data : Subtract the mean (mean), Divided by standard deviation (std)
- Data preprocessing API How to use
Typical operations corresponding to data preprocessing ,OpenVINOTM Preprocessing API Corresponding classes are provided , Easy for developers to use quickly , The main processes are 6 Step [2], Pictured 1-4 Shown , In turn, is :
- Instantiation PrePostProcessor object ;
- Declare the information of the input data
- Specify the data layout of the model (layout)
- Set the information of the model output tensor
- Define the specific steps of preprocessing
- Integrate preprocessing steps into the model

chart 1-4 Use pretreatment API The process of
This article will introduce... In the above order .
Instantiation PrePostProcessor object
Instantiation PrePostProcessor Object's Python Code , Such as code list 1-1 Shown .
Code list 1-1 Instantiation PrePostProcessor object
from openvino.runtime import Core, Type, Layout
from openvino.preprocess import PrePostProcessor, ColorFormat
# Please modify the model path
model_path ="yolov5s.onnx"
model = core.read_model(model_path)
# Step1: Instance PrePostProcessor object
ppp = PrePostProcessor(model)
Declare the information of the input data
Declare the information of the input data Python Code , Such as code list 1-2 Shown .
Code list 1-2 Declare the information of the input data
# Step2: Declare input data information:
ppp.input().tensor() \
.set_color_format(ColorFormat.BGR) \
.set_element_type(Type.u8) \
.set_layout(Layout('NHWC'))
Specify the data layout of the model (layout)
Specify the data layout of the model (layout) Of Python Code , Such as code list 1-3 Shown .
Code list 1-3 Specify the data layout of the model (layout)
# Step3: Specify actual model layout
ppp.input().model().set_layout(Layout('NCHW'))
Set the information of the model output tensor
Set the information of the model output tensor Python Code , Such as code list 1-4 Shown .
Code list 1-4 Set the information of the model output tensor
# Step4: Set output tensor information:
# - precision of tensor is supposed to be 'f32'
ppp.output().tensor().set_element_type(Type.f32)
Define the specific steps of preprocessing
Define the specific steps of preprocessing Python Code , Such as code list 1-5 Shown .

Code list 1-5 Define the specific steps of preprocessing
# Step5: Apply preprocessing modifing the original 'model'
# - Precision from u8 to f32
# - color plane from BGR to RGB
# - subtract mean
# - divide by scale factor
# - Layout conversion will be done automatically as last step
ppp.input().preprocess() \
.convert_element_type(Type.f32) \
.convert_color(ColorFormat.RGB) \
.mean([0.0, 0.0, 0.0]) \
.scale([255.0, 255.0, 255.0])
Integrate preprocessing steps into the model
Integrate preprocessing steps into the model's Python Code , Such as code list 1-6 Shown .
Pretreatment method | CPU/iGPU model | Reasoning equipment | The number of iterations | The elapsed time |
OpenVINOTM Preprocessing API | i7-1165G7 IntelIrisXe | device=”GPU” | 500 | 12.68s |
OpenCV | i7-1165G7 IntelIrisXe | device=”GPU” | 500 | 13.43s |
Code list 1-6 Integrate preprocessing steps into the model
# Step6: Integrate preprocessing steps into model
print(f'Build preprocessor: { ppp}')
model = ppp.build()
Export the model with integrated preprocessing steps
Use serialize() function , Models with integrated preprocessing steps can be exported , Convenient for subsequent calls , Such as code list 1-7 Shown .
Code list 1-7 Export the model with preprocessing steps
# Save the Model with preprocess
from openvino.offline_transformations import serialize
serialize(model, 'yolov5s.xml', 'yolov5s.bin')
Use Netron Open the export model , You can see that the preprocessing steps have been integrated into the execution diagram , Pictured 1-5 Shown .
chart 1-5 Preprocessing integrated into execution diagram
Export the complete source code of the integration preprocessing model :https://gitee.com/ppov-nuc/yolov5_infer/blob/main/preprocessing_with_saving_to_IR.py
Complete sample code and test results
Used with this document OpenVINOTM 2022.1 Preprocessing API Realization YOLOv5s The complete source code of the inference program , See :infer_with_openvino_preprocess.py · PPOV_NUC/yolov5_infer - Gitee.com.
surface 1-1 Use OpenVINOTM 2022.1 Preprocessing API And use OpenCV Performance comparison of pretreatment
operating system :Windows10;Python edition :3.8;OpenVINO edition :2022.1
Model :yolov5s.onnx
Pretreatment method | CPU/iGPU model | Reasoning equipment | The number of iterations | The elapsed time |
OpenVINOTM Preprocessing API | i7-1165G7 IntelIrisXe | device=”GPU” | 500 | 12.68s |
OpenCV | i7-1165G7 IntelIrisXe | device=”GPU” | 500 | 13.43s |
Carry out orders , take yolov5s.onnx Convert to FP16 Accurate yolov5s.xml after
mo --input_model yolov5s.onnx --data_type FP16
operating system :Windows10;Python edition :3.8;OpenVINO edition :2022.1
Model :yolov5s.xml @ FP16
Pretreatment method | CPU/iGPU model | Reasoning equipment | The number of iterations | The elapsed time |
OpenVINOTM Preprocessing API | i7-1165G7 IntelIrisXe | device=”GPU” | 500 | 7.41s |
OpenCV | i7-1165G7 IntelIrisXe | device=”GPU” | 500 | 8.24s |
summary
This article gives a complete introduction to what is OpenVINO Preprocessing API And why pretreatment is recommended API Integrate preprocessing operations into the model execution diagram , Then it introduces the use steps in detail and provides the complete sample source code .
By running the source code , You can see , Used OpenVINO Preprocessing API, Make the input data preprocessing operation no longer depend on CPU, This can be done by reasoning devices ( Such as GPU/VPU) complete , It improves the efficiency of reasoning calculation , Reduced running time .
reference :
[1] openvino.preprocess — OpenVINO documentation
[2] Preprocessing API - details — OpenVINO documentation
[3] openvino_notebooks/002-openvino-api.ipynb at main · openvinotoolkit/openvino_notebooks · GitHub
边栏推荐
- How long is the financial product? Is it better for novices to buy long-term or short-term?
- 618的省钱技术攻略 来啦 -体验场景 领取10元猫超卡!
- 16 channel HD-SDI optical transceiver multi channel HD-SDI HD video optical transceiver 16 channel 3g-sdi HD audio video optical transceiver
- Getting started with reverse debugging - learn about PE structure files
- The R language inputs the distance matrix to the hclust function for hierarchical clustering analysis, uses the cutree function to divide the hierarchical clustering clusters, specifies the number of
- Tuikit audio and video low code solution navigation page
- Wallys/DR6018-S/ 802.11AX MU-MIMO OFDMA / 2* GE PORTS/WIFI 6e / BAND DUAL CONCURRENT
- 90%的人都不懂的泛型,泛型的缺陷和应用场景
- The way out after the development of Internet technology -- the birth of IVX
- Go write permissions to file writefile (FileName, data, 0644)?
猜你喜欢

64 channel PCM telephone optical transceiver 64 channel telephone +2-channel 100M Ethernet telephone optical transceiver 64 channel telephone PCM voice optical transceiver

Generics, generic defects and application scenarios that 90% of people do not understand

2 万字 + 30 张图 |MySQL 日志:undo log、redo log、binlog 有什么用?

C语言的基本数据类型及其打印输出

父母-子女身高数据集的线性回归分析

Androd Gradle模块依赖替换如何使用

#云原生征文#深入了解Ingress

The two 985 universities share the same president! School: true

栈和队列的基本使用

有向图D和E
随机推荐
R language uses the polR function of mass package to build an ordered multi classification logistic regression model, and uses the summary function to obtain the summary statistical information of the
Analysis and solution of connection failure caused by MySQL using replicationconnection
Strengthen the sense of responsibility and bottom line thinking to build a "safety dike" for flood fighting and rescue
Develop a powerful tool for increasing efficiency - vscode plug-in sharing in 2022
"Four highs" of data midrange stability | startdt Tech Lab 18
你管这破玩意儿叫 MQ?
Oracle中dbms_output.put_line怎么使用
Quarkus+saas multi tenant dynamic data source switching is simple and perfect
理解ADT与OOP
Generics, generic defects and application scenarios that 90% of people do not understand
Getting started with reverse debugging - learn about PE structure files
Hanyuan hi tech 8-way telephone +1-way 100M Ethernet RJ11 telephone optical transceiver 8-way PCM telephone optical transceiver
2-optical-2-electric cascaded optical fiber transceiver Gigabit 2-optical-2-electric optical fiber transceiver Mini embedded industrial mine intrinsic safety optical fiber transceiver
理财产品长期是几年?新手最好买长期还是短期?
Loss, duplication and backlog of message queues
[deeply understand tcapulusdb technology] transaction execution of document acceptance
Windows install MySQL
The way out after the development of Internet technology -- the birth of IVX
ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked.
The filter function of dplyr package in R language filters the data rows containing the specified string in the specified data column of dataframe data based on the grepl function
