Chandigarh University • Section 407-B • AI Applications Lab
Computer Vision & Deep Learning with YuNet Face Detection & ResNet34 Classification
Team Member 01
UID: 26BCS11206
Team Member 02
UID: 26BCS11208
Team Member 03
UID: 26BCS11224
Team Member 04
UID: 26BCS11230
Core Architecture
YuNet Face Detector + ResNet34 CNN
Transfer learning with PyTorch & Torchvision
Classification Scope
3 Distinct Output Classes
Mask Correct • Mask Incorrect • No Mask
Web Deployment
Flask & Real-Time UI
Dual mode: File upload & live webcam stream
02 • Executive Summary
Post-pandemic safety, healthcare protocols, and industrial cleanrooms mandate compliant facial coverings. Manual inspections are error-prone, labor-intensive, and non-scalable in crowded public domains.
Critical Nuance:
A binary (Mask / No-Mask) model fails when a mask is worn below the nose or chin. MaskAI enforces strict 3-tier classification.
MaskAI combines lightweight face localization (YuNet) with a deep feature extraction backbone (ResNet34) wrapped in a Flask web application.
Modular Pipeline
Decoupled detection and classification ensures high throughput and adaptability.
Multi-Face Processing
Simultaneous bounding box cropping and batch classification per frame.
03 • Classification Scope
Mask completely covers both the nose and the mouth, fitting securely against sides of the face with no gaps.
Diagnostic Rule
Nasal ridge and oral cavity obscured by approved protective fabric.
Mask present on the subject's face but pulled under the nose, pulled down to the chin, or loosely hanging off one ear.
Diagnostic Rule
Mask detected on facial bbox, but key landmarks (nose/mouth) remain exposed.
Face completely exposed with zero protective barrier covering the mouth, nose, or lower facial region.
Diagnostic Rule
Full facial landmarks visible with zero occluding mask contours detected.
04 • Project Goals
OBJECTIVE 01
Implement OpenCV with the YuNet detector to localize faces and extract precise bounding coordinates at high FPS.
OBJECTIVE 02
Leverage a 34-layer residual CNN via PyTorch and Torchvision, replacing the output head to distinguish the 3 mask categories.
OBJECTIVE 03
Harness pre-trained feature weights to maximize generalization, combat overfitting, and accelerate gradient convergence.
OBJECTIVE 04
Build an intuitive Flask server supporting image upload, live webcam streaming, and dynamic rendering of confidence scores and analytics.
05 • System Pipeline
PHASE 1
Webcam video stream or image file uploaded via browser UI.
PHASE 2
OpenCV DNN scans frame to detect faces and compute bounding boxes.
PHASE 3
ROI extraction, PIL conversion, and Torchvision tensor transforms.
PHASE 4
Feedforward pass through 34 residual layers to generate class logits.
PHASE 5
JSON serialization of label, confidence %, and annotated visual display.
06 • Technical Stack
| Technology | Primary Purpose in MaskAI | Domain |
|---|---|---|
| Python | Primary programming language powering model pipelines & server | Core Language |
| PyTorch | Deep learning model building, transfer learning weights & tensor computation | Deep Learning |
| Torchvision | ResNet34 pretrained architecture access & image transformation pipelines | Vision Models |
| OpenCV & YuNet | Fast facial landmarking, ROI extraction & bounding box coordinate math | Computer Vision |
| Flask | Lightweight Python WSGI backend web framework routing API requests | Backend Web |
| NumPy & Pillow | High-speed multi-dimensional array operations & image format conversions | Data Handling |
| HTML / CSS / JS | Responsive client-side interface, video webcam capture & dynamic results | Frontend UI |
07 • Detection Module
YuNet is an ultra-fast, lightweight CNN face detector optimized natively for the OpenCV DNN module (cv::FaceDetectorYN). It is specifically built for real-time edge processing.
Ultra-Lightweight Footprint
Model size under a few megabytes; runs at high frame rates on standard CPU hardware without GPU requirement.
Multi-Scale & Landmark Extraction
Outputs 5 facial landmarks (eyes, nose tip, mouth corners) along with bounding box [x, y, w, h] and detection score.
VIVA CLARIFICATION NOTE
YuNet performs face detection only; it does NOT classify masks. Mask classification is strictly handled by ResNet34.
08 • Data Preprocessing
1. Color Space Conversion (BGR → RGB)
OpenCV reads images in BGR format; converted to RGB via cv2.cvtColor for PyTorch compatibility.
2. Spatial Resizing (transforms.Resize)
Face crops vary in dimension. Standardized to 224×224 pixels, the native input dimension of ResNet34.
3. Tensor Conversion (transforms.ToTensor)
Converts PIL/NumPy arrays [0, 255] to PyTorch float tensors [0.0, 1.0] with shape [C, H, W].
4. Normalization (transforms.Normalize)
Standardized with ImageNet stats: mean=[0.485, 0.456, 0.406] and std=[0.229, 0.224, 0.225].
Key Invariant
Consistent normalization between pretrained weights and runtime inputs is mandatory for accurate inference.
09 • Deep Learning Backbone
Mathematical formulation:
F(x) + x
Instead of learning an underlying mapping H(x), residual blocks fit a residual mapping F(x) = H(x) - x.
10 • Transfer Learning
Rather than training 34 convolutional layers from scratch with random initialization (which leads to severe overfitting on small datasets), MaskAI utilizes pretrained weights from ImageNet-1K.
Low-Level Features (Layers 1-16)
Gradients, edges, fabric textures, skin contours, and geometric shapes transferred directly.
High-Level Features (Layers 17-34)
Complex semantic face patterns adapted to discriminate between covered vs. bare mouth and nose areas.
Critical Viva Point
MaskAI uses a fine-tuned ResNet34 with transfer learning, NOT an experimental scratch CNN or randomly initialized weights.
11 • Server Architecture
WSGI Microframework
Minimal overhead, synchronous and asynchronous request processing directly coupled to PyTorch runtime.
Buffer Ingestion & Decoding
Decodes multipart/form-data images and webcam base64 streams directly into NumPy arrays via OpenCV.
JSON Response Serialization
Packages detection coordinates, predicted labels, confidence percentages, and timestamps to client.
/
Renders the responsive HTML5 interface with webcam feed controls.
/predict_image
Accepts uploaded static image files, runs full detection, returns JSON.
/predict_frame
Consumes real-time video snapshots from browser JS client loop.
12 • User Interface