Skip to content

Prabinkarki67/Mask-Prediction

Repository files navigation

Face Mask Detection

A simple Convolutional Neural Network (CNN) project to detect whether a person is wearing a mask or not wearing a mask using images. The project is based on a publicly available Kaggle dataset.

Main Code

  • code.ipynb → This is the main notebook.
    It contains all steps:
    1. Loading and preprocessing the dataset (Train, Validation, Test)
    2. Training the CNN model
    3. Evaluating the model
    4. Testing single images
    5. (Optional) Real-time webcam detection

Users should open this notebook first and run all cells sequentially.

Dataset

The project uses the Face Mask Detection dataset from Kaggle.
The dataset is structured into three folders: Train/ Test/ Validation/

Each folder contains two classes:

  • with_mask – Images of people wearing masks
  • without_mask – Images of people not wearing masks

Dataset Source

Kaggle - Face Mask Detection

(Download and unzip the dataset into your project directory.)

Project Folder Structure

Face-Mask-Detection/ │ ├─ dataset/ │ ├─ Train/ │ │ ├─ with_mask/ │ │ └─ without_mask/ │ ├─ Validation/ │ │ ├─ with_mask/ │ │ └─ without_mask/ │ └─ Test/ │ ├─ with_mask/ │ └─ without_mask/ │ ├─ model/ │ └─ face_mask_model.h5 │ ├─ train.py ├─ evaluate.py ├─ detect_mask_webcam.py # optional real-time detection └─ README.md

Requirements

  • Python 3.x
  • TensorFlow / Keras
  • OpenCV
  • NumPy
  • Matplotlib (optional, for visualizations)

Installation

Clone the repo:

git clone https://github.com/yourusername/Face-Mask-Detection.git
cd Face-Mask-Detection

Usage Instructions

To run the model:

  • Open code.ipynb in Jupyter/VSCode
  • Execute all cells in order
  • Model trains, evaluates, and saves as maskDetector.h5
  • Test images directly in notebook

For webcam detection (optional):

  • Run the webcam section in notebook
  • Face detection with OpenCV
  • Real-time mask classification
  • Green/Red indicators for mask status
  • Press 'q' to quit

CNN Architecture

Input: (256, 256, 3) ├── Conv2D (32 filters, 3×3) → ReLU ├── MaxPooling2D (2×2) ├── Conv2D (64 filters, 3×3) → ReLU ├── MaxPooling2D (2×2) ├── Conv2D (128 filters, 3×3) → ReLU ├── MaxPooling2D (2×2) ├── Flatten ├── Dense (128 units) → ReLU ├── Dense (64 units) → ReLU └── Dense (1 unit) → Sigmoid

🔧 Training Configuration

  • Optimizer: Adam
  • Loss Function: Binary Crossentropy
  • Metrics: Accuracy
  • Epochs: 20
  • Batch Size: 32
  • Validation Split: 20%


License

This project is licensed under the MIT License - see the LICENSE file for details.

Author

Prabin Karki
GitHub


Dataset: Kaggle - Face Mask Detection
Code: code.ipynb • Model: maskDetector.h5

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published