将yolov4人脸检测与face_recognition一起使用

问题描述

我可以使用yolov4进行对象检测并使用face_recognition库识别检测到的面部,还是需要使用face_recognition库提供的面部检测才能使用其面部识别?

解决方法

face_recognition库使用dlib的内置算法专门用于面部检测。据称精度为99%+。您不能将该算法更改为YoloV4或其他任何算法。

用于face_recognition的网络体系结构基于ResNet-34,但层数更少,过滤器数量减少了一半。对网络进行了训练,该数据集包含“狂野标签”(LFW)数据集中的300万张图像。

请参阅有关基于深度学习的面部识别如何工作的文章Davis King(dlib的创建者)和Adam Geitgey(face_recognition的作者)的文章:

High Quality Face Recognition with Deep Metric Learning

Modern Face Recognition with Deep Learning

但是,如果这还不足以满足您的情况,您可以训练YoloV4来检测面部,然后在检测后裁剪该面部并将其作为输入作为face_recognition库。

import face_recognition

picture_of_me = face_recognition.load_image_file("me.jpg")
my_face_encoding = face_recognition.face_encodings(picture_of_me)[0]

# my_face_encoding now contains a universal 'encoding' of my facial features that can be compared to any other picture of a face!

unknown_picture = face_recognition.load_image_file("unknown.jpg")
unknown_face_encoding = face_recognition.face_encodings(unknown_picture)[0]

# Now we can see the two face encodings are of the same person with `compare_faces`!

results = face_recognition.compare_faces([my_face_encoding],unknown_face_encoding)

if results[0] == True:
    print("It's a picture of me!")
else:
    print("It's not a picture of me!")