我正在使用keras加载存储在h5文件中的模型,但出现此错误,我尝试在google上搜索但没有结果。
请帮助。
face_classifier = cv2.CascadeClassifier(cv2.data.haarcascades +'haarcascade_frontalface_alt.xml')
classifier = load_model('facial_expression.h5')
class_labels = ['Angry', 'Disgust', 'Fear', 'Happy', 'Neutral', 'Sad', 'Surprise']
cap = cv2.VideoCapture(0)
while True:
ret, frame = cap.read()
labels = []
gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
faces = face_classifier.detectMultiScale(gray,1.3,5)
for (x,y,w,h) in faces:
cv2.rectangle(frame,(x,y),(x+w,y+h),(255,0,0),2)
roi_gray = gray[y:y+h,x:x+w]
roi_gray = cv2.resize(roi_gray,(48,48),interpolation=cv2.INTER_AREA)
# rect,face,image = face_detector(frame)
if np.sum([roi_gray])!=0:
roi = roi_gray.astype('float')/255.0
roi = img_to_array(roi)
roi = np.expand_dims(roi,axis=0)
# make a prediction on the ROI, then lookup the class
preds = classifier.predict(roi)[0]
label=class_labels[preds.argmax()]
label_position = (x,y)
cv2.putText(frame,label,label_position,cv2.FONT_HERSHEY_SIMPLEX,2,(0,255,0),3)
else:
cv2.putText(frame,'No Face Found',(20,60),cv2.FONT_HERSHEY_SIMPLEX,2,(0,255,0),3)
cv2.imshow('Emotion Detector',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
这样的错误:
deserialize_keras_object中的第147行“ C:\ Users \ ADMIN \ anaconda3 \ envs \ myenv \ lib \ site-packages \ keras \ utils \ generic_utils.py” list(custom_objects.items()))
from_config中的第301行,文件“ C:\ Users \ ADMIN \ anaconda3 \ envs \ myenv \ lib \ site-packages \ keras \ engine \ sequential.py” custom_objects = custom_objects)
反序列化文件“ C:\ Users \ ADMIN \ anaconda3 \ envs \ myenv \ lib \ site-packages \ keras \ layers_ init _。py”,行168 printable_module_name ='图层')
deserialize_keras_object中的文件“ C:\ Users \ ADMIN \ anaconda3 \ envs \ myenv \ lib \ site-packages \ keras \ utils \ generic_utils.py”,行149 返回cls.from_config(config ['config'])
from_config中的文件“ C:\ Users \ ADMIN \ anaconda3 \ envs \ myenv \ lib \ site-packages \ keras \ engine \ base_layer.py”,行1179 返回cls(** config)
文件“ C:\ Users \ ADMIN \ anaconda3 \ envs \ myenv \ lib \ site-packages \ keras \ legacy \ interfaces.py”,包装中的第91行 返回func(* args,** kwargs)
TypeError: init ()得到了意外的关键字参数“参差不齐”