Python 人脸识别KNN算法中匹配图像百分比的确定

Python 人脸识别KNN算法中匹配图像百分比的确定,python,face-recognition,knn,Python,Face Recognition,Knn,我目前正在遵循这个repo:使用KNN算法在python中进行人脸识别。当我读代码时,我发现了这个 # Find encodings for faces in the test iamge faces_encodings = face_recognition.face_encodings(X_img, known_face_locations=X_face_locations) # Use the KNN model to find the best matches f

我目前正在遵循这个repo:使用KNN算法在python中进行人脸识别。当我读代码时,我发现了这个

    # Find encodings for faces in the test iamge
    faces_encodings = face_recognition.face_encodings(X_img, known_face_locations=X_face_locations)

    # Use the KNN model to find the best matches for the test face
    closest_distances = knn_clf.kneighbors(faces_encodings, n_neighbors=1)

    are_matches = [closest_distances[0][i][0] <= distance_threshold for i in range(len(X_face_locations))]

    # Predict classes and remove classifications that aren't within the threshold
    return [(pred, loc) if rec else ("unknown", loc) for pred, loc, rec in zip(knn_clf.predict(faces_encodings), X_face_locations, are_matches)]

#在测试图像中查找面编码
面部编码=面部识别。面部编码(X\u img,已知面部位置=X\u面部位置)
#使用KNN模型为测试面找到最佳匹配
最近距离=knn\u clf.kneighbors(面编码,n\u邻居=1)
are_matches=[最近的_距离[0][i][0]试着看看这个:

Adam Geitgey解释说,没有直接的方法可以将距离转换为百分比……但“类似的”是。

Hi@Bohdan,我一直在浏览那个网站,让我困惑的是如何获得
face\u distance
值。
face\u distance
值来自
最近的距离
(根据我在问题中提到的上述代码)?是的,是的,你最近的距离就是这些距离的列表……但是,两个面之间的距离被标准化为1:当它为0时-面完全相同(100%相似),1表示它们完全不同(0%相似),对吗?所以,我的建议是使用最简单的百分比计算`百分比=(1.0-距离)*100.0`。没有人能看到和理解86%和92%图像相似性之间的差异,那么为什么你需要用它来打破你的大脑?!