AttributeError: 'NoneType' object has no attribute 'xy' (YOLOV8 | Deepface)

138 Views Asked by At

I'm running deepface model for face recognition and chose YOLOV8 for detecting face. Here is the code I'm running:

from deepface import DeepFace

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

So, when I run the code, I'm seeing this error message:

left_eye = result.keypoints.xy[0][0], result.keypoints.conf[0][0]

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

I'm assuming that YOLOV8 is detecting face but can't detect keypoints for left/right eyes. I tested it with around 10 images but still failing.

What am I doing wrong? How to solve this problem?

1

There are 1 best solutions below

0
Scott On

The author made modification in deepface and now it's working fine (probably not in pip yet). The change was in Yolo.py in lines 76-78. See github issue here

Changed from:

for result in results:
    # Extract the bounding box and the confidence
    x, y, w, h = result.boxes.xywh.tolist()[0]
    confidence = result.boxes.conf.tolist()[0]

to:

for result in results:

    if result.boxes is None or result.keypoints is None:
        continue

    # Extract the bounding box and the confidence
    x, y, w, h = result.boxes.xywh.tolist()[0]
    confidence = result.boxes.conf.tolist()[0]