This project implements a face mask detection system using a Convolutional Neural Network (CNN) with a pre-trained VGG16 model. The model is designed to identify whether a person is wearing a mask or not, utilizing OpenCV for real-time face detection.
To set up the project, clone this repository and install the required dependencies:
git clone https://github.com/Warishayat/Face-Mask-Detection.git
cd Face-Mask-Detection
pip install -r requirements.txt
- Python 3.x
- OpenCV
- TensorFlow/Keras
- NumPy
- Matplotlib (optional for visualizations)
The model is trained on a balanced dataset obtained from Kaggle, which contains images of individuals wearing masks and those without masks. Ensure the dataset is organized properly for training.
- Load the VGG16 model pre-trained on ImageNet.
- Modify the output layers for binary classification (mask vs. no mask).
- Train the model for 5 epochs, achieving approximately 90% accuracy.
The training script is located in train.py
. You can adjust hyperparameters as needed.
The project utilizes OpenCV for real-time face detection with the Haar Cascade frontal face detection model.
The detection script is found in detect.py
. Start the detection by running:
python detect.py
Ensure your camera is connected and accessible.
- Clone the repository and install dependencies.
- Place the trained mask detection model in the correct directory.
- Run the training script if you wish to retrain the model.
- Use the detection script for real-time mask detection.
The model achieved a training accuracy of 90% after 5 epochs. Real-time detection effectively identifies individuals with or without masks in live video feeds.
Contributions are welcome! If you have suggestions for improvements or new features, feel free to open an issue or submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for more details.