python - 如何使用 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'
我期望模型的预测,但我只是得到这个错误。
解决方案
我刚刚测试了这段代码,它工作得很好。您需要先安装 openvino,然后运行 setupvars.bat 文件以初始化 openvino 环境。完成后,您可以运行代码,它将开始检测您的面部。我在配备 12Gb RAM 的 Intel i5 上对此进行了测试,我得到了 23-25fps,这很好。
推荐阅读
- javascript - 将 SVG 作为 img 元素的 src 加载时会触发 load 事件吗?
- python - 访问 JSON 对象中的嵌套键
- java - “HTTP 状态 500 - 内部服务器错误”通过服务器上传文件
- javascript - Vuex 操作无法正常工作。显示错误“signInWithEmailAndPassword 失败:第一个参数“email”必须是有效字符串”
- php - 如何替换html文件中的内容
- javascript - 如何将锚 href 属性添加到选项对象?
- emacs - 改进从 org 的 babel 源代码生成的格式
- c# - 从基方法的覆盖方法返回。统一
- java - 带有 avro 的递归模式 (SchemaBuilder)
- javascript - 无法将 websocket 连接到服务人员