serengil / deepface

A Lightweight Face Recognition and Facial Attribute Analysis (Age, Gender, Emotion and Race) Library for Python
https://www.youtube.com/watch?v=WnUVYQP4h44&list=PLsS_1RYmYQQFdWqxQggXHynP1rqaYXv_E&index=1
MIT License
10.95k stars 1.92k forks source link

AttributeError: 'NoneType' object has no attribute 'xy' #1077

Closed freedom9393 closed 4 months ago

freedom9393 commented 4 months ago

Simply, what I'm trying to run is this:

from deepface import DeepFace

result = DeepFace.verify(model_name='VGG-Face', detector_backend='yolov8', img1_path=img1, img2_path=img2)

and I'm facing this error:

AttributeError: 'NoneType' object has no attribute 'xy'

Why is it happening and how to solve it?

serengil commented 4 months ago

Can you share input image? Seems like a bug.

freedom9393 commented 4 months ago

I sent it via email

serengil commented 4 months ago

interesting, I can run the verify function with the faces you provided

{'verified': True,
 'distance': 1.1102230246251565e-16,
 'threshold': 0.68,
 'model': 'VGG-Face',
 'detector_backend': 'yolov8',
 'similarity_metric': 'cosine',
 'facial_areas': {'img1': {'x': 106,
   'y': 179,
   'w': 194,
   'h': 265,
   'left_eye': (159, 294),
   'right_eye': (242, 296)},
  'img2': {'x': 106,
   'y': 179,
   'w': 194,
   'h': 265,
   'left_eye': (159, 294),
   'right_eye': (242, 296)}},
 'time': 8.53}
serengil commented 4 months ago

Would you please print the result of this:

from deepface import DeepFace
print(DeepFace.__version__)
freedom9393 commented 4 months ago

When I test those images, I see this error:

ValueError: Face could not be detected in /home/real/Projects/0148e568a63e407f86476d8396d68796_1.jpg.Please confirm that the picture is a face photo or consider to set enforce_detection param to False.

serengil commented 4 months ago

I tested it with pair you just send again. Still, I can get a response.

{'verified': True,
 'distance': 0.33096834352615234,
 'threshold': 0.68,
 'model': 'VGG-Face',
 'detector_backend': 'yolov8',
 'similarity_metric': 'cosine',
 'facial_areas': {'img1': {'x': 163,
   'y': 172,
   'w': 162,
   'h': 202,
   'left_eye': (207, 256),
   'right_eye': (277, 259)},
  'img2': {'x': 106,
   'y': 236,
   'w': 179,
   'h': 217,
   'left_eye': (156, 318),
   'right_eye': (234, 323)}},
 'time': 2.37}

But you mentioned a different exception message. Which one is you getting?

AttributeError: 'NoneType' object has no attribute 'xy'

or

ValueError: Face could not be detected in /home/real/Projects/0148e568a63e407f86476d8396d68796_1.jpg.Please confirm that the picture is a face photo or consider to set enforce_detection param to False.

serengil commented 4 months ago

If you are still getting AttributeError: 'NoneType' object has no attribute 'xy' error, then I just added keypoints check control in the yolo wrapper: https://github.com/serengil/deepface/blob/master/deepface/detectors/Yolo.py#L84 (not published in pip yet, you should use the source code as described in the read me).

On the other hand, if you are getting Face could not be detected error, then that is totally different. Consider to set enforce_detection arg to False.