微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

OpenVINO(NCS2):如何使用推理引擎构建 OpenCV

如何解决OpenVINO(NCS2):如何使用推理引擎构建 OpenCV

我有英特尔 NCS2,我想在它上面运行我的程序,但我有一些问题

代码

import json
import cv2


def decode_out(out):
    detections = []

    for data in out[0,:,:]:
        if float(data[2]) > 0.3:
            detections.append({
                "bBox": [float(x) for x in data[3:]],"score": float(data[2]),"class_id": int(data[1])
            })

    return sorted(detections,key=lambda x: x['score'],reverse=True)


image = cv2.imread(r"C:\Users\06442\PycharmProjects\OpenVino\33.jpg")
image = cv2.resize(image,(300,300))
input_blob = cv2.dnn.blobFromImage(image,1.0 / 127.5,300),127.5)

model = r"C:\Users\06442\PycharmProjects\OpenVino\MobileNetSSD_deploy.caffemodel"
prototxt = r"C:\Users\06442\PycharmProjects\OpenVino\MobileNetSSD_deploy.prototxt"

net = cv2.dnn.readNetFromCaffe(prototxt,model)

# with cpu
net.setPreferableTarget(cv2.dnn.DNN_TARGET_cpu)
net.setPreferableBackend(cv2.dnn.DNN_BACKEND_OPENCV)
net.setInput(input_blob)
out1 = net.forward()
print(json.dumps(decode_out(out1),indent=2))

# with NCS2
net.setPreferableTarget(cv2.dnn.DNN_TARGET_MYRIAD)
net.setPreferableBackend(cv2.dnn.DNN_BACKEND_INFERENCE_ENGINE)
net.setInput(input_blob)
out2 = net.forward()
print(json.dumps(decode_out(out2),indent=2))

“out2 = net.forward()”中的错误

UnkNown backend identifier in function

cpu 上一切正常,但在 NCS2 上没有。 在我的另一个代码中,我有错误

Build OpenCV with Inference Engine to enable loading models from Model Optimizer

也许有帮助

解决方法

如错误所示,这可能是由于您的环境中使用的 OpenCV 版本可能没有英特尔的深度学习推理引擎 (DL IE)。

使用推理引擎构建 OpenCV 以启用从模型优化器加载模型

假设您使用的是 Windows(基于您程序中使用的路径的假设),您可以选择以下选项之一:

有关此信息和其他信息,请查看 Intel's Deep Learning Inference Engine backend

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。