Two-fold Performance Enhancement by Optimizing Face Extraction Function When align_first == True#80
Conversation
| facial_img, rotate_angle, rotation_direction = postprocess.alignment_procedure(facial_img, right_eye, left_eye, nose) | ||
|
|
||
| if align_first is True and len(obj) == 1: | ||
| facial_img = extract_faces( |
There was a problem hiding this comment.
Removing the recursive algorithm will enhance performance twice.
retinaface/RetinaFace.py
Outdated
|
|
||
| return resp | ||
|
|
||
| def rotateFacialArea(facialArea, angle, direction, size): |
There was a problem hiding this comment.
function names should follow snake case instead of camel case
retinaface/RetinaFace.py
Outdated
|
|
||
| return resp | ||
|
|
||
| def rotateFacialArea(facialArea, angle, direction, size): |
There was a problem hiding this comment.
type hintings for input arguments and function's return type are missing
retinaface/RetinaFace.py
Outdated
| y = (facialArea[1] + facialArea[3]) / 2 - size[0] / 2 | ||
|
|
||
| # Rotate the facial area | ||
| xNew = x * np.cos(angle) + y * direction * np.sin(angle) |
There was a problem hiding this comment.
variable names should follow snake case formatting, too.
… (missing-final-newline)
retinaface/RetinaFace.py
Outdated
| # expand the facial area to be extracted and stay within img.shape limits | ||
| x1 = max(0, facial_area[0] - int((facial_area[2] * expand_face_area) / 100)) | ||
| y1 = max(0, facial_area[1] - int((facial_area[3] * expand_face_area) / 100)) | ||
| x2 = min(img.shape[1], facial_area[2] + int((facial_area[2] * expand_face_area) / 100)) |
There was a problem hiding this comment.
linting fails because this line is too long - https://github.com/serengil/retinaface/actions/runs/7857276051/job/21441019715?pr=80
you may consider to make it shorter as
x2 = min(
img.shape[1], facial_area[2] + int((facial_area[2] * expand_face_area) / 100)
)There was a problem hiding this comment.
I just updated the line as follows:
x2 = min(img.shape[1], facial_area[2] +
int((facial_area[2] * expand_face_area) / 100))
Should i change again?
retinaface/RetinaFace.py
Outdated
| x1 = max(0, facial_area[0] - int((facial_area[2] * expand_face_area) / 100)) | ||
| y1 = max(0, facial_area[1] - int((facial_area[3] * expand_face_area) / 100)) | ||
| x2 = min(img.shape[1], facial_area[2] + int((facial_area[2] * expand_face_area) / 100)) | ||
| y2 = min(img.shape[0], facial_area[3] + int((facial_area[3] * expand_face_area) / 100)) |
There was a problem hiding this comment.
similarly, linting fails because line is too long
retinaface/RetinaFace.py
Outdated
| Rotate the facial area around its center. | ||
|
|
||
| Args: | ||
| facial_area (tuple of int): Representing the coordinates (x1, y1, x2, y2) of the facial area. |
There was a problem hiding this comment.
linting fails because line is too long. consider to continue the text in the next line.
retinaface/RetinaFace.py
Outdated
| y1 = max(0, facial_area[1] - int((facial_area[3] * expand_face_area) / 100)) | ||
| x2 = min(img.shape[1], facial_area[2] + | ||
| int((facial_area[2] * expand_face_area) / 100)) | ||
| y2 = min(img.shape[0], facial_area[3] + |
There was a problem hiding this comment.
retinaface/RetinaFace.py:286:55: C0303: Trailing whitespace (trailing-whitespace)
|
LGTM, thank you for your contribution |
Removing the recursive algorithm doubles our performance gains. Also, by recalculating the facial area without reliance on the detect_faces function, we avoid using it twice, resulting in further efficiency.