Skip to content

IQRAZAM/face-similarity-engine

Repository files navigation

Python Flask DeepFace TensorFlow FaceNet OpenCV NumPy MySQL XAMPP Bootstrap HTML5 CSS3 Windows

Face Similarity Engine 🔍🧠

A Flask-based Face Similarity & Recognition System that compares an uploaded face image against a dataset of known faces using deep learning face embeddings.

This project demonstrates how modern face recognition systems work internally — from face detection to embedding generation and similarity matching.


🚀 Features

  • Upload an image and detect a human face
  • Generate deep face embeddings using FaceNet
  • Compare embeddings using cosine similarity
  • Display:
    • Uploaded image
    • Top matching faces
    • Similarity percentage
  • Prevents matching when no face is detected
  • Clean UI with dark/purple theme
  • Ethical AI usage with transparency (ETHICS.md)

🧠 How It Works (High-Level Flow)

  1. User uploads an image
  2. Face is detected using DeepFace
  3. A numerical face embedding is generated
  4. Embedding is compared with stored embeddings in the database
  5. Top matches are ranked and displayed

🧠 Face Recognition Model

🔹 FaceNet

  • A deep learning model trained for face recognition
  • Converts a face into a 128-dimensional numerical vector
  • Designed to focus on facial features, not clothing, makeup, or background

Used via:

DeepFace.represent(
    img_path=image_path,
    model_name="Facenet",
    enforce_detection=True
)
## Installation & Setup

1️⃣ Clone the Repository
   `git clone https://github.com/your-username/face_similarity_engine.git`
    `cd face_similarity_engine`

2️⃣ Create & Activate Virtual Environment
    `python -m venv venv`
Activate it (Windows):

     `venv\Scripts\activate`

3️⃣ Install Dependencies

   `pip install -r requirements.txt`
-(TensorFlow is large (~300MB). Please wait for the download to complete.)
4️⃣ Database Setup (MySQL)

Start XAMPPMySQL

Create database:

`CREATE DATABASE face_db;`


Create table:

```CREATE TABLE face_embeddings (
    id INT AUTO_INCREMENT PRIMARY KEY,
    image_name VARCHAR(255),
    embedding LONGTEXT
);```
5️⃣ Add Dataset Images

Place known face images inside:

static/dataset/


Example:

-static/dataset/iu.jpg
-static/dataset/person2.jpg

6️⃣ Generate Face Embeddings

Run:
`python generate_embeddings.py`
This will:
-Detect faces in dataset images
-Generate embeddings
-Store them in the database

7️⃣ Run the Application
   `python app.py`
Open in browser:
    `http://127.0.0.1:5000`

## Usage

-Upload a clear image containing a human face
-Click Search
### View:
-Uploaded image
-Top face matches
-Similarity percentages
If no face is detected, the system will display an error message.
## ⚠️ Limitations

-Accuracy depends on image quality
-Extreme side angles may reduce detection accuracy
-Small datasets limit recognition capability
-Not suitable for real-world identity verification

About

Flask-based face similarity engine using DeepFace (FaceNet) to match uploaded images against a face dataset with cosine similarity.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors