zyainfal / One-Shot-Face-Swapping-on-Megapixels

One Shot Face Swapping on Megapixels.
Other
312 stars 41 forks source link

How can i swap faces between two images? #26

Open alan-ai-learner opened 2 years ago

alan-ai-learner commented 2 years ago

I have two images and i want to swap the face from one image to another. Any suggestion would be great? thanks

zyainfal commented 2 years ago

You need to get face segmentations at the first step, please refer to this for details. Then you can swap the two faces by giving the path to the inference code, or you can read images by cv2.imread() directly.

alan-ai-learner commented 2 years ago

Hi, thankyou so much for replying, i tried the way you said, but there is a bug in the inference.py file, op module is not found , I tried to downgrade the pytorch but the version 1.3 is not found that you used.any help would be appreciated. Thanks

On Mon, 22 Nov 2021 at 10:45, Yuhao @.***> wrote:

You need to get face segmentations at the first step, please refer to this https://github.com/zllrunning/face-parsing.PyTorch for details. Then you can swap the two faces by giving the path to the inference code, or you can read images by cv2.imread() directly.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/zyainfal/One-Shot-Face-Swapping-on-Megapixels/issues/26#issuecomment-975135171, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMZS64D6TZMCDJJ7W6UYFZDUNHGVRANCNFSM5IGLXPQA .

zyainfal commented 2 years ago

op module is from StyleGAN2. Please refer to stylegan2-pytorch for details. (and please take care of CUDA version, it is crucial to compile op modules)

alan-ai-learner commented 2 years ago

Thanks, I've managed to solved it, but I'm facing this new error, what is exactly and source and target id, I'm trying to replace whole face here, not an particular face attribute. err

zyainfal commented 2 years ago

I assume you give the image name to args. However, this inference.py is coded for CelebA-HQ, where srcID and tgtID are the image indexes. So in your case, you can read images and their segmentations by cv.imread() directly to src_face, tgt_face, and tgt_mask.

alan-ai-learner commented 2 years ago

ok, thanks, will this image swapping works on the images like a profile pictures, like in the Celeb HQ, the images are mainly containg the faces of the celebrities, and i want to swap faces of an image which is like this whole_img

zyainfal commented 2 years ago

For this kind of image, you need to detect and align the face according to the CelebA-HQ paper (or simply by RetinaFace). Then, you can swap them if everything goes well.

alan-ai-learner commented 2 years ago

You need to get face segmentations at the first step, please refer to this for details. Then you can swap the two faces by giving the path to the inference code, or you can read images by cv2.imread() directly.

here i've to find the segmentation of target image or the source images. getting the following result source Img: 000109 Source IMg Segmentation: 000109

Target IMg: 000735 Output Img: 45721bd4-aeca-4191-b0fc-8d717b6d1c3f

zyainfal commented 2 years ago

The target segmentation.

alan-ai-learner commented 2 years ago

For this kind of image, you need to detect and align the face according to the CelebA-HQ paper (or simply by RetinaFace). Then, you can swap them if everything goes well.

Can you suggest some repo that were doing it, that will be great help. Thanks

alan-ai-learner commented 2 years ago

The target segmentation. Again the same, ftm

zyainfal commented 2 years ago

You may make mistake of the target segmentation, it should have values from 0 to 17 (the semantic index), not RGB values. Just like in https://github.com/zllrunning/face-parsing.PyTorch/blob/master/evaluate.py line 39, save vis_parsing_anno as segmentaion image.

alan-ai-learner commented 2 years ago

You may make mistake of the target segmentation, it should have values from 0 to 17 (the semantic index), not RGB values. Just like in https://github.com/zllrunning/face-parsing.PyTorch/blob/master/evaluate.py line 39, save it as segmentaion image.

yeah, i need to use the png segementation, getting this after, seem not realistic ftm (1)

zyainfal commented 2 years ago

Well, this is the result. You can try injection model to check which is better.

alan-ai-learner commented 2 years ago

For this kind of image, you need to detect and align the face according to the CelebA-HQ paper (or simply by RetinaFace). Then, you can swap them if everything goes well.

Can you suggest some repo that were doing it, that will be great help. Thanks

Okay any suggeston on this

zyainfal commented 2 years ago

A simple practice is to use RetinaFace to detect and align the face. RetinaFace: https://github.com/deepinsight/insightface/tree/master/detection/retinaface Align functioin: https://github.com/deepinsight/insightface/blob/ce3600a74209808017deaf73c036759b96a44ccb/recognition/arcface_mxnet/common/build_eval_pack.py Line 72 get_norm_crop()

alan-ai-learner commented 2 years ago

Thanks a lot for your time, can you tell like will it be possible using any virtual Tryon model, I tired few of them but haven't got any proper result. Can you suggest some model that may help if any.

On Mon, 22 Nov 2021 at 19:02, Yuhao @.***> wrote:

A simple practice is to use RetinaFace to detect and align the face. RetinaFace: https://github.com/deepinsight/insightface/tree/master/detection/retinaface Align functioin: https://github.com/deepinsight/insightface/blob/ce3600a74209808017deaf73c036759b96a44ccb/recognition/arcface_mxnet/common/build_eval_pack.py Line 72 get_norm_crop()

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/zyainfal/One-Shot-Face-Swapping-on-Megapixels/issues/26#issuecomment-975525477, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMZS64FNR33CYPNQFPP7ZKTUNJA6LANCNFSM5IGLXPQA .

zyainfal commented 2 years ago

Sorry, I didn't use any Try-on models. And face alignment is one step of face recognition, so I think there are try-on models for face recognition but no try-on models just for alignment.

alan-ai-learner commented 2 years ago

Thanks, I'll check them out.

On Mon, 22 Nov 2021 at 19:10, Yuhao @.***> wrote:

Sorry, I didn't use any Try-on models. And face alignment is one step of face recognition, so I think there are try-on models for face recognition but no try-on models just for alignment.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/zyainfal/One-Shot-Face-Swapping-on-Megapixels/issues/26#issuecomment-975533295, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMZS64F7X2TQBDIYJPIXFJTUNJB35ANCNFSM5IGLXPQA .

an-zi-li commented 2 years ago

You need to get face segmentations at the first step, please refer to this for details. Then you can swap the two faces by giving the path to the inference code, or you can read images by cv2.imread() directly.

here i've to find the segmentation of target image or the source images. getting the following result source Img: 000109 Source IMg Segmentation: 000109

Target IMg: 000735 Output Img: 45721bd4-aeca-4191-b0fc-8d717b6d1c3f

Hello, may I ask how to get the mask that can be used for human face? I would be grateful if you could reply.

zyainfal commented 2 years ago

You may make mistake of the target segmentation, it should have values from 0 to 17 (the semantic index), not RGB values. Just like in https://github.com/zllrunning/face-parsing.PyTorch/blob/master/evaluate.py line 39, save vis_parsing_anno as segmentaion image.

Have you tried this?