Search code examples
pythonopencvdeep-learningbiometrics

How to calculate accuracy for facial recognition system?


I am new to Biometric Evaluation and I wish to plot the ROC curve, CMC curve, and Genuine Vs Imposter Distribution. I trained the model on my dataset based on https://www.pyimagesearch.com/2018/06/18/face-recognition-with-opencv-python-and-deep-learning/. If I give a test image, it is working correctly. But, I do not know how to get a genuine and imposter score based on this method for the entire Test Dataset.


Solution

  • All state-of-the-art models such as VGG-Face, FaceNet or DeepFace are tested on LFW (Labeled Faces in the Wild) data set. Luckily, Scikit learn offers this data set as an out-of-the-box function.

    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
    

    Now, you should test each pair with your model.

    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)
    

    Then, you should compare predictions and labels.

    from sklearn.metrics import accuracy_score
    score = accuracy_score(labels, predictions)
    

    Besides, you can calculate some other metrics

    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)