frankenstein
frankenstein

Reputation: 125

TypeError: __init__() got an unexpected keyword argument 'ragged'? when load model

I'm using keras to load the model which stored in h5 file, but got this error, I tried to google around but got no result.

please help.

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()

error like this :

File "C:\Users\ADMIN\anaconda3\envs\myenv\lib\site-packages\keras\utils\generic_utils.py", line 147, in deserialize_keras_object list(custom_objects.items())))

File "C:\Users\ADMIN\anaconda3\envs\myenv\lib\site-packages\keras\engine\sequential.py", line 301, in from_config custom_objects=custom_objects)

File "C:\Users\ADMIN\anaconda3\envs\myenv\lib\site-packages\keras\layers_init_.py", line 168, in deserialize printable_module_name='layer')

File "C:\Users\ADMIN\anaconda3\envs\myenv\lib\site-packages\keras\utils\generic_utils.py", line 149, in deserialize_keras_object return cls.from_config(config['config'])

File "C:\Users\ADMIN\anaconda3\envs\myenv\lib\site-packages\keras\engine\base_layer.py", line 1179, in from_config return cls(**config)

File "C:\Users\ADMIN\anaconda3\envs\myenv\lib\site-packages\keras\legacy\interfaces.py", line 91, in wrapper return func(*args, **kwargs)

TypeError: init() got an unexpected keyword argument 'ragged'

Upvotes: 0

Views: 1193

Answers (1)

user11530462
user11530462

Reputation:

Instead of importing load_model from keras ,Import it from tf.keras

from tf.keras.models import load_model
classifier = load_model('facial_expression.h5')

Upvotes: 0

Related Questions