face-recognition-pipeline

Face Recognition Pipeline πŸ”πŸ‘€

A modular, research-driven face detection & recognition system with plug-and-play detectors (OpenCV, MTCNN, Dlib, face_recognition) and a slick Gradio web UI. Built for fast iteration, real-world reliability, and clean code vibes.


TL;DR


Features


Demo (Gradio)

python face-recognition-pipeline/app.py
# then open the printed local URL in your browser

You can:


Installation

Python 3.9–3.11 recommended. GPU optional (Dlib CUDA build speeds things up but CPU works).

1) Create env & install deps

# clone
git clone https://github.com/amitesh-maurya/face-recognition-pipeline.git
cd face-recognition-pipeline

# (optional) create venv
python -m venv .venv && source .venv/bin/activate  # Windows: .venv\Scripts\activate

# install
pip install -U pip wheel
pip install -r requirements.txt

2) Optional: Dlib with CUDA (speed-up)

If that’s too extra, stick to CPU β€” it’s fine for testing.


Quickstart

Detect & recognize from an image

python scripts/recognize_image.py \
  --image assets/samples/group.jpg \
  --detector mtcnn \
  --db data/embeddings/known_faces.pkl \
  --threshold 0.6

Run on webcam (real-time)

python scripts/recognize_stream.py \
  --source 0 \
  --detector dlib_cnn \
  --db data/embeddings/known_faces.pkl

Build embeddings from a folder

# expects folder structure: data/known/<person_name>/*.jpg
python scripts/build_embeddings.py \
  --images data/known \
  --output data/embeddings/known_faces.pkl \
  --detector face_recognition

Project Structure

face-recognition-pipeline/
β”‚  app.py
β”‚  requirements.txt
β”‚
β”œβ”€ core/
β”‚   β”œβ”€ __init__.py
β”‚   β”œβ”€ config.py
β”‚   β”œβ”€ logging_crypto.py
β”‚   β”œβ”€ gallery.py
β”‚   β”œβ”€ face_utils.py
β”‚   β”œβ”€ match.py
β”‚   └─ pipeline.py
β”‚
└─ ui/
    β”œβ”€ __init__.py
    └─ gradio_ui.py


Architecture (How it flows)

[Input (image/video/webcam)]
        β”‚
        β–Ό
 [Detector]  ──▢ face boxes + landmarks
        β”‚
        β–Ό
 [Encoder]   ──▢ 128D embedding per face (Dlib ResNet)
        β”‚
        β–Ό
 [Matcher]   ──▢ identity + similarity score vs. embeddings DB
        β”‚
        β–Ό
[Output]     ──▢ annotated frames + JSON results

Swappable Detectors


Configuration

All scripts accept flags; you can also use a YAML config.

Example CLI flags:

--detector {opencv_haar,mtcnn,dlib_hog,dlib_cnn,face_recognition}
--threshold 0.6
--min-size 40
--upsample 1
--nms 0.3
--source 0|/path/to/video.mp4
--db data/embeddings/known_faces.pkl
--save-vis runs/vis.jpg

YAML (optional): configs/default.yaml

detector: mtcnn
threshold: 0.6
min_size: 40
upsample: 1
nms: 0.3
encoder: dlib_resnet
matcher: cosine

Output Formats


Benchmarks (placeholder)

Plug in your machine + dataset results here for transparency.

Detector FPS (CPU) FPS (GPU) Precision Recall
OpenCV Haar Β  Β  Β  Β 
MTCNN Β  Β  Β  Β 
Dlib HOG Β  Β  Β  Β 
Dlib CNN Β  Β  Β  Β 
face_recognition Β  Β  Β  Β 

Tips & Gotchas


Roadmap


Contributing

PRs are welcome! Please:

  1. Run tests: pytest -q
  2. Use type hints & docstrings
  3. Pre-commit hooks for linting/formatting

License

MIT β€” do your thing, just keep the notice.


Citation

If this repo helped your research/product, consider citing:

@software{amitesh_face_recognition_pipeline,
  author = {Maurya, Amitesh},
  title = {Modular Face Recognition Pipeline with Gradio UI},
  year = {2025},
  url = {https://github.com/amitesh-maurya/face-recognition-pipeline}
}

Acknowledgements


Got feature ideas? Open an issue. Want a quick tweak for your setup? PRs welcome.