A modern, interactive web application for detecting face masks in images using deep learning with VGG19 architecture.
- 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
- 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
- Python 3.8 or higher
- Virtual environment (recommended)
- At least 4GB RAM (for TensorFlow)
vgg19_face_mask_model.kerasmodel file⚠️ See MODEL_DOWNLOAD.md
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 RequiredREADME.md(this file)
# 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# Make sure your virtual environment is activated
pip install -r requirements.txtstreamlit run app.pyThe app will automatically open in your default web browser at http://localhost:8501
- Launch the App: Run the command above and navigate to the provided URL
- Navigate: Use the horizontal menu to switch between different sections
- Upload Image: Go to "Detection" tab and upload an image with a face
- Get Prediction: Click "Detect Mask" to analyze the image
- View Results: See the prediction with confidence score and visual feedback
- 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
- 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
-
Model Not Found
Error: Model could not be loaded- Ensure
vgg19_face_mask_model.kerasis in the same directory asapp.py
- Ensure
-
Import Errors
ModuleNotFoundError: No module named 'streamlit'- Make sure virtual environment is activated
- Run
pip install -r requirements.txt
-
Memory Issues
ResourceExhaustedError: OOM when allocating tensor- Close other applications to free up RAM
- Use smaller images or restart the app
-
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
- Use a different port:
You can customize the app by modifying these parameters in app.py:
- Image Size: Change
(224, 224)in thepreprocess_imagefunction - Confidence Threshold: Modify
0.5in thepredict_maskfunction - Styling: Update the CSS in the
st.markdownsection - Colors: Change color schemes in the CSS classes
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
Feel free to contribute to this project by:
- Reporting bugs
- Suggesting new features
- Improving the UI/UX
- Optimizing model performance
This project is for educational and research purposes.
Ziad Mahmoud ElShazly Email: ziad.m.elshazly@gmail.com
Built with ❤️ using Streamlit, TensorFlow, and Python
- v1.0: Initial release with basic mask detection
- v1.1: Added interactive UI and confidence scoring
- v1.2: Enhanced styling and multiple page navigation