使用Yolov5 & Opencv时出错,onnx(-215:Assertion failed)
我准备用Yolov5 & Opencv做睡眠识别检测,onnx。 它通过网络摄像头实时接收视频,并在您是否闭眼时输出。
我把.pt文件转成了.onnx,读模型好像没有问题
output = net.forward()继续出现这些错误
[错误: (-215:Assertion failed) total(srcShape, srcRange.start, srcRange.end) == maskTotal in function 'cv::dnn::computeShapeByReshapeMask']
import cv2
import numpy as np
onnx_model_path = ('C:/Users/182947/Downloads/best.onnx')
net = cv2.dnn.readNetFromONNX(onnx_model_path)
if net.empty():
print('Network load failed.')
exit()
class_labels = ['R_eye_open', 'L_eye_open', 'R_eye_close', 'L_eye_close']
camera = cv2.VideoCapture(0)
while True:
ret, frame = camera.read()
if not ret:
break
frame = cv2.resize(frame, (320, 320))
input_blob = cv2.dnn.blobFromImage(frame, 1.0, (320, 320))
net.setInput(input_blob)
output = net.forward()
for detection in output[0, 0]:
score = float(detection[2])
class_id = int(detection[1])
if score > 0.5:
left = int(detection[3] * frame.shape[1])
top = int(detection[4] * frame.shape[0])
right = int(detection[5] * frame.shape[1])
bottom = int(detection[6] * frame.shape[0])
cv2.rectangle(frame, (left, top), (right, bottom), (0, 255, 0), thickness=2)
class_label = class_labels[class_id]
cv2.putText(frame, f'{class_label}: {score:.2f}', (left, top - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 255, 0), 2)
cv2.imshow("Frame", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
camera.release()
cv2.destroyAllWindows()
为什么会出现错误,我该如何解决?