Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using vggface2 based embedding in inswapper is not prducing correct results #2655

Open
prashant-saxena opened this issue Sep 28, 2024 · 1 comment

Comments

@prashant-saxena
Copy link

Hi,

I'm trying to use vggface2 based embedding using facenet-pytorch
Here is the code to generate:

import torch
from facenet_pytorch import MTCNN, InceptionResnetV1

class FaceEmbed:
    '''https://github.com/timesler/facenet-pytorch'''
    def __init__(self):
        
        device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')

        # If required, create a face detection pipeline using MTCNN:
        self.mtcnn = MTCNN(device=device)

        # Create an inception resnet (in eval mode):
        self.resnet = InceptionResnetV1(pretrained='vggface2').eval()

    def get(self, img):
        # Get cropped and prewhitened image tensor
        img_cropped = self.mtcnn(img)

        # Calculate embedding (unsqueeze to add batch dimension)
        img_embedding = self.resnet(img_cropped.unsqueeze(0))

        return img_embedding.detach().numpy().flatten()

Then using a custom inswapper, I have replaced this line

latent = source_face.normed_embedding.reshape((1,-1))

to

latent = embed.get(source_image).reshape((1,-1))

result

The resulting swap (Incorrect in picture) is not at all good. Any pointers?

@nttstar
Copy link
Collaborator

nttstar commented Oct 25, 2024

You can not use face embeddings with other face recognition models.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants