0

I have Intel NCS2 and i want run my program on it, but i have some problem

Code:

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))

Error in "out2 = net.forward()":

Unknown backend identifier in function

On CPU all work but on NCS2 not. In my another code i have error:

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

Maybe it's help

Leonid
  • 206
  • 2
  • 10
  • Does this answer your question? [OpenVINO: How to build OpenCV with Inference Engine to enable loading models from Model Optimizer](https://stackoverflow.com/questions/57007007/openvino-how-to-build-opencv-with-inference-engine-to-enable-loading-models-fro) – Federico Baù Jan 13 '21 at 09:08
  • Does this answer your question), [OpenVINO: How to build OpenCV with Inference Engine to enable loading models from Model Optimizer](https://stackoverflow.com/questions/57007007/openvino-how-to-build-opencv-with-inference-engine-to-enable-loading-models-fro) – Federico Baù Jan 13 '21 at 09:09
  • Ofc i see this question, but it not work for me – Leonid Jan 13 '21 at 09:15

1 Answers1

1

As the error suggests this is probably due to the OpenCV version used in your environment, which may not have Intel's Deep Learning Inference Engine (DL IE).

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

Assuming you are on Windows (based this assumption on paths used in your program), you can choose one of the following options:

For this and additional information check Intel's Deep Learning Inference Engine backend

avitial
  • 176
  • 6