我有Intel NCS2,我想在它上运行我的程序,但有问题
代码:
import json
import cv2
def decode_out(out):
detections = []
for data in out[0, 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 6442PycharmProjectsOpenVino33.jpg")
image = cv2.resize(image, (300, 300))
input_blob = cv2.dnn.blobFromImage(image, 1.0 / 127.5, (300, 300), 127.5)
model = r"C:Users 6442PycharmProjectsOpenVinoMobileNetSSD_deploy.caffemodel"
prototxt = r"C:Users 6442PycharmProjectsOpenVinoMobileNetSSD_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版本,该版本可能没有Intel的深度学习推理引擎(DL IE(。
使用推理引擎构建OpenCV,以启用从模型优化器加载模型
假设您在Windows上(基于程序中使用的路径(,您可以选择以下选项之一:
- 下载并安装英特尔®;OpenVINO™工具箱-包括现成的OpenCV构建
- OpenCV+DLDT Windows软件包(社区版(
- 从源代码为Microsoft Windows构建OpenCV
有关此信息和其他信息,请查看英特尔的深度学习推理引擎后端