deepinsight / insightface

State-of-the-art 2D and 3D Face Analysis Project
https://insightface.ai
23.23k stars 5.4k forks source link

help for face recognition on my own images #2526

Open kiashann opened 8 months ago

kiashann commented 8 months ago

Please help! How I can use this library for face recognition on my own images. I have known and unknown folder with images. I saw below code but I could not find the complete example to use this library. Could you please provide a complete code or example for me.

import cv2 import numpy as np import insightface from insightface.app import FaceAnalysis from insightface.data import get_image as ins_get_image

handler = insightface.model_zoo.get_model('your_recognition_model.onnx') handler.prepare(ctx_id=0)

@yingfeng

arad2022 commented 8 months ago

I want to use R100 model for face recognition which I downloaded from here. I test different models and the output of similarity is shown in comment I used two images from different person. Is it correct way to compare to faces? Is there any other method to do that? Why did the compare function didn't work? @nttstar

import insightface import cv2 import numpy as np from numpy.linalg import norm

def compare(feat1, feat2):

distance = np.dot(feat2, feat1) / norm(feat2) * norm(feat1)

return distance

img1 = cv2.imread(r"20240127_120414.png")

img2 = cv2.imread(r"IMG_20240205_140538.jpg")

handler = insightface.model_zoo.get_model(r"D:\face recognition\code\insightface\cisia_r50.onnx") #20

handler = insightface.model_zoo.get_model(r"D:\face recognition\code\insightface\models\ms1mv2_r50.onnx") #40

handler = insightface.model_zoo.get_model(r"C:\Users\windows.insightface\models\buffalo_l\w600k_r50.onnx") #37

handler = insightface.model_zoo.get_model(r"D:\face recognition\code\insightface\model.onnx") #31

handler.prepare(ctx_id=-1)

f1 = handler.get_feat(img1) f2 = handler.get_feat(img2)

out = handler.compute_sim(f1, f2) print(out)

dis = compare(f1, f2)

print(dis)

askerlee commented 8 months ago

Thanks for sharing. I'm surprised there's no documentation showing this usage.