环境配置
python3.8.10
pip install -i https://pypi.doubanio.com/simple openvino
pip install -i https://pypi.doubanio.com/simple ipywidgets
onnx2openvino.py
from openvino.runtime import Core
from openvino.runtime import serialize
# 创建一个 OpenVINO 的核心对象 ie,这是与推理引擎的主要交互接口。
ie = Core()
# 要转换的onnx模型
onnx_model_path = r"best.onnx"
# 使用ie对象读取onnx模型
model_onnx = ie.read_model(model=onnx_model_path)
# compiled_model_onnx = ie.compile_model(model=model_onnx, device_name="CPU") #
# xml_path:指定转换完的openvino 输出的 XML 文件路径。 bin_path:指定转换完的openvino 输出的bin文件路径。 version:设置模型版本为 UNSPECIFIED。
serialize(model=model_onnx, xml_path="model.xml",
bin_path="model.bin",
version="UNSPECIFIED")
process.py
# -*- coding: utf-8 -*-
import cv2
import numpy as np
import os
def load_image(image_path):
image = cv2.imdecode(np.fromfile(image_path, dtype=np.uint8), cv2.IMREAD_COLOR)
return image
def pad(image, new_shape=[160, 160], color=(255, 255, 255)):
shape = image.shape[:2]
ratio = min(new_shape[0] / shape[0], new_shape[1] / shape[1])
resize_shape = int(round(shape[1] * ratio)), int(round(shape[0] * ratio))
image = cv2.resize(image, resize_shape, interpolation=cv2.INTER_LINEAR)
dw, dh = new_shape[1] - resize_shape[0], new_shape[0] - resize_shape[1]
top, bottom = int(round(dh / 2 - 0.1)), int(round(dh / 2 + 0.1))
left, right = int(round(dw / 2 - 0.1)), int(round(dw / 2 + 0.1))
image = cv2.copyMakeBorder(image, top, bottom, left, right, cv2.BORDER_CONSTANT, value=color) # add border
return image
# 缩放图片至指定尺寸(640x640),短边自动pad 到640
def letterbox(im, new_shape=(640, 640), color=(114, 114, 114)):
# Resize and pad image while meeting stride-multiple constraints
shape = im.shape[:2]

最低0.47元/天 解锁文章
1万+

被折叠的 条评论
为什么被折叠?



