insightface icon indicating copy to clipboard operation
insightface copied to clipboard

help for face recognition on my own images

Open kiashann opened this issue 1 year ago • 2 comments

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

kiashann avatar Feb 11 '24 15:02 kiashann

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)

arad2022 avatar Feb 27 '24 12:02 arad2022

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

askerlee avatar Feb 28 '24 06:02 askerlee