title: Face-Mask-Detection-YOLOv5l
emoji: 😷
colorFrom: green
colorTo: gray
sdk: gradio
app_file: app.py
pinned: true
license: mit
tags:
- face mask
- covid
- object detection
- yolov5
- gradio
- pytorch
- computer-vision
- huggingface-spaces


😷 Face Mask Detection with YOLOv5l (Snapshot Inference)
Face-Mask-Detection-YOLOv5l is an AI-powered app that detects whether people are wearing masks correctly, incorrectly, or not at all — using a fine-tuned YOLOv5l model.
📷 Upload an image, paste from clipboard, or take a webcam snapshot
The app returns bounding boxes and labels on detected faces:
with_mask
without_mask
mask_weared_incorrect
🌐 Demo
Deployed on Hugging Face Spaces:

Model Details
- Model: YOLOv5l (v6.2)
- Classes:
with_mask, without_mask, mask_weared_incorrect
- Input Size: 640×640
- Dataset: Kaggle Face Mask Detection
- Training: 50 epochs, manual
.state_dict() loading for PyTorch 2.6+ compatibility
📓 Training Notebook (Kaggle)
Model was fine-tuned on Kaggle.
fine-tuning-yolov5l-for-face-mask-detection
Includes:
- YOLOv5l setup (v6.2 locked)
- Custom YAML config for 3 classes
- Exported
best_state_dict.pt for deployment
- Validated mAP:
0.879, P: 0.896, R: 0.817
Features
- Detects 3 face mask statuses
- Upload image, webcam snapshot, or clipboard paste
- Adjustable confidence threshold
- Annotated output with bounding boxes and labels
- Lightweight and fast — runs in browser via Hugging Face
Folder Structure
face-mask-detection-yolov5l/
├── yolov5/ # Cloned YOLOv5 repo (v6.2)
├── app.py # Gradio interface logic
├── inference\_utils.py # Model loading + NMS + annotation
├── model/
│ └── best\_state\_dict.pt # Trained YOLOv5l model weights
├── examples/ # Sample test images
├── requirements.txt
└── README.md
📷 Example Output
| Input Image |
Annotated Output |
 |
 |
Installation
To run locally:
git clone https://github.com/McKlay/face-mask-detection-yolov5l
cd face-mask-detection-yolov5l
pip install -r requirements.txt
python app.py
Requirements
torch
opencv-python
numpy
Pillow
gradio
torchvision
matplotlib
seaborn
👨💻 Author
Developed by Clay Mark Sarte
Built with PyTorch and Gradio
Deployed to Hugging Face Spaces
⚠️ Disclaimer
This tool is for demonstration and educational use only.
It is not intended for real-world medical or security deployment.
评论