← BACK TO PORTFOLIO

Y.O.D.A RECOGNITION

Your Optical Detection Assistant — finds faces in a photo, turns each one into a vector, and uses PostgreSQL to spot duplicates and look people up.

RoleComputer Vision Developer
Timeline2023
StackPython, OpenCV, CLIP, Streamlit
DataPostgreSQL + pgvector, Docker

OVERVIEW

Y.O.D.A combines a classic, fast face detector with a modern embedding model and a vector database. Upload a photo and it finds every face, refuses to store the same face twice, and lets you search the collection with a new photo.

Y.O.D.A Face Recognition System Screen 1
Y.O.D.A Face Recognition System Screen 2
Y.O.D.A Face Recognition System Screen 3
Y.O.D.A Face Recognition System Screen 4
Y.O.D.A Face Recognition System Screen 5
Y.O.D.A Face Recognition System Screen 6
Y.O.D.A Face Recognition System Screen 7

HOW A FACE IS PROCESSED

01DetectOpenCV’s Haar cascade scans a grayscale copy for frontal faces of at least 60×60 pixels. If few faces are found, a retry button loosens the detector and runs it again.
02CropEach face is cropped and shown so the user can see exactly what will be stored.
03EmbedThe crop is resized to 224×224 and encoded by CLIP ViT-B/32 (via sentence-transformers) into a 512-dimension vector.
04Check for duplicatespgvector finds the closest stored face by cosine distance. A similarity of 95% or more counts as the same face and is skipped.
05StoreNew faces are saved to disk, and their filename and vector are inserted into PostgreSQL.

THE APP

Upload & Save
Detect, preview, de-duplicate, and store every face in a photo.
Search
Upload a face and get its closest match with a similarity percentage, side by side.
Gallery
Browse everything stored, and delete entries with a confirmation step.
Settings
Tune the detector’s strictness (minimum neighbours) from the interface.

DESIGN DECISIONS

Fast detector, strong embedder
Haar cascades are cheap and good enough to find faces; the heavy lifting of telling faces apart is left to CLIP.
Similarity in the database
pgvector’s <=> operator ranks matches inside PostgreSQL, so the app never loads every vector into memory.
De-duplicate on write
Checking before inserting keeps the collection clean instead of cleaning it up later.
Containerized
A Dockerfile on Python 3.10 installs OpenCV’s system libraries and runs Streamlit, so it deploys the same way everywhere.

DATABASE

pictures
  • picture — stored file name
  • embedding — VECTOR(512)
Nearest-match query
SELECT picture,
  1 - (embedding <=> $q) AS similarity
FROM pictures
ORDER BY embedding <=> $q
LIMIT 1;

RESULTS & LIMITS

  • In my testing it reached about 70% accuracy in good lighting and reliably blocked duplicates.
  • Haar cascades struggle with low light and side profiles, which caps how many faces are found.
  • CLIP is a general image model, not a face-specific one; a dedicated model such as ArcFace would separate similar-looking people better.

RUN IT

git clone https://github.com/AAFLY99/yoda-face-recognition.git
cd yoda-face-recognition
pip install -r requirements.txt   # needs PostgreSQL with the pgvector extension
streamlit run aio.py

# or with Docker
docker build -t yoda . && docker run -p 8080:8080 yoda