How to remove the padding from the extracted faces

The Extraction process failing on you, and you aren't getting an error back with clear instructions? Tell us about it here


Forum rules

Read the FAQs and search the forum before posting a new topic.

This forum is for reporting errors with the Extraction process. If you want to get tips, or better understand the Extract process, then you should look in the Extract Discussion forum.

Please mark any answers that fixed your problems so others can find the solutions.

Locked
User avatar
soso4
Posts: 3
Joined: Fri Nov 19, 2021 1:54 pm

How to remove the padding from the extracted faces

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

User avatar
torzdf
Posts: 2651
Joined: Fri Jul 12, 2019 12:53 am
Answers: 159
Has thanked: 129 times
Been thanked: 622 times

Re: How to remove the padding from the extracted faces

Post 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

My word is final

User avatar
soso4
Posts: 3
Joined: Fri Nov 19, 2021 1:54 pm

Re: How to remove the padding from the extracted faces

Post 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

User avatar
soso4
Posts: 3
Joined: Fri Nov 19, 2021 1:54 pm

Re: How to remove the padding from the extracted faces

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

User avatar
bryanlyon
Site Admin
Posts: 793
Joined: Fri Jul 12, 2019 12:49 am
Answers: 44
Location: San Francisco
Has thanked: 4 times
Been thanked: 218 times
Contact:

Re: How to remove the padding from the extracted faces

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

Locked