问题
I have installed OpenVINO recently but I don't know how I should give inputs and get the predict from OpenVINOs pre-trained models.
there is two files with .bin and .xml suffixes, I've just worked with keras so I can't use this models in opencv.
I find this code but it didn't work.
import cv2 as cv
net = cv.dnn.readNet('face-detection-adas-0001.bin', 'face-detection-adas-0001.xml')
cap = cv.VideoCapture(0)
while cv.waitKey(1) < 0:
hasFrame, frame = cap.read()
if not hasFrame:
break
blob = cv.dnn.blobFromImage(frame, size=(672, 384))
net.setInput(blob)
out = net.forward()
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.5:
cv.rectangle(frame, (xmin, ymin), (xmax, ymax), color=(0, 255, 0))
cv.imshow('OpenVINO face detection', frame)
there's the error code:
Traceback (most recent call last):
File "C:\Users\Ali-10\Desktop\facial_landmark\face.py", line 3, in <module>
net = cv.dnn.readNet('face-detection-adas-0001.bin', 'face-detection-adas-0001.xml')
cv2.error: OpenCV(3.4.4) C:\projects\opencv-python\opencv\modules\dnn\src\dnn.cpp:2428: error: (-2:Unspecified error) Build OpenCV with Inference Engine to enable loading models from Model Optimizer. in function 'cv::dnn::experimental_dnn_34_v10::Net::readFromModelOptimizer'
I expect the prediction of the model but I just get this error.
回答1:
You need to build OpenCV with Inference Engine support as mentioned in the message. See wiki for details: https://github.com/opencv/opencv/wiki/Intel%27s-Deep-Learning-Inference-Engine-backend.
If you use OpenCV from OpenVINO distribution, it must be already built with IE (maybe except a single R5.1 release from January of 2019).
We also work on simplified way to build OpenCV with IE (without specifying paths but just downloading it's source code by cmake), see PR https://github.com/opencv/opencv/pull/13965.
来源:https://stackoverflow.com/questions/55345798/how-to-use-openvino-pre-trained-models