Machine Learning - Face Detection & Recognition (E2E)
Overview
Pipeline: face detection (pretrained), embedding extraction, and identity matching via nearest neighbors in a vector index (e.g., FAISS).
Steps
- Detect faces to get bounding boxes.
- Crop/align faces and compute embeddings with a trained model.
- Match embeddings against a gallery using cosine similarity or FAISS.
Embeddings + FAISS (snippet)
# pip install faiss-cpu numpy
import faiss, numpy as np
# gallery_embeddings: (N, D), query: (D,)
index = faiss.IndexFlatIP(D) # cosine similarity if vectors are L2-normalized
index.add(gallery_embeddings.astype('float32'))
Dists, Idxs = index.search(query.reshape(1,-1).astype('float32'), k=5)
print(Idxs[0], Dists[0])