VALENCE

VALENCE - Real-Time Facial Emotion Detection AI Platform Case Study Hero Cover
AI / Computer Vision Platform

VALENCE

Real-Time Facial Emotion Detection AI Platform

Editorial Case Review

VALENCE is an end-to-end affective computing platform that classifies human facial expressions into 7 universal emotion categories in real time. The system is powered by a custom ResNet-18 backbone augmented with a CBAM attention module, trained on FER-2013 and AffectNet using Multi-class Focal Loss. The backend is FastAPI with asyncio.to_thread CPU offloading and a bounded WebSocket queue. The frontend features a live canvas webcam overlay, multi-face image analyzer, video timeline scrubber, and real-time dashboard.

Core Capabilities

Live webcam

Live webcam emotion tracking over WebSockets with EMA temporal smoothing

Multi-face detection

Multi-face detection on images up to 4K with per-face probability breakdowns

Frame-by-frame video

Frame-by-frame video analysis generating emotion arc timelines

Custom ResNet-18

Custom ResNet-18 + CBAM attention model achieving 67.6% accuracy on 7 emotions

30% structured

30% structured pruning & calibrated logit adjustment for CPU-optimized deployment

Real-time system

Real-time system health dashboard tracking model status and session analytics

Engineering Case Study

The Challenge

Achieving sub-60ms real-time inference on CPU, handling severe class imbalance (Disgust had 16× fewer samples than Happy), and preventing WebSocket frame queue buildup during sustained live streaming.

The Solution

Applied 30% L1 structured pruning and pinned PyTorch to 2 CPU threads reducing latency from 2,580ms to ~16ms. Solved class imbalance with Multi-class Focal Loss (γ=2.0), inverse-frequency class weights, and logit prior adjustment (τ=0.30). Eliminated queue buildup using asyncio.Queue(maxsize=1) to auto-drop stale frames.

Development Journey & Milestones

Phase 01

Architecture & System Design

Structured the schema for VALENCE, defining state management patterns and API route handlers.

Phase 02

Full-Stack Implementation

Engineered core features using PyTorch, FastAPI, OpenCV (YuNet) with component modularity.

Phase 03

Performance & Optimization

Applied server-side rendering, debounced event flows, and asset compression for top Lighthouse scores.

Phase 04

Deployment & CI/CD Telemetry

Deployed live production build with continuous integration and automated telemetry tracking.

Key Specifications

Your RoleAI/ML Engineer & Full-Stack Developer
Timeline8 Weeks (2026)
CategoryAI / Computer Vision Platform

Built With

PyTorchFastAPIOpenCV (YuNet)Next.js (App Router)TypeScriptWebSocketsSQLite (WAL)Docker

Product Performance

85%
~56ms (CPU)End-to-end inference latency
68%
67.6% (7-class)Model test accuracy
68%
0.68Weighted F1 Score
97%
~16ms on CPUNeural forward pass
0%
0% latency driftWebSocket frame drop rate

Local Setup Commands

bash — setup
git clone https://github.com/Rameshwar-bhagwat10/Emotion-Detection-AI.git
cd valence
npm install
npm run dev

Interface Gallery

VALENCE - Landing Interface and System Overview (Desktop Screen 1)