Skip to content

Siamese Neural Network for Facial Recognition using Triplet Loss — built with TensorFlow & Keras as part of the Master’s in MIS/ML program at the University of Arizona.

Notifications You must be signed in to change notification settings

JDede1/advanced-machine-learning-applications1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Siamese Neural Network for Facial Recognition

A Deep Learning application for one-shot face verification using Triplet Loss.

Facial Recognition Preview


Project Overview

This project implements a Siamese Neural Network (SNN) designed to perform facial recognition through embedding similarity, rather than traditional classification. By using Triplet Loss, the network learns to minimize the distance between images of the same person (anchor and positive) while maximizing the distance from a different person (negative).

The model was trained on the Celebrity Faces Dataset, achieving near-perfect verification accuracy on 5-, 10-, 15-, and 20-way tests, and 98% accuracy on 25-way tests — demonstrating robust and generalizable embeddings.


Core Objectives

  • Build a CNN-based embedding model capable of learning discriminative facial features.
  • Train the model using Triplet Loss to improve similarity learning.
  • Evaluate model performance across multiple n-way identification tests.
  • Visualize embeddings and verify the ability to generalize to unseen faces.

Tech Stack

Languages & Frameworks

  • Python 3.10
  • TensorFlow / Keras
  • NumPy | Matplotlib | OpenCV

Development Tools

  • Google Colab + GPU Runtime
  • VS Code (local testing)
  • Git & GitHub (version control)

Model Architecture

The embedding model is a sequential CNN comprising:

  1. Convolution → BatchNorm → MaxPooling → Dropout (3× blocks)
  2. Flatten → Dense(128, ReLU)
  3. Lambda Layer for L2 normalization of embeddings

The embeddings for (anchor, positive, negative) images are concatenated to form the Siamese structure.


Training Summary

Parameter Value
Optimizer Adam
Loss Triplet Loss
Input Shape 105×105×1 (grayscale)
Embedding Size 128
Epochs 10
Batch Size 4

Training Results

Epoch 1–10: Loss steadily reduced to 8.17e-05

Verification Accuracy

Test Type Accuracy
5-way 100%
10-way 100%
15-way 100%
20-way 100%
25-way 98%

Key Insights

  • Triplet Loss directly optimizes similarity relationships, not classification.
  • L2-normalized embeddings stabilize cosine distance comparisons.
  • Preprocessing (grayscale, resize, normalize) removed noise and ensured consistency.
  • CNN feature extractor learned compact, robust facial representations.

How to Run

  1. Clone the repo:

    git clone https://github.com/JDede1/advanced-machine-learning-applications1.git
    cd advanced-machine-learning-applications1
  2. Create and activate your virtual environment:

    python3 -m venv ml-env
    source ml-env/bin/activate   # (Linux/Mac)
    ml-env\Scripts\activate      # (Windows)
  3. Install dependencies:

    pip install -r requirements.txt
  4. Run the notebook or Python script:

    jupyter notebook notebooks/Facial_recoginition_Project.ipynb
    # or
    python notebooks/facial_recoginition_project.py

Business Applications

  • Employee or student identity verification systems
  • Access control and attendance tracking
  • Customer identification in retail / banking
  • Face-based authentication for smart devices

Recommendations for Production Deployment

  • Integrate face detection preprocessing (e.g., MTCNN).
  • Use FaceNet-style transfer learning for larger datasets.
  • Deploy via FastAPI + TensorFlow Serving for real-time inference.
  • Add monitoring (e.g., model drift detection using embeddings).
  • Store embeddings securely for privacy compliance.

Author

Ajibola Jeremiah Dedenuola University of Arizona — MIS/ML Program Role: Machine Learning Engineer / Data Scientist GitHub Profile

About

Siamese Neural Network for Facial Recognition using Triplet Loss — built with TensorFlow & Keras as part of the Master’s in MIS/ML program at the University of Arizona.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published