Skip to content

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

Merged
serengil merged 7 commits intoserengil:masterfrom
UmutDeniz26:master
Feb 10, 2024
Merged

Two-fold Performance Enhancement by Optimizing Face Extraction Function When align_first == True#80
serengil merged 7 commits intoserengil:masterfrom
UmutDeniz26:master

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.

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(
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.


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


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

2 participants

Comments