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.
- 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)
- User uploads an image
- Face is detected using DeepFace
- A numerical face embedding is generated
- Embedding is compared with stored embeddings in the database
- Top matches are ranked and displayed
- 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 XAMPP → MySQL
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