Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

DeepFace analyze function rises serialization issue

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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?

>Solution :

you have to give 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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading