【oppenvino】使用docker安装openvino并进行onnx到IR中间件的转化


下面是详细的过程:

1.拉取oppenvino的docker

下载完后其镜像ID为2a3b1bacb73a

docker pull openvino/ubuntu18_dev

2.将带转换的.onnx文件放入指定文件夹下,作为docker容器在宿主机上的工作目录

这里是将scrfd_2.5g_kps_Simplified.onnx及arcfaceresnet100-8_simplify.onnx放入C:\Users\25360\Desktop\simplify文件夹下;

3.启动docker容器:

docker run -itd -v /c/Users/25360/Desktop/simplify:/app --name simplify  --network=bridge 2a3b1bacb73a

4.进行模型转换

其大体的命令格式为:

mo --framework=onnx --input_model "{onnx_model_path}"  --input_shape "[1,3,32,32]" --data_type FP32 --output_dir "{MODEL_DIR}"

对于scrfd_2.5g_kps_Simplified.onnx:

mo --framework=onnx --input_model /app/scrfd_2.5g_kps_Simplified.onnx  --input_shape "[1,3,640,640]" --data_type FP32 --output_dir ./

输出:

OpenVINO runtime found in:      /opt/intel/openvino/python/python3.6/openvino
OpenVINO runtime version:       2022.2.0-7713-af16ea1d79a-releases/2022/2
Model Optimizer version:        2022.2.0-7713-af16ea1d79a-releases/2022/2
[ SUCCESS ] Generated IR version 11 model.
[ SUCCESS ] XML file: /app/scrfd_2.5g_kps_Simplified.xml
[ SUCCESS ] BIN file: /app/scrfd_2.5g_kps_Simplified.bin
[ SUCCESS ] Total execution time: 1.42 seconds.
[ SUCCESS ] Memory consumed: 104 MB.

重点关注生成.xml以及.bin,而.mapping可忽略

对于arcfaceresnet100-8_simplify.onnx:

mo --framework=onnx --input_model /app/arcfaceresnet100-8_simplify.onnx  --input_shape "[1,3,112,112]" --data_type FP32 --output_dir ./

输出:

OpenVINO runtime found in:      /opt/intel/openvino/python/python3.6/openvino
OpenVINO runtime version:       2022.2.0-7713-af16ea1d79a-releases/2022/2
Model Optimizer version:        2022.2.0-7713-af16ea1d79a-releases/2022/2
[ SUCCESS ] Generated IR version 11 model.
[ SUCCESS ] XML file: /app/arcfaceresnet100-8_simplify.xml
[ SUCCESS ] BIN file: /app/arcfaceresnet100-8_simplify.bin
[ SUCCESS ] Total execution time: 19.76 seconds.
[ SUCCESS ] Memory consumed: 603 MB.

oppenvino加速完成。

5.验证

将下列代码保存为test.py,放入C:\Users\25360\Desktop\simplify,运行即可:
在这里插入图片描述

from openvino.inference_engine import IECore
import numpy as np
import cv2
import time

ie = IECore()
# model="ctdet_coco_dlav0_512.onnx"
model = "scrfd_2.5g_kps_Simplified.xml"
net = ie.read_network(model=model)
input_blob = next(iter(net.input_info))
out_blob = next(iter(net.outputs))
net.batch_size = 1  # batchsize

n, c, h, w = net.input_info[input_blob].input_data.shape
print(n, c, h, w)
images = np.ndarray(shape=(n, c, h, w))
exec_net = ie.load_network(network=net, device_name="CPU")
start = time.time()
res = exec_net.infer(inputs={input_blob: images})
print(res)
print('infer total time is %.4f s' % (time.time() - start))
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

颢师傅

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值