https://github.com/subhajit0210/face-mask-detection-using-cnn
This project demonstrates how to build a Face Mask Detection System using CNN
https://github.com/subhajit0210/face-mask-detection-using-cnn
activation-functions cnn convolutional-neural-networks cv2 deep-learning deep-neural-networks face-mask-detection keras loss-functions matplotlib neural-network numpy optimizer python3 sklearn tensorflow
Last synced: 3 months ago
JSON representation
This project demonstrates how to build a Face Mask Detection System using CNN
- Host: GitHub
- URL: https://github.com/subhajit0210/face-mask-detection-using-cnn
- Owner: Subhajit0210
- Created: 2025-05-04T15:51:34.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-05-15T21:23:51.000Z (about 1 year ago)
- Last Synced: 2025-06-22T10:04:18.371Z (about 1 year ago)
- Topics: activation-functions, cnn, convolutional-neural-networks, cv2, deep-learning, deep-neural-networks, face-mask-detection, keras, loss-functions, matplotlib, neural-network, numpy, optimizer, python3, sklearn, tensorflow
- Language: Jupyter Notebook
- Homepage:
- Size: 1.03 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Face Mask Detection using CNN
## Table of Contents
- [Project Overview](#project-overview)
- [Dependencies](#dependencies)
- [Data Collection](#data-collection)
- [Data Preparation](#data-preparation)
- [CNN Model](#cnn-model)
- [Results and Insights](#results-and-insights)
- [Usage](#usage)
- [Contributing](#contributing)
## Project Overview
The goal of this project is to create a model that can accurately detect whether a person in an image is wearing a face mask or not. This is achieved by training a CNN on a dataset of images of people with and without masks. The trained model can then be used to classify new images and predict whether a person is wearing a mask.
## Dependencies
The following libraries are required to run this project:
- TensorFlow
- Keras
- OpenCV
- NumPy
- Matplotlib
- PIL
- Scikit-learn
## Data Collection
The project uses the "Face Mask Dataset" available on Kaggle. This dataset contains images of people wearing and not wearing face masks. It is used to train and evaluate the CNN model. You can download it using the Kaggle API.
* **Source:** Kaggle Datasets
* **Link:** https://www.kaggle.com/datasets/omkargurav/face-mask-dataset
* **Content:** Images of people with and without face masks.
* **Classes:**
* with_mask: Images of individuals wearing face masks correctly.
* without_mask: Images of individuals not wearing face masks.
* mask_weared_incorrect: Images of individuals wearing masks incorrectly (e.g., covering the mouth but not the nose).
* **Size:** 853 images
* **Labeled Objects:** 4072 labeled objects belonging to the 3 classes mentioned above.
* **Image Format:** JPEG
* **Resolution:** Varies
## Data Preparation
* **Download:** The Dataset is downloaded from Kaggle using the Kaggle API.
* **Extract:** The downloaded dataset is extracted.
* **Resize:** All images are resized to 128x128 pixels for consistency.
* **Convert:** Images are converted into NumPy arrays for processing.
* **Label:** Images are labeled as 'with_mask' or 'without_mask'.
* **Split:** Data is split into training and testing sets.
* **Scale:** Pixel values are scaled to a range of 0-1.
## CNN Model
This project employs a Convolutional Neural Network (CNN) to classify images of people with and without masks. CNNs are particularly well-suited for image recognition tasks due to their ability to learn spatial hierarchies of features.
**Model Architecture:**
The CNN model consists of the following layers:
* **Convolutional Layers:** These layers extract features from the input images using learnable filters. We use multiple convolutional layers with increasing filter sizes to capture both low-level and high-level features.
* **Max Pooling Layers:** These layers downsample the feature maps, reducing their dimensionality and computational complexity. They also help to make the model more robust to variations in the input images.
* **Flatten Layer:** This layer converts the multi-dimensional feature maps into a single vector, preparing them for input to the fully connected layers.
* **Fully Connected Layers:** These layers perform the final classification based on the extracted features. We use two fully connected layers with ReLU activation functions, followed by a final output layer with a sigmoid activation function for binary classification (mask or no mask).
## Results and Insights
* **High Accuracy:** Our CNN model achieved over 92% accuracy in detecting face masks.
* **Effective for Real-world Use:** This shows its potential for applications like public health monitoring.
* **Further Improvements:** We can explore data augmentation and model architecture for even better results.
## Usage
To run the project, follow these steps:
1. Clone the repository:
```bash
git clone https://github.com/yourusername/Face-Mask-Detection-using-CNN.git
```
2. Navigate to the project directory:
```bash
cd Face-Mask-Detection-using-CNN
```
4. Run the Jupyter notebook:
```bash
jupyter notebook Face_Mask_Detection_using_CNN.ipynb
```
## Contributing
Contributions are welcome! Please create a new branch for any changes and submit a pull request for review.