【发布时间】:2021-01-13 08:34:41
【问题描述】:
我有 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\06442\PycharmProjects\OpenVino\33.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\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
也许有帮助
【问题讨论】:
-
我看到了这个问题,但它对我不起作用
标签: python opencv intel openvino