下面是详细的过程:
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))