0% found this document useful (0 votes)
4 views9 pages

Face Mask Detection Using TensorFlow in Python

The document outlines a face mask detection system using TensorFlow and Keras, structured into training and deployment phases. It describes dataset preparation, including data augmentation and a train-test split strategy, as well as the architecture of the CNN model and its training results. Additionally, it details the integration of a Haar Cascade Classifier for real-time face detection and discusses deployment readiness and potential enhancements.

Uploaded by

raja.bala
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views9 pages

Face Mask Detection Using TensorFlow in Python

The document outlines a face mask detection system using TensorFlow and Keras, structured into training and deployment phases. It describes dataset preparation, including data augmentation and a train-test split strategy, as well as the architecture of the CNN model and its training results. Additionally, it details the integration of a Haar Cascade Classifier for real-time face detection and discusses deployment readiness and potential enhancements.

Uploaded by

raja.bala
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Face Mask Detection using

TensorFlow in Python
Build an intelligent computer vision system to detect face masks in real-
time using deep learning and TensorFlow
Two-Phase Detection System
Our face mask detector follows a structured approach that separates training from deployment, ensuring robust and reliable
detection capabilities.

Training Phase Deployment Phase


Load the face mask dataset, train a CNN model using Keras Load the trained mask detector, perform face detection on
and TensorFlow, and serialize the trained detector for images or video streams, and classify each face as
deployment with_mask or without_mask
Dataset Preparation
Initial Dataset Balance Data Augmentation

Our starting dataset contains a well-balanced distribution of We expand our dataset through rotation and flipping
masked and unmasked face images, providing a solid techniques, increasing robustness and generalization
foundation for training. capabilities.

• 690 images with face masks (labeled 'yes') • 2,751 total images after augmentation
• 686 images without masks (labeled 'no') • 1,380 images with masks (50.16%)
• Nearly equal distribution ensures unbiased learning • 1,371 images without masks (49.84%)
Train-Test Split Strategy

80% 20%

Training Set Test Set


2,200 images used to train the CNN model and learn mask 551 images reserved for evaluating model performance on
detection patterns unseen data

This 80-20 split ensures our model has sufficient training data while maintaining a robust test set for validation.
Building the CNN Architecture
Our Sequential CNN model leverages multiple convolutional and pooling layers to extract hierarchical features from face images.

01 02

Convolutional Layers Pooling Layers


Two Conv2D layers with 100 filters and ReLU activation extract MaxPooling2D layers reduce spatial dimensions while preserving
spatial features from 150×150 input images important features

03 04

Flatten & Dropout Dense Layers


Flatten layer converts 2D features to 1D, while 50% dropout Two Dense layers with softmax activation output probability scores
prevents overfitting for mask classification

The model uses Adam optimizer with binary crossentropy loss for efficient two-class classification. Consider using MobileNetV2
for improved accuracy on mobile devices.
Training Results

30 98.86% 96.19%
Training Epochs Training Accuracy Test Accuracy
Model iterations to Validation accuracy on
optimize mask Final accuracy unseen test images
detection accuracy achieved on the
training dataset

The close alignment between training and test accuracy indicates excellent
model generalization without overfitting. Additional epochs could improve
performance, but careful monitoring prevents degradation.
Face Detection Integration
Haar Cascade Classifier Color-Coded Results

We integrate OpenCV's Haar Feature-based Cascade Classifier for robust Visual feedback system for instant recognition:
frontal face detection in real-time video streams.
• GREEN rectangle: Mask detected (label: 1)
The classifier is pre-trained on thousands of positive and negative face • RED rectangle: No mask (label: 0)
images, enabling fast and accurate facial feature detection.

• Uses haarcascade_frontalface_default.xml file


• Detects faces across various angles and lighting conditions
• Provides bounding box coordinates for each detected face
Real-Time Detection Pipeline
Video Capture 1
Initialize webcam stream using OpenCV's VideoCapture
function
2 Face Detection
Apply Haar Cascade Classifier to locate faces in each frame

Preprocessing 3
Extract face ROI, convert to RGB, resize to 224×224, and
normalize pixel values
4 Batch Prediction
Run CNN model on all detected faces simultaneously for
efficient inference
Visualization 5
Draw color-coded bounding boxes with confidence scores on
detected faces
Deployment & Next Steps
Ready for Production Enhancement
Opportunities
Your face mask detector is now
trained and ready to deploy across • Integrate MobileNetV2
multiple platforms. architecture for better mobile
performance
• Works with PC webcams and
• Add multi-angle face detection
smartphone cameras
support
• Processes real-time video
• Implement distance monitoring
streams efficiently
for social distancing
• Provides instant visual
feedback with confidence
• Deploy on edge devices for
scores
offline operation
• Press 'q' key to exit the
• Log detection statistics for
detection loop
compliance reporting

You might also like