首页 > 解决方案 > 如何使用 OpenVINO 预训练模型?

问题描述

我最近安装了 OpenVINO,但我不知道我应该如何提供输入并从 OpenVINO 预训练模型中获得预测。

有两个带有 .bin 和 .xml 后缀的文件,我刚刚使用过 keras,所以我不能在 opencv 中使用这个模型。

我找到了这段代码,但它没有用。

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)

有错误代码:

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'

我期望模型的预测,但我只是得到这个错误。

标签: pythonintelopenvino

解决方案


我刚刚测试了这段代码,它工作得很好。您需要先安装 openvino,然后运行 ​​setupvars.bat 文件以初始化 openvino 环境。完成后,您可以运行代码,它将开始检测您的面部。我在配备 12Gb RAM 的 Intel i5 上对此进行了测试,我得到了 23-25fps,这很好。


推荐阅读