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

Fix missing normalization when skipping face detection #889

Merged
merged 1 commit into from
Nov 22, 2023

Conversation

ndido98
Copy link
Contributor

@ndido98 ndido98 commented Nov 15, 2023

When using the DeepFace.represent function where detector_backend=skip, the image is not properly normalized.
In particular, digging around the repo I found that this bug was introduced in 8f667ee: the line that divides the image's pixels by 255 is moved inside functions.extract_faces, which is skipped with the above mentioned keyword argument.

Therefore, the model's input image (in particular, I tried with ArcFace) has a distribution which is significantly different than the one used in training; as a consequence, the model has a significantly lower performance than advertised when tested on LFW (~64.5% with cosine distance).
On the contrary, when the image is manually normalized in the [0, 1] range, this accuracy is around ~91%.
I used DeepFace 0.0.79.

While waiting for this PR to be merged, I suggest anyone in the same situation to manually normalize your images converting them from BGR to RGB and manually normalizing them so that the pixels' range is [0, 1].

rgb_image = cv2.cvtColor(bgr_image, cv2.COLOR_BGR2RGB).astype(np.float32)
rgb_image = rgb_image / 255
embedding = DeepFace.represent(img_path=rgb_image, model_name="ArcFace", detector_backend="skip")[0]["embedding"]

@serengil serengil merged commit 3fb8ac7 into serengil:master Nov 22, 2023
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