mike9251 / simswap-inference-pytorch

Unofficial Pytorch implementation (inference only) of the SimSwap: An Efficient Framework For High Fidelity Face Swapping
93 stars 20 forks source link

I'm having a problem with overlapping faces. #21

Open mbeytekin opened 1 year ago

mbeytekin commented 1 year ago

swap_family-of-four-7101-a234e9249b2c7223d4e4d8cd9432f9e9@1x

I guess to fix this I have to merge all the found faces separately. Can you help with this?

By the way, the app already finds softmasks of faces. After all, isn't it better to use them when merging faces into the picture?

mbeytekin commented 1 year ago

I made some changes in simswap.py and got better results: soft_facemask, = self.smooth_mask(face_mask) img_white=soft_face_mask*255.

Only take face area from the swapped image

     swapped_img = swapped_img * soft_face_mask

swap_1280px-Happy_family_(1)

However, in some cases, overlaps can occur. swap_family-of-four-7101-a234e9249b2c7223d4e4d8cd9432f9e9@1x

swap_happy-families-couple700x400

mike9251 commented 1 year ago

Hey @mbeytekin , you can blend faces separately. At the end of the simswap.py file do not sum img_mask and target_image, instead blend each crop independently.

I think a better solution would be computing intersection between crops and compensating it during the blend step. I'll take a look later.

mike9251 commented 1 year ago

Fixed the issue with the latest update

before

swap_before

After swap_fix