Skip to content

Ziadelshazly22/FaceMaskDetectionTool_NTI_Project

Repository files navigation

Face Mask Detection Streamlit App 😷

A modern, interactive web application for detecting face masks in images using deep learning with VGG19 architecture.

🚀 Features

  • Real-time Mask Detection: Upload images and get instant predictions
  • Interactive UI: Beautiful, modern interface with animations and visual feedback
  • Confidence Scoring: See how confident the model is in its predictions
  • Multiple Pages: Home, Detection, Model Info, and About sections
  • Responsive Design: Works on desktop and mobile devices
  • Visual Analytics: Interactive charts and gauges for prediction confidence

🛠️ Technology Stack

  • Frontend: Streamlit with custom CSS styling
  • Backend: TensorFlow/Keras
  • Model: VGG19 with Transfer Learning
  • Image Processing: OpenCV, PIL
  • Visualization: Plotly
  • UI Components: Streamlit Option Menu

📋 Prerequisites

  • Python 3.8 or higher
  • Virtual environment (recommended)
  • At least 4GB RAM (for TensorFlow)
  • vgg19_face_mask_model.keras model file ⚠️ See MODEL_DOWNLOAD.md

🔧 Installation & Setup

Step 1: Clone or Download

Make sure you have all the project files in your directory:

  • app.py (main Streamlit application)
  • requirements.txt (dependencies)
  • vgg19_face_mask_model.keras (trained model) ⚠️ Download Required
  • README.md (this file)

Step 2: Create Virtual Environment

# Navigate to project directory
cd "c:\Users\Ziad mahmoud\Downloads\MaskDetection project"

# Create virtual environment
py -m venv mask_detection_env

# Activate virtual environment
# On Windows:
mask_detection_env\Scripts\activate

# On macOS/Linux:
# source mask_detection_env/bin/activate

Step 3: Install Dependencies

# Make sure your virtual environment is activated
pip install -r requirements.txt

Step 4: Run the Application

streamlit run app.py

The app will automatically open in your default web browser at http://localhost:8501

📱 How to Use

  1. Launch the App: Run the command above and navigate to the provided URL
  2. Navigate: Use the horizontal menu to switch between different sections
  3. Upload Image: Go to "Detection" tab and upload an image with a face
  4. Get Prediction: Click "Detect Mask" to analyze the image
  5. View Results: See the prediction with confidence score and visual feedback

🎯 Usage Tips

  • Image Quality: Use clear, well-lit images for best results
  • Face Visibility: Ensure the face is clearly visible and not too small
  • Supported Formats: JPG, JPEG, PNG, BMP, TIFF
  • Single Face: Works best with one face per image

📊 Model Information

  • Architecture: VGG19 with custom classifier layers
  • Training: Transfer learning from ImageNet
  • Input Size: 224 × 224 × 3 pixels
  • Output: Binary classification (Mask/No Mask)
  • Accuracy: ~93-95% on validation data

🐛 Troubleshooting

Common Issues:

  1. Model Not Found

    Error: Model could not be loaded
    
    • Ensure vgg19_face_mask_model.keras is in the same directory as app.py
  2. Import Errors

    ModuleNotFoundError: No module named 'streamlit'
    
    • Make sure virtual environment is activated
    • Run pip install -r requirements.txt
  3. Memory Issues

    ResourceExhaustedError: OOM when allocating tensor
    
    • Close other applications to free up RAM
    • Use smaller images or restart the app
  4. Port Already in Use

    Port 8501 is already in use
    
    • Use a different port: streamlit run app.py --server.port 8502
    • Or kill the existing process

🔧 Configuration

You can customize the app by modifying these parameters in app.py:

  • Image Size: Change (224, 224) in the preprocess_image function
  • Confidence Threshold: Modify 0.5 in the predict_mask function
  • Styling: Update the CSS in the st.markdown section
  • Colors: Change color schemes in the CSS classes

📂 Project Structure

MaskDetection project/
├── app.py                          # Main Streamlit application
├── requirements.txt                # Python dependencies
├── vgg19_face_mask_model.keras    # Trained model file
├── README.md                       # Project documentation
├── mask_detection_env/             # Virtual environment (created after setup)
└── VGG19_MaskDetection_ZiadMahmoudElShazly.ipynb  # Training notebook

🤝 Contributing

Feel free to contribute to this project by:

  • Reporting bugs
  • Suggesting new features
  • Improving the UI/UX
  • Optimizing model performance

📄 License

This project is for educational and research purposes.

👨‍💻 Developer

Ziad Mahmoud ElShazly Email: ziad.m.elshazly@gmail.com

Built with ❤️ using Streamlit, TensorFlow, and Python

🔄 Version History

  • v1.0: Initial release with basic mask detection
  • v1.1: Added interactive UI and confidence scoring
  • v1.2: Enhanced styling and multiple page navigation

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors