This repository contains a Python script to train a mask detection model and a web application to test if a person is wearing a mask or not.
From the given link Download the DataSet https://www.kaggle.com/datasets/omkargurav/face-mask-dataset and store it in the root folder. folder Structure will be like
data-
├───without_mask
└───with_mask
To train and save the model, follow these steps:
-
Install Dependencies: Ensure you have the necessary dependencies installed. You can install them using pip:
pip install -r requirements.txt
-
Train and Save Model: Run the
main.py
script to train the model and save it to the root folder:python main.py
The trained model will be saved as
mask-detection-model.h5
.
To run the web application, follow these steps:
-
Start the Web App: Start the Flask web application by running the
app.py
script:python app.py
-
Access the Web App: Open a web browser and go to http://localhost:5000 to access the web application.
-
Upload an Image: Upload an image of a person to the web application.
-
Detect Mask: Click the "Upload and Detect" button.
-
View Results: The application will process the image and display the result, indicating whether the person in the image is wearing a mask or not.
main.py
: Python script to train the mask detection model and save it.app.py
: Python script for the Flask web application.data/
: Directory containing the dataset of images with and without masks.templates/
: Directory containing HTML templates for the web application.static/
: Directory for static files used in the web application.mask-detection-model.h5
: The trained model file.
- Python 3.x
- TensorFlow
- Keras
- Flask
- Pillow (PIL)
- scikit-learn
The dataset used for training the model is located in the data/
directory. It includes images of people with and without masks.
This project is licensed under the MIT License. As an academic project, you are encouraged to adapt and use this code for educational purposes. Please check the LICENSE file for full details.