-
Notifications
You must be signed in to change notification settings - Fork 3
/
export_yolov8_cls_ppp.py
34 lines (29 loc) · 1.21 KB
/
export_yolov8_cls_ppp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from openvino.preprocess import PrePostProcessor, ColorFormat, ResizeAlgorithm
from openvino.runtime import Core, Layout, Type, serialize
# 定义常量
MODEL_NAME = "yolov8n"
# ======== Step 0: read original model =========
core = Core()
model = core.read_model(f"{MODEL_NAME}-cls.xml")
# Step 1: Add Preprocessing steps to a model ==
ppp = PrePostProcessor(model)
# Declare User’s Data Format
ppp.input().tensor() \
.set_element_type(Type.u8) \
.set_spatial_dynamic_shape() \
.set_layout(Layout('NHWC')) \
.set_color_format(ColorFormat.BGR)
# Declaring Model Layout
ppp.input().model().set_layout(Layout('NCHW'))
# Explicit preprocessing steps. Layout conversion will be done automatically as last step
ppp.input().preprocess() \
.convert_element_type() \
.convert_color(ColorFormat.RGB) \
.resize(ResizeAlgorithm.RESIZE_LINEAR) \
.mean([123.675, 116.28, 103.53]) \
.scale([58.624, 57.12, 57.375])
# Integrate preprocessing Steps into a Model
print(f'Dump preprocessor: {ppp}')
model_with_ppp = ppp.build()
# ======== Step 2: Save the model with preprocessor================
serialize(model_with_ppp, f'{MODEL_NAME}-cls_ppp.xml', f'{MODEL_NAME}-cls_ppp.bin')