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

Two-fold Performance Enhancement by Optimizing Face Extraction Function When align_first == True #80

Merged
merged 7 commits into from
Feb 10, 2024

Conversation

UmutDeniz26
Copy link
Contributor

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.


if align_first is True and len(obj) == 1:
facial_img = extract_faces(
Copy link
Contributor Author

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.

resp.append(facial_img[:, :, ::-1])

return resp

def rotateFacialArea(facialArea, angle, direction, size):
Copy link
Owner

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

resp.append(facial_img[:, :, ::-1])

return resp

def rotateFacialArea(facialArea, angle, direction, size):
Copy link
Owner

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

y = (facialArea[1] + facialArea[3]) / 2 - size[0] / 2

# Rotate the facial area
xNew = x * np.cos(angle) + y * direction * np.sin(angle)
Copy link
Owner

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.

@serengil
Copy link
Owner

Linting failed - https://github.com/serengil/retinaface/actions/runs/7857063255/job/21440536002?pr=80

# 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))
Copy link
Owner

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)
)

Copy link
Contributor Author

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?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, that also works

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))
Copy link
Owner

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

Rotate the facial area around its center.

Args:
facial_area (tuple of int): Representing the coordinates (x1, y1, x2, y2) of the facial area.
Copy link
Owner

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry again.

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] +
Copy link
Owner

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)

@serengil
Copy link
Owner

LGTM, thank you for your contribution

@serengil serengil merged commit adfa54b into serengil:master Feb 10, 2024
2 checks passed
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