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

change the order of arguments #46

Closed
wants to merge 1 commit into from

Conversation

glucose6126
Copy link

When calling the postprocess.alignment_procedure function within the RetinaFace.extract_faces function, the order of the arguments is incorrect and changed.

The order of the arguments of the RetinaFace.extract_faces function is wrong and changed.
@serengil
Copy link
Owner

serengil commented Oct 14, 2022

can you monitor the results with this change?

I mean that maybe we need to rename the variables instead of changing order. This might cause problems in alignment.

@glucose6126
Copy link
Author

glucose6126 commented Oct 14, 2022

The variable name is set appropriately, but the argument order of alignment_procedure function and the argument order of extract_faces function in RetinaFace are different from each other.

extract_faces function in RetinaFace.py
facial_img = postprocess.alignment_procedure(facial_img, right_eye, left_eye, nose)

alignment_procedure function in postprocess.py
def alignment_procedure(img, left_eye, right_eye, nose):

Therefore, I changed the argument order when calling the alignment_procedure function in extract_faces, and the execution code and function execution result to check the result before and after the change are as follows.

original data

image

before

execution code

from retinaface import RetinaFace
from retinaface.RetinaFace import *
from retinaface.commons import postprocess
import matplotlib.pyplot as plt
import cv2
import numpy as np

def extract_faces(img_path, threshold=0.9, model = None, align = True, allow_upscaling = True):

    resp = []

    #---------------------------

    img = get_image(img_path)

    #---------------------------

    obj = detect_faces(img_path = img, threshold = threshold, model = model, allow_upscaling = allow_upscaling)
    if type(obj) == dict:
        for key in obj:
            identity = obj[key]

            facial_area = identity["facial_area"]
            facial_img = img[facial_area[1]: facial_area[3], facial_area[0]: facial_area[2]]

            if align == True:
                landmarks = identity["landmarks"]
                left_eye = landmarks["left_eye"]
                right_eye = landmarks["right_eye"]
                nose = landmarks["nose"]
                mouth_right = landmarks["mouth_right"]
                mouth_left = landmarks["mouth_left"]

                facial_img = postprocess.alignment_procedure(facial_img, right_eye, left_eye, nose)

            resp.append(facial_img[:, :, ::-1])
    #elif type(obj) == tuple:

    return resp

img = RetinaFace.get_image("./lenna.jpg")
plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
plt.title('Original')
plt.axis("off")
plt.show()

for face in extract_faces(img) :
    plt.imshow(face)
    plt.title('extract face before code fix')
    plt.axis("off")
    plt.show()

Execution result
image

after

execution code

from retinaface import RetinaFace
from retinaface.RetinaFace import *
from retinaface.commons import postprocess
import matplotlib.pyplot as plt
import cv2
import numpy as np

def extract_faces(img_path, threshold=0.9, model = None, align = True, allow_upscaling = True):

    resp = []

    #---------------------------

    img = get_image(img_path)

    #---------------------------

    obj = detect_faces(img_path = img, threshold = threshold, model = model, allow_upscaling = allow_upscaling)
    if type(obj) == dict:
        for key in obj:
            identity = obj[key]

            facial_area = identity["facial_area"]
            facial_img = img[facial_area[1]: facial_area[3], facial_area[0]: facial_area[2]]

            if align == True:
                landmarks = identity["landmarks"]
                left_eye = landmarks["left_eye"]
                right_eye = landmarks["right_eye"]
                nose = landmarks["nose"]
                mouth_right = landmarks["mouth_right"]
                mouth_left = landmarks["mouth_left"]

                facial_img = postprocess.alignment_procedure(facial_img, left_eye, right_eye, nose)

            resp.append(facial_img[:, :, ::-1])
    #elif type(obj) == tuple:

    return resp

img = RetinaFace.get_image("./lenna.jpg")
plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
plt.title('Original')
plt.axis("off")
plt.show()

for face in extract_faces(img) :
    plt.imshow(face)
    plt.title('extract face after code fix')
    plt.axis("off")
    plt.show()

execution result
image

@serengil
Copy link
Owner

If you run unit tests, you will see your approach is not working

Before:

before

After your change:

after

@serengil
Copy link
Owner

So, unit tests show that as is approach is totally fine. i am closing this PR.

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.

None yet

2 participants