Giter VIP home page Giter VIP logo

Comments (4)

sajjjadayobi avatar sajjjadayobi commented on July 30, 2024

yes there is, you can look at the following function and find out your two image distance with print

diff = embs.unsqueeze(-1) - target_embs.transpose(1, 0).unsqueeze(0)
dist = torch.sum(torch.pow(diff, 2), dim=1)
print(dist) # it returns the distance between new face with all faces in your bank

it's in facelib/InsightFace/models/Learner.py
or you can write your own function in Learner Class
like the following

def compare2faces(self, conf, faces, tta=False)
        """faces : list of PIL Image (your faces for comparing) """
        faces = faces_preprocessing(faces, conf.device)
        if tta:
            faces_emb = self.model(faces)
            hflip_emb = self.model(faces.flip(-1))  # image horizontal flip
            embs = l2_norm((faces_emb + hflip_emb)/2)  # take mean
        else:
            embs = self.model(faces)

        diff = embs[0] - embs[1]
        dist = torch.sum(torch.pow(diff, 2), dim=1)
        return dist

and run it like this:

from facelib import FaceRecognizer, get_config
recognizer = FaceRecognizer(get_config())
recognizer.model.eval()
img1 = PIL.Image.open('')
img2 = PIL.Image.open('')
recognizer.compare2faces(self.conf, faces=[img1, img2], tta=self.tta)

from facelib.

sajjjadayobi avatar sajjjadayobi commented on July 30, 2024

and you can also see the embeddings at (embs in the infer function)
if you add any new features to this project let me know

from facelib.

Adeel-Intizar avatar Adeel-Intizar commented on July 30, 2024

sure I will let you know, Thank you

from facelib.

bistcuite avatar bistcuite commented on July 30, 2024

I tried to run this code but i got this error :
Capture

from facelib.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.