[英]How to use OpenVINO pre-trained models?
I have installed OpenVINO recently but I don't know how I should give inputs and get the predict from OpenVINOs pre-trained models.我最近安装了 OpenVINO,但我不知道我应该如何提供输入并从 OpenVINO 预训练模型中获得预测。
there is two files with .bin and .xml suffixes, I've just worked with keras so I can't use this models in opencv.有两个带有 .bin 和 .xml 后缀的文件,我刚刚使用过 keras,所以我不能在 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.我期待模型的预测,但我只是得到这个错误。
I just tested this code and it works perfectly fine.我刚刚测试了这段代码,它工作得很好。 You need to install openvino first and then run setupvars.bat file in order to initialize the openvino enviroment.
您需要先安装 openvino,然后运行 setupvars.bat 文件以初始化 openvino 环境。 Once that is done, you can run your code and it will start detecting your face.
完成后,您可以运行您的代码,它将开始检测您的脸。 I tested this on Intel i5 with 12Gb RAM and I was getting 23-25fps which is good.
我在具有 12Gb RAM 的 Intel i5 上对此进行了测试,并且获得了 23-25fps,这很好。
You need to build OpenCV with Inference Engine support as mentioned in the message.您需要使用消息中提到的推理引擎支持构建 OpenCV。 See wiki for details: https://github.com/opencv/opencv/wiki/Intel%27s-Deep-Learning-Inference-Engine-backend .
有关详细信息,请参阅 wiki: 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).如果您使用 OpenVINO 发行版中的 OpenCV,它必须已经使用 IE 构建(可能除了 2019 年 1 月的单个 R5.1 版本)。
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 .我们还致力于使用 IE 构建 OpenCV 的简化方法(不指定路径,只是通过 cmake 下载它的源代码),请参阅 PR https://github.com/opencv/opencv/pull/13965 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.