-
-
Notifications
You must be signed in to change notification settings - Fork 163
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
Two-fold Performance Enhancement by Optimizing Face Extraction Function When align_first == True #80
Conversation
|
||
if align_first is True and len(obj) == 1: | ||
facial_img = extract_faces( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing the recursive algorithm will enhance performance twice.
retinaface/RetinaFace.py
Outdated
resp.append(facial_img[:, :, ::-1]) | ||
|
||
return resp | ||
|
||
def rotateFacialArea(facialArea, angle, direction, size): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function names should follow snake case instead of camel case
retinaface/RetinaFace.py
Outdated
resp.append(facial_img[:, :, ::-1]) | ||
|
||
return resp | ||
|
||
def rotateFacialArea(facialArea, angle, direction, size): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, that also works
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
linting fails because line is too long. consider to continue the text in the next line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry again.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.