Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent no attribute error when using Mtcnn #976

Merged
merged 1 commit into from
Jan 27, 2024

Conversation

MattPChoy
Copy link
Contributor

What has been done

When running this code with an image with no faces, a TypeError was encountered. Using short-circuit evaluation a condition was added to prevent this exception from occurring again.

Traceback (most recent call last):
  File "XXXXXXX.py", line 65, in find_face
    enforce_detection=enforce_detection)
  File "/home/YYYYYY/anaconda3/envs/facedetection/lib/python3.7/site-packages/deepface/DeepFace.py", line 451, in extract_faces
    grayscale=grayscale,
  File "/home/YYYYYY/anaconda3/envs/facedetection/lib/python3.7/site-packages/deepface/modules/detection.py", line 57, in extract_faces
    align=align,
  File "/home/YYYYYY/anaconda3/envs/facedetection/lib/python3.7/site-packages/deepface/commons/functions.py", line 178, in extract_faces
    face_objs = DetectorWrapper.detect_faces(detector_backend, img, align)
  File "/home/YYYYYY/anaconda3/envs/facedetection/lib/python3.7/site-packages/deepface/detectors/DetectorWrapper.py", line 78, in detect_faces
    return face_detector.detect_faces(img=img, align=align)
  File "/home/YYYYYY/anaconda3/envs/facedetection/lib/python3.7/site-packages/deepface/detectors/FastMtCnn.py", line 47, in detect_faces
    if len(detections[0]) > 0:
TypeError: object of type 'NoneType' has no len()

How to test

make lint && make test

@serengil
Copy link
Owner

Good point! Thank you for your contribution.

@serengil serengil merged commit 13f33de into serengil:master Jan 27, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants