ValueError:顺序层的输入 0 与层不兼容::预期 min_ndim=4,发现 ndim=3。完整形状收到:[无,48,48]

问题描述 投票:0回答:0

我正在尝试从相机检测情绪,但出现 ValueError:顺序层的输入 0 与层不兼容::预期 min_ndim=4,发现 ndim=3。收到完整形状:以下代码出现 [None, 48, 48] 错误。任何帮助将不胜感激。谢谢!

`导入cv2 从 deepface 导入 DeepFace 将 numpy 导入为 np face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') 视频 = cv2.VideoCapture(0,cv2.CAP_DSHOW)

while video.isOpened(): _,frame = video.read()

grey=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
face = face_cascade.detectMultiScale(grey,scaleFactor=1.1,minNeighbors=5)

for x,y,w,h in face:
    img = cv2.rectangle(frame,(x,y),(x+w,y+h),(0,0,255),1)
    try:
        analyze = DeepFace.analyze(frame,actions=['emotion'])
        print(analyze['dominant_emotion'])
    except Exception as e:
        print("The error is:",e)

cv2.imshow('video',frame)
key = cv2.waitKey(1)
if key==ord('q'):
    break

video.release()`

我试图通过在代码中添加这一行来重塑它(上面的尝试:函数):

frame = frame.reshape(-1, 28, 28, 1)

但是为此我收到如下错误: 框架 = frame.reshape(-1, 28, 28, 1) ValueError:无法将大小为 921600 的数组重塑为形状 (28,28,1)

pycharm python-3.8 cv2 anaconda3 deepface
© www.soinside.com 2019 - 2024. All rights reserved.