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
14.34k stars 2.2k forks source link

Type error raised when using Retinaface detector #328

Closed yvs997 closed 3 years ago

yvs997 commented 3 years ago

I using face detection module using mtcnn but the result not too satisfied compare with retinaface. But when i try to do this, i get TypeError: alignment_procedure() takes 3 positional arguments but 4 were given. My image store on web so i using curl to load it

This is my code:

...
def searchOnline(fpath, fname):
    url = "https://url"
    req_body = {"filename": fname, "folder": fpath}
    print(req_body)
    post_request = requests.post(url, req_body)
    try:
        post_request_result = post_request.json()
        images_link = post_request_result['result']
        image_data = requests.get(images_link).content
        images = np.frombuffer(image_data, np.uint8)
        images = cv2.imdecode(images, cv2.IMREAD_COLOR)
        plt.figure()
        plt.imshow(images)
        plt.show()
        return images
    except Exception(Exception,FileNotFoundError) as err:
        print(err)
    finally:
        status.HTTP_200_OK
...
image = searchOnline(path[0],file[0])
face = face_recon(image)
...
def face_recon(image):
    try:
        detectedFace = deepface.DeepFace.detectFace(img_path=image, detector_backend='retinaface', enforce_detection=True,
                                            align=True)
        plt.figure()
        plt.imshow(detectedFace)
        plt.show()
        return detectedFace
    except ValueError:
        print("No Face Found")
        status.HTTP_400_BAD_REQUEST
    finally:
        status.HTTP_200_OK
...
serengil commented 3 years ago

please update your retina-face package.

yvs997 commented 3 years ago

i have update my retina-face package but it still give me the same error when i check my retina-face version it gives me this: retina-face 0.0.4 and deepface version: deepface 0.0.67

yvs997 commented 3 years ago

and this is the trace of the issue:

  File "D:\<path>\utils.py", line 234, in face_recon
    detectedFace = DeepFace.detectFace(img_path=image, detector_backend='retinaface')
  File "C:\ProgramData\Anaconda3\lib\site-packages\deepface\DeepFace.py", line 813, in detectFace
    img = functions.preprocess_face(img = img_path, detector_backend = detector_backend
  File "C:\ProgramData\Anaconda3\lib\site-packages\deepface\commons\functions.py", line 159, in preprocess_face
    img, region = detect_face(img = img, detector_backend = detector_backend, grayscale = grayscale, enforce_detection = enforce_detection, align = align)
  File "C:\ProgramData\Anaconda3\lib\site-packages\deepface\commons\functions.py", line 96, in detect_face
    detected_face, img_region = FaceDetector.detect_face(face_detector, detector_backend, img, align)
  File "C:\ProgramData\Anaconda3\lib\site-packages\deepface\detectors\FaceDetector.py", line 36, in detect_face
    obj = detect_faces(face_detector, detector_backend, img, align)
  File "C:\ProgramData\Anaconda3\lib\site-packages\deepface\detectors\FaceDetector.py", line 59, in detect_faces
    obj = detect_face(face_detector, img, align)
  File "C:\ProgramData\Anaconda3\lib\site-packages\deepface\detectors\RetinaFaceWrapper.py", line 58, in detect_face
    detected_face = postprocess.alignment_procedure(detected_face, right_eye, left_eye, nose)
TypeError: alignment_procedure() takes 3 positional arguments but 4 were given

this is only happen to retinaface, with other model like mtcnn or blank (default opencv), it not show like this

serengil commented 3 years ago

your retina-face version is old. its latest version is 0.0.5:

https://pypi.org/project/retina-face/

https://pypi.org/project/retina-face/0.0.5/