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
Conversation
The order of the arguments of the RetinaFace.extract_faces function is wrong and changed.
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. |
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 alignment_procedure function in postprocess.py 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 databeforeexecution 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() afterexecution 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() |
So, unit tests show that as is approach is totally fine. i am closing this PR. |
When calling the postprocess.alignment_procedure function within the RetinaFace.extract_faces function, the order of the arguments is incorrect and changed.