Page 1 of 1

How to remove the padding from the extracted faces

Posted: Fri Nov 19, 2021 2:26 pm
by soso4

I want to remove the padding from the extracted faces, so that the result will be just the face without any padding, For example this is the image resulting from the extraction:

I need it to be:

The reason for that is that I want to use the resulting extracted face in face recognition using another software that requires the images to be cropped exactly around the face.


Re: How to remove the padding from the extracted faces

Posted: Fri Nov 19, 2021 2:53 pm
by torzdf

You will only be able to do this by editing the code. I'm not going to go into detail about what you have to do, but will point you in the direction of where you need to look.

The code which controls the padding around the face is here:
https://github.com/torzdf/faceswap/blob ... ce.py#L119
Specifically the coverage_ratio parameter controls the amount of padding to add

The extract script does not call this directly, rather it calls the load_aligned function from here:
https://github.com/torzdf/faceswap/blob ... ct.py#L254
Most likely just editing the centering here to legacy will get you what you want (or close).

If you do have to further edit the coverage, then you can edit it in the load_aligned function here:
https://github.com/torzdf/faceswap/blob ... ce.py#L315


Re: How to remove the padding from the extracted faces

Posted: Fri Nov 19, 2021 9:46 pm
by soso4

Hi [mention]torzdf[/mention] ,
Thanks a lot for your help :)

This works perfectly:

Most likely just editing the centering here to legacy will get you what you want


Re: How to remove the padding from the extracted faces

Posted: Sat Dec 18, 2021 3:29 pm
by soso4

Hi,
Another issue appeared after setting the centering to "legacy" in this line:
https://github.com/torzdf/faceswap/blob ... ct.py#L254

The issue is that the "Sort" tool is not working properly with the faces which are without padding; it mixes faces of different identities.
If I put back the centering to "head" (that results in faces with padding) and run the "Sort" on the padded faces it works properly.
Could you please help me? I want to both crop the faces to be without padding, and then sort them.


Re: How to remove the padding from the extracted faces

Posted: Sat Dec 18, 2021 7:25 pm
by bryanlyon

This chain of questions sounds like an XY problem ( https://en.wikipedia.org/wiki/XY_problem ). Why don't you ask us for help with what you're actually attempting to do.

If you're just trying to modify the extract process of Faceswap for other extract needs, you're going to have to modify everything yourself. We just don't have time to provide support for modification of the project for other uses.