i would like to use deepface algorithm for detection human's emotion from the image, here is my code :
import cv2
from deepface import DeepFace
import numpy as np
import json
image =cv2.imread('emotion.jpg')
#json.dumps(image)
analyze =DeepFace.analyze(image,actions='emotions',enforce_detection=False)
print(analyze)
but when i have run the code, got the following error
C:\Users\User\PycharmProjects\AI_Project\venv\Scripts\python.exe C:\Users\User\PycharmProjects\AI_Project\emotion_detection.py
Action: e: 0%| | 0/8 [00:00<?, ?it/s]
Traceback (most recent call last):
File "C:\Users\User\PycharmProjects\AI_Project\emotion_detection.py", line 7, in <module>
analyze =DeepFace.analyze(image,actions=('emotions'),enforce_detection=False)
File "C:\Users\User\PycharmProjects\AI_Project\venv\lib\site-packages\deepface\DeepFace.py", line 452, in analyze
resp_obj["region"][parameter] = int(region[i]) #int cast is for the exception - object of type 'float32' is not JSON serializable
IndexError: list index out of range
Process finished with exit code 1
i have searched a lot about this problem, for instance try the following code
json.dumps(image)
but when i run, got :
TypeError: Object of type ndarray is not JSON serializable
please tell me is there any solution? or it is just deepface's bug?
you have to pass the image directly. No need to read with opencv & then pass to Deepface.analyze. Read documentaion clearly.
backends = ['opencv', 'ssd', 'dlib', 'mtcnn', 'retinaface', 'mediapipe']
analyze = DeepFace.analyze(img_path = 'emotion.jpg', detector_backend =backends[4])
print(analyze)