Qiyu Zhong
Qiyu Zhong

Reputation: 74

Trying to run OpenVINO inference kit with an OpenCV version of 4.5.1, while reporting error

The error that I have gotten is:

cv2.error: OpenCV(4.5.1) /private/var/folders/nz/vv4_9tw56nv9k3tkvyszvwg80000gn/T/pip-req-build-yaf6rry6/opencv/modules/dnn/src/dnn.cpp:3901: error: (-2:Unspecified error) Build OpenCV with Inference Engine to enable loading models from Model Optimizer. in function 'readFromModelOptimizer'

The complete code that calls the function of the OpenVINO kit is:

import cv2 as cv

// Check the path of the package

print(cv.__file__)
print(cv.getBuildInformation())

// Load the model

net = cv.dnn.readNet('face-detection-adas-0001.xml', 'face-detection-adas-0001.bin')

// Specify target device (CPU)

net.setPreferableTarget(cv.dnn.DNN_TARGET_CPU)
     
// Read an image

frame = cv.imread('faces.jpg')
     
// Prepare input blob 

blob = cv.dnn.blobFromImage(frame, size=(672, 384), ddepth=cv.CV_8U)

// Perform inference (face detection)

net.setInput(blob)
out = net.forward()
     
// Draw detected faces on the frame

for detection in out.reshape(-1, 7):

    confidence = float(detection[2])
    
    xmin = int(detection[3] * frame.shape[1])
    ymin = int(detection[4] * frame.shape[0])
    xmax = int(detection[5] * frame.shape[1])
    ymax = int(detection[6] * frame.shape[0])

    if confidence > 0.2:
        cv.rectangle(frame, (xmin, ymin), (xmax, ymax), color=(0, 255, 0))

// Save the frame to an image file

cv.imwrite('output_02.png', frame)

where the declaration of face-detection-adas-0001.xml' and 'face-detection-adas-0001.bin' is literally the model of MobileNet as the default settings of OpenVINO inference engine includes.

May I wonder if I was wrong in any way to deal with the architecture of the neural network or there is some kind of issue of my hardware setup? I am using a Macbook Pro (13-inch, 2020, 3-thunderbolt ports) with Catalina 10.15.7.

Thanks!~

Upvotes: 0

Views: 277

Answers (1)

markusbr
markusbr

Reputation: 118

How have you installed OpenCV (and OpenVINO) on your machine?

Have you built OpenCV from source-code or installed a pre-built, pre-packaged version?

You might want to check e.g. this post: OpenVINO: How to build OpenCV with Inference Engine to enable loading models from Model Optimizer

Few options:

  • build OpenCV from source-code, and add -DWITH_INF_ENGINE=ON to the call to cmake
  • using OpenCV via the OpenVINO installation (in older versions of OpenVINO, OpenCV was already contained as a pre-built version; in newer versions OpenCV is not included but can be downloaded via a helper-script shipping with the OpenVINO installation)
  • checking whether your application simply cannot find the OpenVINO libraries (like missing search-paths)

Upvotes: 1

Related Questions