Skip to content

HexCrystal69/AirAware

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

5 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

AirAware | Face Mask Detection System ๐Ÿ˜ทโœจ

A real-time face mask detection system that can identify whether a person is wearing a mask, not wearing a mask, or wearing a mask incorrectly using computer vision and deep learning.


๐Ÿš€ Features

  • ๐Ÿ•’ Real-time Detection: Works with webcam for live mask detection
  • ๐Ÿ‘ฅ Multiple Face Support: Detects and classifies multiple faces simultaneously
  • ๐ŸŸข๐ŸŸก๐Ÿ”ด Three-Class Classification:
    • ๐ŸŸข with_mask: Person is wearing a mask correctly
    • ๐Ÿ”ด without_mask: Person is not wearing a mask
    • ๐ŸŸก mask_weared_incorrect: Person is wearing a mask incorrectly
  • ๐Ÿ“ˆ High Accuracy: CNN-based model with data augmentation
  • ๐Ÿ–ฅ๏ธ User-Friendly Interface: Real-time statistics and visual feedback
  • ๐Ÿ“ธ Screenshot Capability: Save detection results as images

๐Ÿ–ฅ๏ธ System Requirements

  • ๐Ÿ Python 3.7 or higher
  • ๐ŸŽฅ Webcam (for real-time detection)
  • ๐Ÿ’พ Sufficient RAM (4GB+ recommended for training)
  • โšก GPU (optional, for faster training)

โš™๏ธ Installation

  1. Clone or download this repository

    git clone https://github.com/HexCrystal69/AirAware.git
  2. Install dependencies:

    pip install -r requirements.txt
  3. Verify installation:

    python -c "import tensorflow, cv2, numpy; print('All dependencies installed successfully!')"

๐Ÿ—‚๏ธ Dataset Structure

The system expects the following dataset structure:

data/
โ”œโ”€โ”€ images/
โ”‚   โ”œโ”€โ”€ maksssksksss0.png
โ”‚   โ”œโ”€โ”€ maksssksksss1.png
โ”‚   โ””โ”€โ”€ ... (all PNG images)
โ””โ”€โ”€ annotations/
    โ”œโ”€โ”€ maksssksksss0.xml
    โ”œโ”€โ”€ maksssksksss1.xml
    โ””โ”€โ”€ ... (corresponding XML annotations)

๐Ÿ› ๏ธ Usage

1๏ธโƒฃ Training the Model

To train the mask detection model:

python train.py

This will:

  • ๐Ÿ“ฅ Load and preprocess the dataset from data/ folder
  • ๐Ÿ—๏ธ Create a CNN model with data augmentation
  • ๐Ÿƒ Train the model with early stopping and learning rate scheduling
  • ๐Ÿ’พ Save the best model as mask_detector_model.h5
  • ๐Ÿ–ผ๏ธ Generate training plots (training_history.png)
  • ๐Ÿ“Š Create a confusion matrix (confusion_matrix.png)
  • ๐Ÿ“ Print evaluation metrics

Training Parameters:

  • โณ Epochs: 50 (with early stopping)
  • ๐Ÿ“ฆ Batch Size: 32
  • ๐Ÿšฆ Learning Rate: 0.001 (with reduction on plateau)
  • ๐Ÿ”„ Data Augmentation: Rotation, shifts, flips, zoom, brightness

2๏ธโƒฃ Real-time Detection

To run real-time mask detection with your webcam:

python run_detection.py

Advanced Options:

# Use a different model file
python run_detection.py --model my_custom_model.h5

# Use a different camera (if you have multiple cameras)
python run_detection.py --camera 1

# Adjust confidence threshold
python run_detection.py --confidence 0.8

# Hide FPS and statistics display
python run_detection.py --no-fps

Real-time Controls:

  • ๐Ÿ…€ q: Quit detection
  • ๐Ÿ’พ s: Save screenshot
  • โ„น๏ธ h: Show help

3๏ธโƒฃ Image-based Detection

To test the system on a single image:

python src/mask_classifier.py

Then enter the path to your image when prompted.


๐Ÿง  Model Architecture

The CNN model consists of:

  • ๐Ÿงฑ 4 Convolutional Blocks with increasing filters (32โ†’64โ†’128โ†’256)
  • ๐Ÿงช Batch Normalization for stable training
  • ๐ŸŠ MaxPooling for dimension reduction
  • ๐Ÿ›ก๏ธ Dropout for regularization
  • ๐Ÿข Dense Layers (512โ†’256โ†’3) for classification
  • ๐Ÿงฎ Softmax activation for multi-class output

๐Ÿ“Š Performance

The system typically achieves:

  • ๐Ÿ† Training Accuracy: 95%+
  • ๐Ÿฅˆ Validation Accuracy: 90%+
  • โšก Real-time FPS: 15-30 FPS (depending on hardware)
  • ๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ Face Detection: Works with multiple faces simultaneously

๐Ÿ“ File Structure

Face Mask Detection System/
โ”œโ”€โ”€ data/                          # Dataset folder
โ”‚   โ”œโ”€โ”€ images/                    # PNG images
โ”‚   โ””โ”€โ”€ annotations/               # XML annotations
โ”œโ”€โ”€ src/                          # Source code
โ”‚   โ”œโ”€โ”€ realtime_detection.py     # Real-time detection
โ”‚   โ”œโ”€โ”€ mask_classifier.py        # Image-based detection
โ”‚   โ”œโ”€โ”€ face_detector.py          # Face detection utilities
โ”‚   โ””โ”€โ”€ utils.py                  # Data loading and utilities
โ”œโ”€โ”€ train.py                      # Complete training script
โ”œโ”€โ”€ run_detection.py              # Simple detection launcher
โ”œโ”€โ”€ requirements.txt              # Python dependencies
โ””โ”€โ”€ README.md                     # This file

๐Ÿ›‘ Troubleshooting

โš ๏ธ Common Issues

  1. โŒ "Model file not found"

    • Make sure you've trained the model first using python train.py
  2. ๐Ÿ“ท "Could not open camera"

    • Check if your webcam is connected and not being used by another application
    • Try different camera indices: --camera 1, --camera 2, etc.
  3. ๐Ÿ–ผ๏ธ "No images found in dataset"

    • Ensure your dataset is in the correct structure under data/ folder
    • Check that images are in PNG format
  4. ๐Ÿข Low FPS

    • Close other applications using the camera
    • Reduce image resolution in the code
    • Use a GPU for faster inference
  5. ๐ŸŽฏ Poor detection accuracy

    • Retrain the model with more data
    • Adjust confidence threshold
    • Ensure good lighting conditions

๐Ÿ’ก Performance Tips

  • ๐Ÿ”† For better accuracy: Use good lighting and face the camera directly
  • ๐Ÿš€ For faster processing: Close unnecessary applications
  • ๐Ÿ‘€ For multiple faces: Ensure all faces are clearly visible
  • ๐Ÿ–ฅ๏ธ For training: Use GPU acceleration if available

๐Ÿ› ๏ธ Customization

โž• Adding New Classes

To add new mask types, modify src/utils.py:

CLASSES = ['with_mask', 'without_mask', 'mask_weared_incorrect', 'new_mask_type']

๐Ÿ—๏ธ Adjusting Model Architecture

Modify the create_model() function in src/train_model.py to change the CNN architecture.

๐ŸŽ›๏ธ Changing Detection Parameters

Adjust face detection parameters in src/face_detector.py:

faces = detect_faces(frame, scaleFactor=1.1, minNeighbors=5)

๐Ÿค Contributing

Feel free to contribute to this project by:

  • ๐Ÿž Reporting bugs
  • ๐Ÿ’ก Suggesting new features
  • ๐Ÿ“ Improving documentation
  • โšก Optimizing performance

๐Ÿ“„ License

This project is open source and available under the MIT License.


๐Ÿ™ Acknowledgments

  • ๐Ÿ“š Dataset: Face Mask Detection Dataset
  • ๐Ÿ‘๏ธ Face Detection: OpenCV Haar Cascades
  • ๐Ÿง  Deep Learning Framework: TensorFlow/Keras
  • ๐Ÿ–ผ๏ธ Computer Vision: OpenCV

About

AirAware is a real-time face mask detection system using deep learning, identifying correct, incorrect, or absent mask usage with webcam support.

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages