๐Ÿ”ฅLimited Offer: Get 50% OFFon AI & Full Stack Courses๐Ÿ”ฅ
Back to Deep Learning Notes
Topic #195

Face Recognition

Face recognition is a specialized computer vision application built directly on embedding-based learning โ€” using the exact contrastive and triplet loss ideas covered in the Loss Functions category to map faces into a space where identity is measured by distance.

Verification vs Identification

TaskQuestion Answered
Face verification"Are these two face images the same person?" (a 1-to-1 comparison)
Face identification"Which person, among a known database, does this face belong to?" (a 1-to-many comparison)

The Embedding-Based Approach

Rather than classifying faces into a fixed set of known identities (which wouldn't generalize to new people never seen during training), a face recognition network learns to map any face image into a fixed-length embedding vector, such that images of the same person are close together in that embedding space, and images of different people are far apart โ€” trained using triplet loss (see Triplet Loss) or contrastive loss (see Contrastive Loss).

Verification via Distance Thresholding

\[ \text{Same person if } \|\mathbf{e}_1-\mathbf{e}_2\| < \tau \]

Once two faces are embedded, verification is simply a distance comparison against a chosen threshold \(\tau\) โ€” the exact same Euclidean distance measure used throughout the triplet/contrastive loss formulas.

Code

import torch
import torch.nn.functional as F

def is_same_person(embedding1, embedding2, threshold=1.0):
    distance = F.pairwise_distance(embedding1.unsqueeze(0), embedding2.unsqueeze(0))
    return distance.item() < threshold

# embedding1, embedding2 would come from a trained face-embedding network
embedding1 = torch.randn(128)
embedding2 = torch.randn(128)
print(is_same_person(embedding1, embedding2))

Common Mistakes

  • Framing face recognition as standard fixed-class classification โ€” this fails to generalize to new individuals never seen during training; the embedding-based, distance-comparison approach is what enables recognizing people not present in the original training set.
  • Choosing a verification threshold \(\tau\) without considering the precision/recall tradeoff (see Precision & Recall) appropriate for the specific application's stakes (e.g. security access vs. photo-tagging convenience).

Interview Relevance

Q: "Why does face recognition typically use an embedding-based approach rather than standard classification?" Classification requires a fixed, known set of classes decided at training time โ€” it can't recognize a new person never seen during training without retraining the whole classifier. An embedding-based approach, trained with triplet or contrastive loss, learns a general notion of "same person = close in embedding space," which generalizes to verifying or identifying people never encountered during training, as long as at least one reference image of them exists.

Practice Question

Why would face identification (matching against a large known database) typically be more computationally demanding than face verification (a single 1-to-1 comparison)?

Want to go beyond the notes?

Join CodingNow 2.0's Deep Learning course โ€” live mentorship, real projects, and 100% placement support.

Enroll Now โ€” Free Demo Available

Face Recognition โ€“ FAQs

Quick answers about learning Face Recognition in Deep Learning.

This free note from CodingNow 2.0 explains Face Recognition in Deep Learning โ€” concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every Deep Learning topic on CodingNow 2.0, including Face Recognition, is 100% free with no signup required.
With focused practice, most students grasp Face Recognition in 1โ€“3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) โ€” expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now