CoolFace
Apppublic

sakethdevx/construction-safety-monitor

sourceHugging Facemitupdated 1y agoView on Hugging Face
0likes
App README

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:

  1. 1.Hardhat (Green boxes)
  2. 2.Mask (Yellow boxes)
  3. 3.NO-Hardhat (Red boxes - triggers HIGH priority alert)
  4. 4.NO-Mask (Magenta boxes - triggers LOW priority alert)
  5. 5.NO-Safety Vest (Orange boxes - triggers MEDIUM priority alert)
  6. 6.Person (Cyan boxes)
  7. 7.Safety Cone (White boxes)
  8. 8.Safety Vest (Blue boxes)
  9. 9.Machinery (Gray boxes)
  10. 10.Vehicle (Pink boxes)

Alert System

  • —🔴 High Priority: Missing Hard Hat
  • —🟡 Medium Priority: Missing Safety Vest
  • —🟢 Low Priority: Missing Mask

Installation

  1. 1.Clone or download the project files
  1. 1.Install Python dependencies:
bash
   pip install -r requirements.txt
  1. 1.Ensure you have the trained models: Make sure the following model files are in the outputs/ folder:
  2. 2.yolov8n.pt
  3. 3.yolo11n.pt

Usage

  1. 1.Start the Streamlit app:
bash
   streamlit run construction_safety_app.py
  1. 1.Open your web browser and navigate to the displayed URL (usually http://localhost:8501)
  1. 1.Configure the app:
  2. 2.Select your preferred model (YOLOv8n or YOLO11n) from the sidebar
  3. 3.Adjust the confidence threshold if needed (default: 0.5)
  1. 1.Upload a video:
  2. 2.Click "Browse files" and select a construction site video
  3. 3.Supported formats: MP4, AVI, MOV, MKV
  1. 1.Start processing:
  2. 2.Click "Start Processing" to begin analysis
  3. 3.Monitor real-time alerts in the right panel
  4. 4.View processed frames with bounding boxes and labels
  1. 1.Review results:
  2. 2.Check the safety alerts panel for violations
  3. 3.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 dataset

Technical 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:

  1. 1.Adjusting confidence thresholds in the sidebar
  2. 2.Modifying alert priorities in the analyze_safety_violations() function
  3. 3.Adding new detection classes by updating the class_names dictionary
  4. 4.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

  1. 1.Model loading errors: Ensure the model files exist in the outputs/ folder
  2. 2.Video upload issues: Check that your video format is supported (MP4, AVI, MOV, MKV)
  3. 3.Memory issues: Try processing smaller video files or reduce the confidence threshold
  4. 4.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.