FaceNet


source

facenet

 facenet (pretrained=True)

A binary classifier matching pairs of facial images


source

FaceNetInceptionResnetV1

 FaceNetInceptionResnetV1 (pretrained=True, classify=True)

Like pytorch_facenet’s InceptionResnetV1 but accepts standard float tensors

from fastai.vision.all import *
from fastai_datasets.all import *

Performance on LFW

Let’s start by quickly evaluating on the development view of LFW:

dls = LFWPairs().dev().dls()
face_matcher = facenet()

face_matcher.fit_threshold(dls.train)
learn = Learner(dls, face_matcher, metrics=accuracy)
learn.validate()
(#2) [0.22585052251815796,0.9919999837875366]
learn.show_results()

face_matcher.plot_distance_histogram(dls.valid)

We can also evaluate the test accuracy (as defined by LFW: 10-fold cross validation on the test view):

class FacenetCrossValidation(RepeatedExperiment):
    def iteration(self):
        self.model.fit_threshold(self.dls.train)
        stats = Learner(self.dls, self.model, metrics=accuracy).validate()
        return dict(zip(['loss', 'accuracy'], stats))
res = FacenetCrossValidation(facenet('vggface2'), LFWPairs().test()).run()
res.plot_stats()

print(as_percentage(res.stat_means['accuracy']))
99.35%

Performance on SLLFW

For a quick evaluation, let’s use the first cross-validation split (since SLLFW doesn’t have a dev view)

dls = SLLFWPairs().test()[0].dls()
face_matcher = facenet()

face_matcher.fit_threshold(dls.train)
learn = Learner(dls, face_matcher, metrics=accuracy)
learn.validate()
(#2) [0.36826473474502563,0.9466666579246521]
learn.show_results()

face_matcher.plot_distance_histogram(dls.valid)

And evaluating properly using the 10-fold cross validation:

res = FacenetCrossValidation(facenet('vggface2'), SLLFWPairs().test()).run()
res.plot_stats()

print(as_percentage(res.stat_means['accuracy']))
94.85%