How hai4h/yolo-human-face-detection works
Project type and purpose
• This is a full-stack, real-time web application for person/face detection and emotion recognition.
• It uses a vanilla JavaScript/CSS/HTML frontend, a Python FastAPI backend, and AI models (YOLO & TensorFlow/TFLite) for inference.
Main components
a. Web Frontend
• Static assets (frontend/index.html, CSS, JS) served over HTTPS by run_server.py using SSL certs in ssl/
• JS modules: camera.js (WebRTC capture), detection.js (send frame & parse response), stats.js (update metrics), ui.js, state.js, config.js
b. FastAPI Backend
• Entry point: backend/main.py (defines /process_frame and /health endpoints)
• app/config.py (model paths, thresholds), app/models.py (model loader), app/box_detector.py (orchestrates inference), backend/db_utils.py (optional logging/persistence)
c. AI Model Layer
• YOLO person & face detectors (.pt files in models/)
• Emotion & human-action recognizers (.tflite, .h5 files)
d. Optional Offline Training & Utilities
• scripts/ for training, conversion, benchmarking
• dataset/ for training data
Relationships and data flow
• Browser (user) ▶︎ captures video frames via camera.js
• Frontend ▶︎ POST multipart/form-data to FastAPI /process_frame (frame JPEG)
• FastAPI ▶︎ box_detector loads models, runs YOLO person→face detection, then TensorFlow/TFLite emotion inference
• FastAPI ▶︎ returns JSON payload (persons, faces, person_boxes, face_boxes with emotion)
• Frontend ▶︎ detection.js & stats.js update UI
Architectural patterns & design principles
• Separation of Concerns:
• Frontend MVC-like structure (camera, detection, UI, state, stats)
• Backend modularization (config, model loader, detection logic, API)
• Asynchronous I/O: FastAPI + Uvicorn for concurrency
• Offline vs. Online: real-time serving vs. batch/utility scripts
Detail without over-splitting
• Every runtime module but focus on logical groupings
• SSL termination at the boundary (HTTPS)