deepface icon indicating copy to clipboard operation
deepface copied to clipboard

Possible to add InsightFace

Open ethaniel opened this issue 10 months ago • 18 comments

Hi! Thank you for the amazing library, it really was a gentle introduction into the world of facial recognition.

However, I've noticed that none of the models really work for my face, I get false and false positive results (I've tried different detectors and normalizers too). I've also noticed that the models that you've linked are all around 4 years old.

Perhaps, adding some newer models (like InsightFace) would be possible?

ethaniel avatar Apr 14 '24 14:04 ethaniel

ArcFace is the facial recognition model of insightface project. It is already supported in deepface.

serengil avatar Apr 14 '24 14:04 serengil

Besides, GhostFace is a recently published model.

serengil avatar Apr 14 '24 16:04 serengil

@serengil thank you! One small thing - looks like Arcface has released new models (r100,AdaFace back in 2022. Is that the one that you ported to deepface?

ethaniel avatar Apr 15 '24 08:04 ethaniel

Backbone: Resnet34 Trianing: CASIA, E40 LFW: 0.9946

serengil avatar Apr 15 '24 13:04 serengil

Thank you! Any chance that r100,AdaFace could be ported into your library?

I've got an asian face and no matter how much I try, I couldn't get Arcface (or any other model in the library) to provide correct embeddings that would match me on different photos through the last 10 years. I was hoping that one of the newer models from Arcface could have possibly fixed that.

ethaniel avatar Apr 15 '24 14:04 ethaniel

of course, will try to add AdaFace model as well but its lfw score is very close, do not think it will resolve your problem.

serengil avatar Apr 15 '24 14:04 serengil

InsightFace have also been experimenting with south asian and east asian faces (https://github.com/deepinsight/insightface/tree/master/model_zoo), getting good results on their R100,Glint360K model. However that's onnx format and waay over my head to understand if it's even possible to be ported into deepface.

Sefik, I just wanted to say that I appreciate you and everything that you do! Thank you so so much for opening the world of facial recognition for people that want to learn!

ethaniel avatar Apr 15 '24 15:04 ethaniel

Which onnx fits you?

serengil avatar Apr 15 '24 15:04 serengil

Looking again at that list, "buffalo_l" model seems like the overall winner. It has the best South Asian (93.16) and East Asian (74.96) accuracy of all + the LFW is at 99.83.

ethaniel avatar Apr 15 '24 15:04 ethaniel

But cannot find buffalo_l's onnx in that page

serengil avatar Apr 15 '24 16:04 serengil

buffalo_l can be downloaded from here: https://github.com/deepinsight/insightface/tree/master/python-package

ethaniel avatar Apr 15 '24 16:04 ethaniel

I too am another one waiting for buffalo_l to be integrated into deepface. and I find difficulty while using multi threading of deepface.

I had this code and I'm always getting segmentation fault, double linked list core dumped, and free(): invalid next size (fast) errors. i actually tried find method and it is not giving accurate results compared to verify method {even this too gives some false positives but better when compared to find method. so basically want to extract unique faces from a folder and store it to another folder and this should use multi threading to save time as folder may contain many images.

Raghucharan16 avatar Apr 18 '24 08:04 Raghucharan16

will add buffalo_l model into the portfolio soon - possibly this weekend

yeah i know the library becomes unstable because of tf dependency when being called with multithread. recommend not to use multi-threading for now.

serengil avatar Apr 18 '24 08:04 serengil

@serengil thanks for the response and we really appreciate your work on this. keep building such unique,amazing and simple to use things for the community.

Raghucharan16 avatar Apr 18 '24 08:04 Raghucharan16

@ethaniel did you figured out any way of implementing buffalo_l model into script?

Raghucharan16 avatar Apr 22 '24 09:04 Raghucharan16

Hey @serengil when can we expect the buffalo_l model in deepface? Any tentative time??

Raghucharan16 avatar Apr 23 '24 12:04 Raghucharan16

soon

serengil avatar Apr 23 '24 12:04 serengil

@serengil thank you! One small thing - looks like Arcface has released new models (r100,AdaFace back in 2022. Is that the one that you ported to deepface?

Hey @ethaniel I've figured out a way to use those onnx file formats but for me it is taking lot of time to execute, in my usecase i have to compare 2 folder of faces and extract unique faces among them. may be that's not your case, you can use the onnx models of insight face in this way

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("model.onnx")#specify your model path
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)

Raghucharan16 avatar May 17 '24 05:05 Raghucharan16