Face alignment with rotation using resample #1269
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
If you set the face
alignment
parameter toTrue
, you can see pixel artefacts when you rotate the face horizontally over the eyes when working with faces of smaller dimensions.Original Image
Face alignment
You can easily notice the changed pixels after rotation.
Rotate with
resample=Image.BICUBIC
This PR adds a
resample=Image.BICUBIC
parameter to the align_face function, which smooths the changed pixels after face alignment.What does it improve?
Firstly, there are now better facial images after calling
DeepFace.extract_faces()
I initially had a theory that these deformed pixels are passed to the models to turn the face into vectors and thus affect the result for the worse.
I compared the two photos through all algorithms to see if smoothing via
resample=Image.BICUBIC
helps or not.Code
Each check was first run without
Image.BICUBIC
, then a second check with the same models was run withImage.BICUBIC
The entire report is at the link: https://docs.google.com/spreadsheets/d/1BPWT7bqz60QHu5y2Zx7Dhx0Kty4o_FDrVtf0vZYaTOw/edit?usp=sharing
Conclusions
This change affects faces from low resolution images. In large images - deformed pixels are not noticeable after rotation.
From the Excel report in the link above, it is noticeable that on the green background the percentage of difference is much higher than 12-19%. That is 12-19% improvement in the validation result between the two faces.
At the same time there is also a red background, but there the percentage of deterioration of the result is much lower.