A real-time face mask detection system using deep learning and computer vision to identify whether people are wearing face masks. Built with TensorFlow, OpenCV, and Streamlit.
- Real-time Detection: Detect face masks in uploaded images with bounding boxes and confidence scores
- User-Friendly Interface: Interactive Streamlit web application for easy image uploads
- High Accuracy: Uses MobileNetV2 architecture for efficient and accurate predictions
- Visual Feedback: Color-coded bounding boxes (Green for mask, Red for no mask)
- Confidence Scores: Displays prediction confidence percentage for each detection
- Deep Learning: TensorFlow/Keras with MobileNetV2
- Computer Vision: OpenCV for image processing and face detection
- Frontend: Streamlit for the web interface
- Model: Pre-trained face detector with custom mask classification model
- Python 3.8 or higher
- pip package manager
- Clone the repository:
git clone https://github.com/CodeBalch25/Face_Mask_Detection_Python.git
cd Face_Mask_Detection_Python
- Install dependencies:
pip install -r requirements.txt
-
Download the required model files:
- Place
face_mask_detector.model
in the root directory - Place face detector files in
face_detector/
directory:deploy.prototxt
res10_300x300_ssd_iter_140000.caffemodel
- Place
-
Create the necessary directories:
mkdir images
mkdir face_detector
Run the Streamlit application:
streamlit run app.py
The application will open in your browser at http://localhost:8501
- Select "Image" from the sidebar
- Upload an image (JPG or PNG format)
- Click "Process" to detect face masks
- View the results with bounding boxes and confidence scores
Face_Mask_Detection_Python/
├── app.py # Main Streamlit application
├── detect_mask_in_image.py # Image detection module
├── detect_mask_in_video.py # Video detection module (future feature)
├── searching_face.py # Face search utilities
├── training_detection.py # Model training script
├── requirements.txt # Python dependencies
├── face_detector/ # Pre-trained face detector models
│ ├── deploy.prototxt
│ └── res10_300x300_ssd_iter_140000.caffemodel
├── images/ # Temporary image storage
└── README.md # Project documentation
- Face Detection: Uses OpenCV's DNN module with a pre-trained Caffe model to detect faces
- Preprocessing: Detected faces are extracted, resized to 224x224, and preprocessed for the neural network
- Classification: MobileNetV2-based model classifies each face as "Mask" or "No Mask"
- Visualization: Draws bounding boxes with labels and confidence scores on the original image
- Base Model: MobileNetV2 (pre-trained on ImageNet)
- Input Size: 224x224x3
- Output: Binary classification (Mask / No Mask)
- Face Detector: SSD (Single Shot Detector) with ResNet-10 backbone
- [ ] Real-time webcam detection
- Batch processing for multiple images
- Mobile app deployment
- Dataset expansion for improved accuracy
- Support for different mask types
Detection Pipeline:
- Image input → Blob conversion
- Face detection using DNN
- ROI extraction and preprocessing
- Mask classification
- Result visualization
Performance:
- Detection confidence threshold: 0.5
- Image preprocessing: BGR to RGB conversion
- Real-time capable on modern hardware
Contributions are welcome! Please feel free to submit a Pull Request.
This project is open source and available under the MIT License.
Timothy Balch - @CodeBalch25
- TensorFlow team for the MobileNetV2 architecture
- OpenCV community for computer vision tools
- Streamlit for the excellent web framework
machine-learning
computer-vision
tensorflow
opencv
covid19
deep-learning
streamlit
python
face-detection
image-classification