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

[FEATURE]: Performance Impact of Image.BICUBIC Resampling in Face Alignment #1378

Closed
matluuk opened this issue Oct 28, 2024 · 4 comments
Closed
Labels
enhancement New feature or request

Comments

@matluuk
Copy link

matluuk commented Oct 28, 2024

Description

In pull request #1269, the face alignment method was changed to use Image.BICUBIC resampling. While this change may improve image quality, it significantly impacts performance.

Performance Testing

I tested the performance impact by running the ´DeepFace.represent´ function with timeit for 100 rounds. The “yunet” detector and “SFace” face recognition model were used.

from deepface import DeepFace
from deepface.models.FacialRecognition import FacialRecognition

import cv2
import timeit

# Read the image
img = cv2.imread('absolute/path/to/image.jpg')

model_name = "SFace"

model = DeepFace.build_model(model_name=model_name)

execution_time = timeit.timeit('DeepFace.represent(img_path=img, model_name=model_name, detector_backend="yunet")', globals=globals(), number=100)
print(f"Execution time: {execution_time} seconds")

Results

  • without Image.BICUBIC resampling:
    Execution time: 7.931031430998701 seconds
    with Image.BICUBIC resampling:
    Execution time: 41.79532476099848 seconds

Suggestion

Since the alignment method has no impact on the face recognition performance, it would be beneficial to make the resampling method configurable. This way, users can choose whether to use Image.BICUBIC resampling based on their performance needs.

Environment Details

  • DeepFace version: 0.0.92
  • Python version: 3.10.12
  • Operating System: Ubuntu 24.04
  • CPU: i7 4770

Additional Info

No response

@matluuk matluuk added the enhancement New feature or request label Oct 28, 2024
@serengil
Copy link
Owner

serengil commented Oct 28, 2024

The sentence Since the alignment method has no impact on the face recognition performance is totally false. As you can confirm from here, alignment increases facial recognition pipeline's accuracy up to 6%.

If you still insist to skip alignment, you already have an option in the input argument. If you set align to False in any function, then this is going to skip alignment as mentioned here. Similarly, you can skip detection as well while setting detector_backend argument to skip as mentioned here.

@serengil serengil closed this as not planned Won't fix, can't repro, duplicate, stale Oct 28, 2024
@serengil serengil added the invalid This doesn't seem right label Oct 28, 2024
@matluuk
Copy link
Author

matluuk commented Oct 28, 2024

I could have described the suggestion better. I am using alignment in both situations that I measured.

The with the sentence Since the alignment method has no impact on the face recognition performance was badly shaped. I tried to refer to comment #1269 (comment) that expressed that the usage of ´Image.BICUBIC´ resampling doesn't affect the face recognition performance. Thus it would not matter from face recognition perspective if we are using
img = np.array(Image.fromarray(img).rotate(angle))
or
img = np.array(Image.fromarray(img).rotate(angle, resample=Image.BICUBIC)) . Changing the image rotation to the latter has significant performance impact I measured with timeit.

To clarifying further: Both timeit measurements were done with alingment enabled. Faster run (7.931031430998701 seconds) was done with the old image rotation that doesn't use ´Image.BICUBIC´ resampling. The slower run (41.79532476099848 seconds) was done with newer image rotation that uses ´Image.BICUBIC´ resampling.

@serengil serengil removed the invalid This doesn't seem right label Oct 28, 2024
@serengil
Copy link
Owner

Okay, I could understand it now.

Your request is fair enough. Thank you for the explanation.

@serengil serengil reopened this Oct 28, 2024
@serengil
Copy link
Owner

In the current source code, this seems retired already - https://github.com/serengil/deepface/blob/master/deepface/modules/detection.py#L346

@serengil serengil closed this as not planned Won't fix, can't repro, duplicate, stale Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants