Skip to content

sofialtamsh/Face_Mask_Detection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

😷 Face Mask Detection

A computer vision project that detects whether a person is wearing a face mask or not using machine learning and image processing techniques.

📌 Features

  • Detects face with mask and face without mask
  • Uses computer vision & deep learning
  • Real-time detection (if webcam enabled)
  • Easy to train and test

🛠️ Tech Stack

  • Python
  • OpenCV
  • TensorFlow / Keras
  • NumPy
  • Matplotlib

📁 Project Structure

Face_Mask_Detection/
│
├── dataset/
│   ├── with_mask/
│   └── without_mask/
├── model/
├── train_model.py
├── detect_mask.py
├── requirements.txt
└── README.md

⚙️ Setup Instructions

1️⃣ Clone the Repository

git clone https://github.com/sofialtamsh/Face_Mask_Detection.git

2️⃣ Create a Virtual Environment (Recommended)

python -m venv venv

3️⃣ Activate the Virtual Environment

Windows:

venv\Scripts\activate

macOS/Linux:

source venv/bin/activate

4️⃣ Install Dependencies

pip install -r requirements.txt

🚀 Usage

🔹 1. Train the Model

python train_model.py
  • Loads images from the dataset
  • Trains the CNN model
  • Saves the trained model in model

🔹 2. Run Face Mask Detection

python detect_mask.py

Uses webcam or video feed, Detects faces in real-time

Displays:

  • Green box → Mask detected
  • Red box → No mask detected
  • Press ESC to quit

🖼️ Example Output

[INFO] Starting video stream...
[INFO] Mask detected with 98.45% confidence

On-screen:

  • Bounding box around face
  • Label: Mask / No Mask
  • Confidence percentage

📊 Dataset Format

Ensure your dataset is structured as follows:

dataset/
├── with_mask/
│   ├── img1.jpg
│   ├── img2.jpg
│   └── ...
└── without_mask/
    ├── img1.jpg
    ├── img2.jpg
    └── ...

Guidelines:

  • Images should be clear and front-facing when possible
  • Supported formats: .jpg, .png
  • Balanced classes improve model accuracy

🧠 Model Architecture

  • Convolutional Neural Network (CNN)
  • Image preprocessing using OpenCV
  • Binary classification:
  • With Mask
  • Without Mask
  • Trained using TensorFlow/Keras
  • Model saved in the model/ directory after training

📦 Dependencies

TensorFlow
OpenCV-Python
NumPy
Matplotlib
Scikit-learn

📝 Notes

  • Always activate the virtual environment before running scripts
  • Ensure proper lighting for better face detection
  • You can improve accuracy by adding more training images

🤝 Contributing

Pull requests are welcome!
For major changes, please open an issue first to discuss what you’d like to change.

🪪 License

MIT License © 2025 Sofi Altamsh

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages