AuthBrain AI Face Analysis Engine
A privacy-first, real-time facial behavior analysis platform that combines classical computer vision, expert rules, deep learning, graph neural networks, and explainable AI in a React + FastAPI system.
This document is both a developer guide and a technical architecture report. It is written for GitHub, research handover, software engineering documentation, and thesis appendix use.
- Project Overview
- Overall System Architecture
- Technology Stack
- Folder Structure
- Complete Processing Pipeline
- Deep Learning Architecture
- Graph Neural Network
- Expert Rule Engine
- Explainable AI
- Model Ensemble
- Database Design
- WebSocket Communication
- Dashboard Components
- Configuration
- Performance Optimization
- Security
- Testing
- Installation
- API Documentation
- Future Work
- References
AUTHFACEGRAPH AI is a real-time face analysis platform for webcam-driven observation of facial behavior, attention, fatigue, and emotion. The system streams frames from a browser to a backend inference pipeline, performs landmark detection and signal extraction, then combines deterministic rules with learned models to produce explainable per-frame outputs.
The project is organized as an enterprise-style full stack system:
- React frontend for live capture and dashboards
- FastAPI backend for analysis and streaming
- MediaPipe Face Mesh for 478-landmark geometry
- Classical physiological analyzers for EAR, MAR, gaze, head pose, and smile
- Deep learning emotion models for image-based inference
- Graph neural networks for facial landmark relational reasoning
- Explainable AI for model and rule transparency
- Database persistence for sessions, metrics, and logs
Most webcam-based facial analytics systems fail for one or more of the following reasons:
- They rely on a single model and produce brittle results.
- They ignore geometric signals such as eyes, mouth, and head pose.
- They show model output without explaining why it happened.
- They do not track temporal behavior.
- They do not separate classical CV reliability from learned model uncertainty.
- They do not gate weak models or detect bad inputs.
This project addresses those weaknesses by combining multiple inference layers, confidence-aware decision logic, and a research-oriented visualization stack.
The platform is designed to study and operationalize the following questions:
- Can facial emotion recognition be made more reliable under live webcam conditions?
- Can a hybrid system outperform a single deep model by combining rules, CNNs, and graph reasoning?
- Can explainability be built into the pipeline rather than added afterward?
- Can uncertainty and disagreement be tracked explicitly for real-time inference?
- Can facial behavior be analyzed without requiring biometric storage or identity recognition?
- Webcam frames arrive with inconsistent lighting, pose, and compression artifacts.
- Pretrained emotion models can misclassify smiling faces under domain mismatch.
- A single classifier has no explicit mechanism to detect uncertainty.
- GNN overlays can become visually unreadable if scaling is not controlled.
- Many systems lack auditable rule-based outputs for safety and debugging.
- Temporal behavior is often ignored even though it matters for fatigue and attention.
- Hybrid architecture combining rules, CNNs, GNNs, and XAI.
- 478-landmark graph representation of the face.
- Geometric Action Unit estimation from facial landmarks.
- Dynamic result fusion with agreement and disagreement measurement.
- Explicit confidence handling and low-confidence gating.
- Live WebSocket transport for low-latency inference feedback.
- Research-mode dashboard for node-level and edge-level visualization.
- Real-time webcam capture in the browser.
- FastAPI WebSocket backend for binary JPEG frame streaming.
- MediaPipe Face Mesh with 478 landmarks.
- Eye Aspect Ratio, Mouth Aspect Ratio, gaze, head pose, and smile estimation.
- Expert rule engine for fatigue, focus, and alert classification.
- HSEmotion emotion recognition.
- EfficientFace model integration framework.
- Graph Attention Network and Graph Convolution baseline support.
- Geometric Action Unit estimation.
- Explainable AI outputs for landmarks and rules.
- Dashboard with emotion, metrics, timeline, and GNN visualization.
- Session persistence and log storage.
- Frame-by-frame inference over WebSocket.
- Multiple model outputs with confidence and uncertainty tracking.
- Per-session metrics and summary statistics.
- Debug inference artifacts written to disk.
- Model health tracking and latency reporting.
- Optional GNN inference controlled by checkpoint availability.
- Frontend research mode for graph interrogation.
flowchart TD
U[User] --> R[React Frontend]
R --> W[WebSocket Binary Frame Stream]
W --> F[FastAPI Backend]
F --> P[Analysis Pipeline]
P --> E[Expert Rule Engine]
P --> D[Deep Learning Engine]
D --> G[Graph Neural Network]
D --> X[Explainable AI]
E --> M[Result Fusion]
D --> M
X --> M
M --> DB[Database]
M --> R
R --> DASH[Dashboard]
+-------------------+ +------------------------+
| React Frontend | | FastAPI Backend |
|-------------------| |------------------------|
| Camera capture |<----->| WebSocket endpoint |
| Dashboard UI | | Auth/session API |
| Research mode | | Analysis pipeline |
| Canvas visualizer | | Model registry |
+-------------------+ | Expert rules |
| DL engine |
| DB persistence |
+------------------------+
sequenceDiagram
participant User
participant React as React App
participant WS as WebSocket
participant API as FastAPI
participant Pipe as Analysis Pipeline
participant Rules as Expert Rules
participant DL as Deep Learning Engine
participant DB as Database
User->>React: Grant camera consent
React->>WS: Send JPEG frame
WS->>API: Binary frame + token
API->>Pipe: Decode and analyze frame
Pipe->>Rules: EAR/MAR/pose/behavior metrics
Pipe->>DL: Emotion, graph, AU, XAI inference
DL->>DB: Persist model health / metrics
Pipe->>DB: Persist session data
API->>WS: JSON result + annotated frame
WS->>React: Update dashboard
- The frontend does not perform the core inference; it only captures and displays frames.
- The backend is the authoritative inference layer.
- The pipeline is intentionally modular so classical CV, rules, and learned models can evolve independently.
- The GNN is checkpoint-gated to prevent random or untrained graph predictions from being surfaced as valid output.
| Layer | Technology | Why It Was Selected |
|---|---|---|
| Frontend | React 18 + TypeScript | Strong component model, type safety, and maintainable dashboard code |
| Frontend build | Vite | Fast local development and production build performance |
| Styling | Tailwind CSS | Utility-driven UI assembly for dense scientific dashboards |
| Charts | Recharts | Stable, flexible charting for time-series and probability plots |
| State | Zustand | Lightweight global state for streaming analysis data |
| Backend | FastAPI | High-performance async API and WebSocket support |
| ASGI server | Uvicorn | Simple production-ready server for FastAPI |
| Computer Vision | OpenCV | Frame decode, crop, geometry, and image processing |
| Landmark detection | MediaPipe Face Mesh | 478 landmark extraction with production-grade runtime |
| Emotion recognition | HSEmotion ONNX | Low-latency webcam emotion classification |
| Emotion alternative | EfficientFace | Pluggable CNN architecture for research and benchmarking |
| Graph learning | PyTorch Geometric | Native graph neural network tooling |
| ML framework | PyTorch | Flexible training and inference for graph and CNN models |
| Explainability | Custom XAI + GNN attention | Human-readable feature attribution and graph saliency |
| Database | SQLite / PostgreSQL | Local development and production persistence |
| ORM | SQLAlchemy Async | Type-safe persistence with async backend support |
| Auth | JWT | Secure session and WebSocket access control |
| Networking | WebSocket | Low-latency live frame transport |
| Testing | PyTest | Unit, integration, and behavior tests |
| Deployment | Docker / docker-compose | Reproducible multi-service deployment |
The stack is intentionally split between real-time systems tooling and research tooling. FastAPI and WebSocket are used for live inference. PyTorch and PyTorch Geometric provide the model experimentation layer. React and Tailwind provide a responsive scientific dashboard. SQLite supports local development, while PostgreSQL supports production and longer-lived session analytics.
backend/- FastAPI backend, analysis pipeline, models, and tests.frontend/- React dashboard and webcam interface.models/- MediaPipe task file and model assets.docker-compose.yml- Multi-service orchestration.start.sh- Convenience script to launch backend and frontend.Makefile- Task shortcuts for development workflows.
FastAPI application entry point. Registers routers, middleware, and lifespan handling.
Classical computer vision and behavioral analysis.
pipeline.py- Main per-frame orchestrator.face_detector.py- MediaPipe Face Mesh wrapper and face crop extraction.eye_analyzer.py- EAR, blink count, closure duration, gaze direction.mouth_analyzer.py- MAR, smile intensity, yawn logic.head_pose.py- Head pose estimation from canonical 3D landmarks.behavior_tracker.py- Temporal stability and behavior history.quality_scorer.py- Face quality estimation.landmark_indices.py- Landmark constants.
Deep learning subsystem.
base.py- Abstract model interfaces and data structures.registry.py- Model registration and lifecycle management.engine.py- Orchestrates model loading, inference, fusion, and outputs.emotion/- Emotion recognition models and ensemble logic.graph/- Graph construction and GNN architectures.action_units/- FACS-style action unit estimation.xai/- Graph explanation and attribution utilities.
Rule-based decision layer.
rules.py- Deterministic rules and risk classifications.scorer.py- Composite fatigue, focus, and confidence scoring.explainer.py- Human-readable explanations for rules and signals.
REST and WebSocket routes.
routes/- Auth, sessions, models, consent, health.websocket/- Frame transport and response handling.
Infrastructure and platform concerns.
config.py- Environment variables and settings.database.py- Async DB connectivity and session management.logging.py- Structured logging.security.py- JWT and auth helpers.
Contracts and persistence models.
schemas.py- Pydantic API schemas.db_models.py- SQLAlchemy tables.
Shared utilities.
frame_utils.py- JPEG conversion, resizing, image drawing.math_utils.py- Geometry and confidence utilities.calibration.py- Confidence calibration helpers.
PyTest unit and integration tests for the analysis and model stack.
CameraFeed.tsx- Live video capture and stream control.PrimaryAIVisualizer.tsx- Research-mode face graph visualizer.
MetricsPanel.tsx- Summary analytics and metric cards.EnsemblePanel.tsx- Model selection and ensemble inspection.EmotionRadarChart.tsx- Emotion distribution radar.EmotionTimelineChart.tsx- Temporal emotion evolution.ActionUnitsPanel.tsx- AU intensities.SystemLogs.tsx- Event and diagnostic logs.TopBar.tsx,LeftSidebar.tsx,RightPanel.tsx- Dashboard layout.
index.ts- Zustand store and live analysis state.
websocket.ts- Binary frame sending and message handling.
ConsentPage.tsx- User consent gate.Dashboard.tsx- Main analysis dashboard.
The user authenticates and obtains a JWT access token. The session is associated with a session ID and consent state.
Input: credentials, consent metadata Output: authenticated session context
The browser requests webcam access via getUserMedia() and begins frame capture.
Input: device camera stream Output: video element frames
The frontend captures frames using an off-screen canvas, compresses them to JPEG, and transmits them over WebSocket.
Input: video frame Output: JPEG blob
The backend decodes JPEG bytes to BGR and runs MediaPipe Face Landmarker.
Input: JPEG bytes Output: one or more faces with 478 landmarks
Each face is represented as a normalized landmark set.
Input: detected face landmarks Output: landmark array, bounding box, pixel coordinates
Classical physiological signals are computed from landmarks:
- EAR - Eye Aspect Ratio
- MAR - Mouth Aspect Ratio
- Head pose
- Blink count
- Gaze direction
- Smile intensity
- Behavior stability
Input: landmark set, prior frame state Output: structured eye, mouth, head, behavior, and quality metrics
Deterministic rules classify fatigue, focus, and risk.
Input: EAR, MAR, head pose, behavior, quality Output: attention state, fatigue score, focus score, alerts
Emotion models run on the face crop, and optional graph models operate on the landmark graph.
Input: aligned face crop, graph data Output: emotion probabilities, node importance, edge attention, AU metrics
The 478 landmarks become a graph with nodes, features, and edges.
Input: landmark coordinates
Output: FaceGraph
The graph is passed to the GNN when a trained checkpoint exists.
Input: face graph Output: graph-level emotion prediction and graph attributions
Geometric AU estimators compute FACS-style units.
Input: landmarks Output: AU presence and intensity
The system produces explanations from GNN attention, node importance, and rule outputs.
Input: model outputs, rules, AU metrics Output: textual and visual explanations
Outputs are fused into a final frame result.
Input: expert system, DL models, GNN, AU, quality Output: consolidated analysis payload
The backend sends JSON and binary responses back to the browser.
Input: fused result Output: JSON analysis + annotated frame
The frontend updates the dashboard, timelines, charts, and the research HUD.
Input: WebSocket payload Output: live UI state
Purpose
Primary webcam emotion model for real-time facial emotion classification.
Architecture
HSEmotion uses an EfficientNet-style backbone trained on AffectNet-8 and deployed through ONNX.
Input
- RGB face crop
- Size: 224 × 224
Output
- 8-class emotion probabilities
- Calibrated top-1 confidence
- Raw confidence
Dataset
AffectNet-8.
Pretraining
Trained externally by the model authors; loaded through hsemotion-onnx.
Advantages
- Fast inference
- Good baseline accuracy
- Easy to deploy
Limitations
- Sensitive to domain mismatch
- Can misclassify smiling faces under poor crop orientation or lighting
- Confidence is not an absolute correctness guarantee
Inference Pipeline
- Convert RGB crop to BGR.
- Run emotion prediction.
- Convert logits to probabilities.
- Calibrate probabilities.
- Return
EmotionPrediction.
Latency
Typically low tens of milliseconds on CPU, depending on crop and hardware.
Memory Usage
Moderate. ONNX runtime is significantly lighter than a full training stack.
Purpose
Alternative CNN-based emotion model for benchmarking and research.
Architecture
EfficientNet-B0-style backbone with a classification head.
Input
224 × 224 face crop.
Output
Emotion probabilities and top-1 label.
Dataset
AffectNet-8 pretrained checkpoint expected.
Pretraining
Fine-tuned weights are expected from Hugging Face or local cache.
Advantages
- Strong research baseline
- Pluggable architecture
- Easier to train/fine-tune than legacy models
Limitations
- The repository currently expects a valid fine-tuned checkpoint.
- If no checkpoint is available, the model load fails rather than silently producing fake outputs.
Inference Pipeline
- Preprocess RGB crop.
- Normalize.
- Forward pass through CNN.
- Softmax to class probabilities.
Latency
Depends on checkpoint and backend environment.
Memory Usage
Higher than HSEmotion due to PyTorch runtime overhead.
Purpose
Learn relational facial behavior from landmark geometry.
Architecture
- Input: 478 nodes with 10-dimensional features
- Several GATv2 layers
- Global mean pooling
- Classification head for emotion prediction
Input
Face graph generated from landmarks.
Output
- Emotion class
- Confidence
- Probability distribution
- Node importance
- Edge attention
Dataset
Designed for facial landmark graph training on emotion datasets such as AffectNet or RAF-DB.
Pretraining
A real checkpoint is required. The repository now gates GNN loading on checkpoint availability.
Advantages
- Captures spatial facial relations
- More interpretable than a black-box CNN alone
- Suitable for research on landmark dynamics
Limitations
- Requires trained weights to be useful
- More sensitive to graph construction quality
- More expensive than simple rules
Inference Pipeline
- Convert landmarks to graph.
- Encode node features.
- Run attention layers.
- Pool node embeddings.
- Predict emotion.
- Extract attention and importance.
Latency
Depends on graph density and hardware.
Memory Usage
Higher than classical rule-based analysis.
Purpose
Baseline GNN architecture for ablation and comparative research.
Architecture
- Graph convolution layers
- Global pooling
- Linear classifier
Advantages
- Simpler than attention-based GNNs
- Useful for model comparison
Limitations
- Lower expressiveness than attention-based variants
- No edge-level attention interpretability
Purpose
Fuse multiple emotion predictions into a single robust output.
Architecture
The ensemble computes a weighted probability mixture and then selects the argmax emotion.
Advantages
- Reduces single-model brittleness
- Allows quality-aware weighting
- Produces uncertainty and disagreement scores
Limitations
- Only improves if multiple models are genuinely trained and loaded
- A “single-model ensemble” is effectively just a fallback
Purpose
Translate landmark geometry into FACS-style action units.
Output
- AU ID
- Name
- Presence boolean
- Intensity from 0.0 to 5.0
Use Cases
- Explain emotion decisions
- Support risk scoring
- Provide human-readable signals
Each landmark is treated as a node:
where:
-
$V$ is the set of landmark nodes -
$E$ is the set of edges connecting facial regions
For each node
where:
-
$x_i, y_i, z_i$ are normalized coordinates -
$\Delta x_i, \Delta y_i$ are temporal displacement components -
$v_i$ is velocity magnitude -
$r_{i,k}$ are region one-hot features
The repository supports three major graph construction families:
-
Anatomical edges
- Derived from face mesh topology
- Preserve anatomical neighborhoods
-
k-NN edges
- Connect each node to its nearest landmarks in 3D space
- Useful when topology should adapt to pose variation
-
Radius edges
- Connect nodes within a distance threshold
- Useful for local structure capture
For a graph attention layer, the attention coefficient between node
where:
-
$h_i$ is the node embedding -
$W$ is a learned linear transform -
$a$ is the attention vector -
$\Vert$ denotes concatenation
The updated embedding is:
Node embeddings represent learned latent facial structure. The embedding norm is used as a proxy for node importance in the current implementation.
Each GNN layer aggregates information from adjacent nodes. This allows local changes around the mouth, eyes, eyebrows, or nose to influence the final prediction.
Global mean pooling produces a graph-level vector:
This pooled representation is classified into emotion classes.
The pooled vector is passed through an MLP head to produce logits and softmax probabilities.
The repository now requires a real checkpoint before enabling GNN inference. This prevents invalid random predictions from being shown as real model output.
The expert system provides deterministic, auditable behavior scoring.
EAR, or Eye Aspect Ratio, estimates eye openness from landmark geometry.
Low EAR indicates eye closure, blink, or fatigue.
MAR, or Mouth Aspect Ratio, estimates mouth openness.
High MAR over sustained frames may indicate yawning.
The system estimates pitch, yaw, and roll using canonical 3D points and solvePnP-style geometry.
Fatigue is computed as a weighted function of eye closure, blink rate, yawning, head pose, and landmark stability.
Focus is derived from forward-facing behavior, eye openness, no-yawn state, and stability.
Stress is inferred indirectly from combinations of head movement, blink rate, low stability, and fatigue-like markers.
Risk rules are priority-based and sorted by severity:
- critical
- high
- medium
- low
Rules generate auditable alerts such as:
- extended eye closure
- head turn
- frequent blinking
- poor image quality
- low facial symmetry
Rule confidence is derived from the magnitude of the violation, clamped to
The first matching high-severity rule can override the attention state. The system never hides deterministic warnings behind model output.
Node importance measures which landmarks contribute most to the GNN prediction.
Attention weights indicate which facial connections matter most to the current graph decision.
The repository includes a lightweight wrapper that extracts top landmarks and summarizes the strongest regions.
Attributions are grouped into facial regions such as eyes, mouth, nose, and eyebrows.
Action Units are used both as features and as explanations for expression decisions.
The frontend visualizer renders node-level hotspots when XAI mode is enabled.
The system can explain outputs using:
- rule triggers
- AU intensities
- graph importance
- probability distributions
Planned explanation methods:
- SHAP
- LIME
- GradCAM
- Integrated Gradients
Current model categories include:
- HSEmotion CNN emotion model
- EfficientFace CNN emotion model
- GNN emotion model
The ensemble computes a weighted mixture of class probabilities:
Raw confidences are calibrated to avoid overconfident predictions.
Uncertainty is derived from the complement of confidence:
A disagreement measure can be approximated with normalized entropy:
The dashboard surfaces a disagreement score so researchers can detect unstable predictions.
The final class is selected by argmax after fusion, not by any single model unless only one model is available.
If only one model is loaded, the ensemble is mathematically a single-model fallback. This is not a bug; it is a configuration reality that should be addressed by training and enabling additional models.
The platform stores session, model, and analytics data in an ORM-backed schema.
| Table | Responsibility |
|---|---|
| users | Authentication and identity |
| organizations | Tenant or org membership |
| analysis_sessions | Session metadata and aggregate metrics |
| analysis_frames | Optional per-frame persistence |
| model_health | Runtime model health and latency |
| session_logs | Structured event logs |
| consent_records | User consent tracking |
- A user can have many sessions.
- An organization can have many users and sessions.
- A session can contain many frames and logs.
- A session can reference model health snapshots.
erDiagram
USERS ||--o{ ANALYSIS_SESSIONS : owns
ORGANIZATIONS ||--o{ USERS : contains
ORGANIZATIONS ||--o{ ANALYSIS_SESSIONS : scopes
ANALYSIS_SESSIONS ||--o{ SESSION_LOGS : emits
ANALYSIS_SESSIONS ||--o{ ANALYSIS_FRAMES : stores
ANALYSIS_SESSIONS ||--o{ MODEL_HEALTH : snapshots
USERS ||--o{ CONSENT_RECORDS : grants
The backend records:
- session start and stop
- aggregate counts
- average EAR / MAR / focus / fatigue
- model health snapshots
- inference timing
- logs and alerts
Typical stored metrics include:
- blink count
- average EAR
- mean head pose values
- average fatigue score
- average focus score
- average inference time
The browser sends JPEG-encoded webcam frames as binary data.
The backend returns the structured analysis payload as JSON.
The annotated frame may be returned as a binary JPEG stream for display.
WebSocket is used because it provides low overhead and stateful connection management suitable for live inference.
Frames are JPEG-compressed in the browser before transmission.
The client uses a requestAnimationFrame loop and a simple in-flight guard to avoid buffer bloat.
Live webcam preview, connection state, frame rate, and overlays.
Session metrics and inferred behavior summaries.
Predicted state, confidence, and previous state tracking.
Temporal history of emotion and behavior signals.
Emotion radar charts and metric plots.
FACS intensity meters and signal summaries.
Research-mode graph overlay with landmark importance.
Attention hotspots for salient landmarks.
Streamed system, model, and alert logs.
Per-model output review and latency comparison.
A more technical view for graph investigation and debugging.
| Variable | Purpose |
|---|---|
DL_ENABLED |
Master switch for deep learning features |
DL_DEVICE |
CPU or CUDA device selection |
DL_EMOTION_MODELS |
Enabled emotion model IDs |
DL_GNN_ENABLED |
Enable graph model loading |
DL_GNN_CHECKPOINT_PATH |
Path to a real trained GNN checkpoint |
DL_ENSEMBLE_STRATEGY |
Fusion strategy |
DL_XAI_ENABLED |
Enable expensive explanations |
DL_MODEL_CACHE_DIR |
Model cache directory |
DL_INFERENCE_TIMEOUT_MS |
Model inference timeout |
DL_DEBUG_MODE |
Save crops and debug artifacts |
DL_GRAPH_EDGE_STRATEGY |
Graph construction mode |
DL_GRAPH_KNN_K |
k-NN parameter |
MAR_YAWN_THRESHOLD |
Mouth opening threshold |
EAR_BLINK_THRESHOLD |
Eye closure threshold |
Model loading is gated by the registry and configuration. The backend only loads a GNN if the checkpoint exists.
The system is configured for CPU-first real-time use, with optional CUDA support.
Thresholds are intentionally conservative and should be tuned using your own webcam dataset.
Debug mode saves crops, frames, and inference logs to backend/debug_inference/.
Structured logging captures model load events, inference details, and warning conditions.
- Threaded execution for analysis
- Lazy model loading
- Quality-aware model gating
- Timeout-based model skipping
The backend is designed to offload frame processing to worker threads so the event loop remains responsive.
The default stack uses CPU-friendly model choices and lightweight geometry pipelines.
Where available, PyTorch and compatible models can be moved to CUDA.
Models are loaded only when needed.
Model weights and MediaPipe assets are cached locally.
Potential future optimization for supported CNN/GNN workloads.
The system is currently frame-oriented rather than batch-oriented, which matches live webcam requirements.
The frontend uses a controlled capture loop, and the backend avoids redundant graph construction where possible.
JWT-based authentication secures API and WebSocket entry points.
Sessions are tied to authenticated identities and organizational context.
The system includes a consent page before camera analysis begins.
This platform is designed for facial behavior analysis, not identity recognition.
- Consent is explicit.
- Analysis should be limited to the stated purpose.
- Retention should be minimized.
The system does not attempt to identify who the user is.
The intended operation is frame analytics, not biometric enrollment.
WebSocket and HTTP deployment should be served over TLS in production.
Covers geometry, rules, model plumbing, and pipeline behavior.
Covers frame processing and end-to-end pipeline flow.
Measures throughput, frame latency, and reliability under live capture.
Should evaluate behavior under noisy frames, low lighting, and camera movement.
Model evaluation should be performed on benchmark datasets and your own collected webcam dataset.
- Python 3.11+
- Node.js 18+
- npm or pnpm
- Optional: CUDA-compatible GPU
cd backend
python3.11 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtcd frontend
npm installEnsure the MediaPipe Face Landmarker file exists:
mkdir -p models
curl -L https://storage.googleapis.com/mediapipe-models/face_landmarker/face_landmarker/float16/1/face_landmarker.task \
-o models/face_landmarker.taskcd backend
source .venv/bin/activate
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000cd frontend
npm run dev./start.shUse the root docker-compose.yml file to run the stack in containers.
The backend exposes standard REST routes for:
- authentication
- consent
- session metadata
- model health
- system health
Endpoint
/ws/analyze?token=...&session_id=...
Client payload
Binary JPEG frame.
Server payload
JSON analysis result and optional annotated frame stream.
The WebSocket requires a valid token and session context.
Client: JPEG frame bytes
Server: analysis_result JSON
Server: annotated JPEG frame
{
"type": "analysis_result",
"payload": {
"face_detected": true,
"deep_learning": {
"emotion_ensemble": {
"final_emotion": "happy",
"confidence": 0.87
}
}
},
"timestamp": "2026-07-10T12:00:00Z"
}- LSTM
- GRU
- Transformer
- ST-GCN
- Graph Transformer
- SHAP
- LIME
- GradCAM
- Integrated Gradients
- Federated Learning
- Edge AI deployment
- Cloud inference scaling
- Clinical validation
- Cross-dataset generalization
- Calibration studies
- Bias and fairness analysis
- Robustness under occlusion and head pose variation
- MediaPipe Face Mesh: https://developers.google.com/mediapipe
- HSEmotion: https://github.com/garychencnu/face-emotion-recognition
- EfficientFace: https://arxiv.org/abs/2104.12119
- Graph Neural Networks: https://arxiv.org/abs/1812.08434
- Graph Attention Networks: https://arxiv.org/abs/1710.10903
- PyTorch Geometric: https://pytorch-geometric.readthedocs.io/
- FACS: https://en.wikipedia.org/wiki/Facial_Action_Coding_System
- AffectNet: https://ibug.doc.ic.ac.uk/resources/affectnet/
- FER2013: https://www.kaggle.com/datasets/msambare/fer2013
- RAF-DB: http://www.whdeng.cn/RAF/model1.html
- OpenCV: https://opencv.org/
- FastAPI: https://fastapi.tiangolo.com/
- React: https://react.dev/
- SQLite: https://www.sqlite.org/
- PostgreSQL: https://www.postgresql.org/
- The GNN must not be enabled without a trained checkpoint.
- Emotion accuracy under webcam conditions depends heavily on crop orientation, lighting, and face alignment.
- Domain mismatch is the most likely cause of low-confidence or wrong emotion labels.
- If the model says sadness on a smiling face, inspect the crop first, then inspect calibration, then inspect training data coverage.
- The system is designed for analysis and research; it should not be used as a sole source of truth for sensitive decisions.
- Single-model emotion inference is not the same as ensemble confidence.
- Visual graph overlays should remain bounded by the viewport and should not scale directly with raw canvas size.
- If the dashboard looks large or distorted, check the visualization projection scale before assuming the model is wrong.
- Use benchmark datasets and your own webcam dataset for calibration.
- Evaluate with confusion matrices, top-1 accuracy, F1 score, calibration error, and latency.
- Include negative examples such as smiles, partial occlusion, and head rotation.
- Separate inference accuracy from explanation quality in evaluations.
AUTHFACEGRAPH AI is a modular, explainable, real-time facial analysis platform that combines deterministic feature engineering, deep learning, graph reasoning, and research-friendly visualization. The current implementation emphasizes robustness, observability, and correctness over fake completeness: a model must be trained, checkpointed, and loaded before it is treated as a valid inference source.
This makes the project suitable for engineering handover, research documentation, and incremental model improvement.