--- title: FaceEmbedding Model keywords: fastai sidebar: home_sidebar nb_path: "nbs/indexers.FaceRecognitionModel.ipynb" ---
The FaceEmbeddingModel
recognizes face from photos. Behind the scenes it uses the arcface model from deepinsight to make predictions. The model does both face detection (creating bouding boxes around faces) and face verification (compare faces and check for similarity).
You can initialize the Facerecognition model as follows:
indexer = FaceEmbeddingModel()
photo = IPhoto.from_path(path=PYI_TESTDATA / "photos" / "facerecognition" / "celebs.jpg")
boxes, landmarks = indexer.predict_boundingboxes(photo)
photo.draw_boxes(boxes)
crops = photo.get_crops(boxes, landmarks)
You can easily inspect the embeddings for those crops using the get_embedding
function
embedding = indexer.get_embedding(crops[0])
embedding.shape, embedding[:3]
You can inspect the crops using the show_images
function
show_images([crops[0], crops[1]])
And check if they are the same
try:
similarity = indexer.compare(crops[0], crops[1])
assert similarity < 0.5
finally:
print("Not the same person")
ellen1 = IPhoto.from_path(path=PYI_TESTDATA / "photos" / "facerecognition" / "ellen1.png")
ellen2 = IPhoto.from_path(path=PYI_TESTDATA / "photos" / "facerecognition" / "ellen2.png")
show_images([ellen1.data, ellen2.data])
try:
sim = indexer.compare(ellen1.data, ellen2.data)
assert sim > 0.5
finally:
print("Same person")
When we plot the crops, we see that our model actually is doing some magic behind the scenes to normalize and scale our images.
photo.plot_crops(boxes, landmarks)