sakethdevx/construction-safety-monitor
0
Construction Site Safety Monitor
A Streamlit web application that uses YOLO models to monitor construction site safety by detecting workers and their personal protective equipment (PPE) in real-time video feeds.
Features
- Real-time Video Processing: Upload and process construction site videos
- PPE Detection: Detects hard hats, safety vests, masks, and identifies missing equipment
- Live Alerts: Generates instant alerts when workers are not wearing required safety equipment
- Safety Analytics: Provides comprehensive statistics and violation reports
- Model Selection: Choose between YOLOv8n and YOLO11n models
- Interactive Dashboard: User-friendly interface with real-time monitoring
Detected Classes
The app can detect the following 10 classes:
- Hardhat (Green boxes)
- Mask (Yellow boxes)
- NO-Hardhat (Red boxes - triggers HIGH priority alert)
- NO-Mask (Magenta boxes - triggers LOW priority alert)
- NO-Safety Vest (Orange boxes - triggers MEDIUM priority alert)
- Person (Cyan boxes)
- Safety Cone (White boxes)
- Safety Vest (Blue boxes)
- Machinery (Gray boxes)
- Vehicle (Pink boxes)
Alert System
- 🔴 High Priority: Missing Hard Hat
- 🟡 Medium Priority: Missing Safety Vest
- 🟢 Low Priority: Missing Mask
Installation
- Clone or download the project files
- Install Python dependencies:
pip install -r requirements.txt- Ensure you have the trained models: Make sure the following model files are in the
outputs/folder: yolov8n.ptyolo11n.pt
Usage
- Start the Streamlit app:
streamlit run construction_safety_app.py- Open your web browser and navigate to the displayed URL (usually
http://localhost:8501)
- Configure the app:
- Select your preferred model (YOLOv8n or YOLO11n) from the sidebar
- Adjust the confidence threshold if needed (default: 0.5)
- Upload a video:
- Click "Browse files" and select a construction site video
- Supported formats: MP4, AVI, MOV, MKV
- Start processing:
- Click "Start Processing" to begin analysis
- Monitor real-time alerts in the right panel
- View processed frames with bounding boxes and labels
- Review results:
- Check the safety alerts panel for violations
- Review summary statistics including total persons detected, violation rates, and more
File Structure
dataset11/
├── construction_safety_app.py # Main Streamlit application
├── requirements.txt # Python dependencies
├── README.md # This file
├── data.yaml # Dataset configuration
├── outputs/ # Trained models directory
│ ├── yolov8n.pt # YOLOv8 nano model
│ └── yolo11n.pt # YOLO11 nano model
├── train/ # Training dataset
├── valid/ # Validation dataset
└── test/ # Test datasetTechnical Details
- Framework: Streamlit for web interface
- Model: YOLO (You Only Look Once) for object detection
- Video Processing: OpenCV for video handling and frame processing
- Real-time Analysis: Frame-by-frame processing with bounding box visualization
- Alert Generation: Automatic detection of safety violations with severity classification
Customization
You can customize the app by:
- Adjusting confidence thresholds in the sidebar
- Modifying alert priorities in the
analyze_safety_violations()function - Adding new detection classes by updating the
class_namesdictionary - Changing bounding box colors in the
get_class_colors()function
Performance Tips
- For large videos, the app processes every 10th frame for display to maintain performance
- Adjust the confidence threshold to balance between detection accuracy and processing speed
- Use smaller video files for faster processing during testing
Troubleshooting
- Model loading errors: Ensure the model files exist in the
outputs/folder - Video upload issues: Check that your video format is supported (MP4, AVI, MOV, MKV)
- Memory issues: Try processing smaller video files or reduce the confidence threshold
- Slow processing: Lower the confidence threshold or process fewer frames
Requirements
- Python 3.8+
- At least 4GB RAM (8GB recommended for large videos)
- CUDA-compatible GPU (optional, for faster processing)
License
This project is for educational and safety monitoring purposes in construction environments.
