Age & Gender Detection

Computer vision pipeline evaluating demographic attribute prediction and regression-to-the-mean bias.

Computer VisionTensorflowKerasOpenCVReal-time DetectionRetinaFaceModel Evaluation

The Challenge

Deploying pre-trained facial analysis models on real-world data often reveals hidden systemic biases and performance bottlenecks. This project aimed to evaluate DeepFace demographic predictions, specifically investigating why neural networks often default to average demographic values when uncertain, and determining the optimal hardware utilization for frame-by-frame inference.

System Architecture

The pipeline handles image and video streams using OpenCV for preprocessing, feeding frames into the DeepFace inference engine, and mathematically analyzing the output distribution to identify skew.

Media Stream → OpenCV Preprocessing → DeepFace Inference Engine → Bias Analysis & Statistics

Performance & Results

Measured against 23,707 images from the UTKFace dataset, using the RetinaFace detector backend:

MetricRawAfter calibration
Age MAE10.66 years9.16 years (-14.4%, validated on a held-out test set)
Gender accuracy83.58%— (calibration only applies to age)

Live Inference Performance

Benchmarked on a Mac Studio (M3 Ultra), averaged over 300 processed frames:

ModeDisplay FPSAvg. analysis time
Synchronous (no threading)0.533735 ms
Multithreaded (default)29.283612 ms

Decoupling DeepFace analysis from the display loop via a background thread improved live display FPS by ~55x. The per-frame analysis cost remains essentially unchanged; the improvement comes entirely from unblocking the render loop.

Engineering Learnings

  • Statistical Bias Diagnosis: Identified systematic regression-to-the-mean bias in age predictions and implemented a post-hoc linear calibration model.
  • Inference Optimization: Designed a multithreaded inference pipeline that holds analysis throughput steady at 0.26–0.27 analyses/sec while preventing display blocking.
  • Environment Management: Resolved Keras 3 compatibility breaks and memory leaks to ensure stability during long-running inference sessions.

Showcase

View GitHub

Ask AI

Hi! I'm Irvallen's AI assistant. Ask me anything about his projects or experience.