Face Recognition in a Few Lines of Python
February 6, 2026Posted by Federico Ulfo
An engineer coded a face recognition app to recognize people who look similar from different pictures. The code is surprisingly easy, just use
from deepface import DeepFace
from sklearn.metrics.pairwise import cosine_distances
import sys
## Faces Cosine Distance
faces = DeepFace.extract_faces(sys.argv[1], enforce_detection=False)
## get embedding for first two faces
e0 = DeepFace.represent(faces[0]["face"], model_name="ArcFace")[0]["embedding"]
e1 = DeepFace.represent(faces[1]["face"], model_name="ArcFace")[0]["embedding"]
## compute cosine distance
print(cosine_distances([e0], [e1])[0][0])
Sources: tweet