A comprehensive face mask detection system built with deep learning that can classify images of faces to determine mask-wearing status. The system uses transfer learning with MobileNetV3 architecture to efficiently identify whether individuals are wearing masks properly, improperly, or not at all.
This project implements a face mask detection system using advanced deep learning techniques, particularly relevant for public health monitoring and mask compliance verification. The system provides real-time detection capabilities through an intuitive GUI interface built with Tkinter.
face.demo.mp4
- Binary Classification: Accurately detects "with_mask" vs "without_mask" status
- High Performance: Achieves 100% accuracy on test dataset
- Real-time Detection: Interactive GUI for immediate image analysis
- Transfer Learning: Leverages pre-trained MobileNetV3 for efficient training
- User-friendly Interface: Simple Tkinter-based GUI with visual feedback
- Robust Preprocessing: Comprehensive data augmentation and preprocessing pipeline
- TensorFlow/Keras: Deep learning framework for model development and training
- Kaggle Environment: Cloud platform for dataset access and model training
- Tkinter: Python GUI framework for desktop application interface
- OpenCV: Image processing and computer vision operations
- NumPy: Numerical computations and array operations
- Matplotlib: Data visualization and result plotting
The system utilizes MobileNetV3 as the backbone network, chosen for its optimal balance between accuracy and computational efficiency.
-
Input Layer
- Accepts RGB images (224×224×3)
- Standardized input format for consistent processing
-
Initial Convolutional Layer
- Standard convolution (not depthwise separable)
- 3×3 kernel with stride 2
- Batch normalization and ReLU6 activation
-
Bottleneck Blocks
- Core building blocks with three operations:
- 1×1 expansion convolution
- 3×3 depthwise convolution (spatial filtering)
- 1×1 projection convolution
- Residual connections for gradient flow
- ReLU6 activation functions
- Core building blocks with three operations:
-
Global Average Pooling
- Reduces spatial dimensions to 1×1
- Minimizes overfitting risk
- Efficient parameter reduction
-
Fully Connected Layer
- Dense layer for feature mapping
- Connects to binary classification output
-
Softmax Layer
- Probability distribution output
- Binary classification: with_mask / without_mask
Input Image → Preprocessing → Dataset Partitioning → Training/Validation/Testing
↓
Classification ← Trained Model ← MobileNetV3 Training
- Data Preprocessing: Image normalization, resizing, and augmentation
- Dataset Partitioning: Train/validation/test split for robust evaluation
- Model Training: Transfer learning with MobileNetV3 base
- Validation: Performance monitoring during training
- Testing: Final model evaluation on unseen data
- Classification: Real-time prediction on new images
- Overall Accuracy: 100%
- Precision:
- With Mask: 99%
- Without Mask: 100%
- Recall:
- With Mask: 100%
- Without Mask: 99%
- F1-Score: 100% for both classes
- True Positives (with_mask): 572
- True Negatives (without_mask): 543
- False Positives: 2
- False Negatives: 3
- Total Test Samples: 1,120
The system features an intuitive Tkinter-based desktop application with:
- Image Selection: Browse and load images for analysis
- Real-time Detection: Instant mask detection with confidence scores
- Visual Feedback:
- Red bounding box for "without_mask" (100% confidence)
- Green bounding box for "with_mask" (100% confidence)
- Detection Statistics:
- Total faces detected
- Percentage breakdown of mask/no-mask detection
- Processing status indicators
- Model loading section with file path display
- Image display area with detection overlays
- Results panel showing detection statistics
- Control buttons for image selection and detection execution
-
Clone the Repository
git clone https://github.com/esraamhmd/FaceMaskDetector.git cd FaceMaskDetector -
Install Dependencies
pip install tensorflow opencv-python tkinter numpy matplotlib pillow
-
Download Pre-trained Model
- Ensure the trained model file (
face_mask_mobilenetV3.h5) is in the project directory - Model can be downloaded from the releases section or trained using the provided notebook
- Ensure the trained model file (
python face_mask_detector_gui.py- Load Model: Click "Load Model" to initialize the pre-trained model
- Select Image: Choose an image file for mask detection
- Detect Masks: Click "Detect Masks" to analyze the selected image
- View Results: Check detection results in the statistics panel
- JPEG (.jpg, .jpeg)
- PNG (.png)
- BMP (.bmp)
- TIFF (.tiff)
FaceMaskDetector/
├── face_mask_detector_gui.py # Main GUI application
├── model_training.ipynb # Training notebook
├── face_mask_mobilenetV3.h5 # Trained model weights
├── requirements.txt # Project dependencies
├── README.md # Project documentation
└── sample_images/ # Test images directory
The model training process includes:
- Data Augmentation: Rotation, scaling, brightness adjustment
- Transfer Learning: Fine-tuning MobileNetV3 pre-trained weights
- Optimization: Adam optimizer with learning rate scheduling
- Regularization: Dropout and batch normalization for generalization
- Early Stopping: Prevents overfitting during training
- Public Health Monitoring: Automated mask compliance checking
- Security Systems: Integration with surveillance cameras
- Educational Tools: Demonstration of computer vision concepts
- Research Platform: Base for advanced face detection research
The system can be extended for:
- Multi-class Detection: Proper/improper mask wearing classification
- Real-time Video: Webcam integration for live detection
- Mobile Deployment: Conversion to mobile-friendly formats
- API Integration: RESTful service for web applications
- Fork the repository
- Create a feature branch (
git checkout -b feature/new-feature) - Commit your changes (
git commit -am 'Add new feature') - Push to the branch (
git push origin feature/new-feature) - Create a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Esraa Mohammed - GitHub Profile
- TensorFlow team for the MobileNetV3 architecture
- Kaggle community for dataset resources and compute environment
- OpenCV contributors for computer vision tools
- Public health organizations inspiring this COVID-19 era project
For questions, suggestions, or collaborations:
- Open an issue on GitHub
- Contact the repository owner through GitHub
⭐ Star this repository if you find it helpful for your projects!