python - 如何计算人脸识别系统的准确率?
问题描述
我是生物识别评估的新手,我希望绘制 ROC 曲线、CMC 曲线和 Genuine Vs Imposter Distribution。我根据https://www.pyimagesearch.com/2018/06/18/face-recognition-with-opencv-python-and-deep-learning/在我的数据集上训练了模型。如果我给出一个测试图像,它工作正常。但是,我不知道如何根据这种方法为整个测试数据集获得真实和冒名顶替的分数。
解决方案
所有最先进的模型,例如 VGG-Face、FaceNet 或 DeepFace,都在 LFW(Labeled Faces in the Wild)数据集上进行了测试。幸运的是,Scikit learn 将此数据集作为开箱即用的功能提供。
from sklearn.datasets import fetch_lfw_pairs
fetch_lfw_pairs = fetch_lfw_pairs(subset = 'test', color = True, resize = 1)
pairs = fetch_lfw_pairs.pairs
labels = fetch_lfw_pairs.target
现在,您应该使用您的模型测试每一对。
predictions = []
for i in range(0, pairs.shape[0]):
pair = pairs[i]
img1 = pair[0]
img2 = pair[1]
prediction = verify(img1, img2) #this should return 1 for same person, 0 for different persons.
predictions.append(prediction)
然后,您应该比较预测和标签。
from sklearn.metrics import accuracy_score
score = accuracy_score(labels, predictions)
此外,您还可以计算其他一些指标
from sklearn.metrics import precision_score, recall_score, f1_score
precision = precision_score(actuals, predictions)
recall = recall_score(actuals, predictions)
f1 = f1_score(actuals, predictions)
推荐阅读
- mongodb - 如何使用 Mongo 聚合来限制给定输入周围的结果?
- c# - 为什么在表达式树中不允许丢弃?
- mongodb - 如何制作重复记录
- node.js - 将自定义信息添加到 Firebase Functions 中的 Stackdriver 错误日志
- scala - 无法分析数据
- python - 将矩阵负值更改为绝对值
- c# - XAML 将徽标添加到 Xamarin 跨平台表单
- c# - 为什么要列出
.Sort(IComparer ) 和列表 .排序(比较 ) 以不同的方式处理角落案例? - c++ - 如何从文件中读取用空格分隔的数字
- javascript - 通过 JavaScript 从私有 GitHub 存储库获取文件内容