Skip to content

A Streamlit-based PPE detection system with real-time webcam and video analysis, powered by a custom-trained YOLO model for complete offline privacy.

Notifications You must be signed in to change notification settings

MichAdebayo/security-checker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

34 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Smart Safety Monitor πŸ›‘οΈ

Smart Safety Monitor

Local YOLO PPE Detection System - Privacy-First Computer Vision

A comprehensive Personal Protective Equipment (PPE) detection system built with Streamlit and a locally trained YOLO model. Features real-time webcam monitoring, video processing, and image analysis with complete privacy protection through offline processing.

✨ Features

  • πŸ–ΌοΈ Image Analysis - Upload and analyze images for PPE compliance with detailed metrics
  • πŸŽ₯ Video Processing - Process video files with frame-by-frame detection and tracking
  • πŸ“Ή Live Detection - Real-time webcam monitoring with continuous compliance tracking
  • πŸ€– Local Trained Model - Custom-trained YOLO model specifically for PPE detection
  • ⚑ High Performance - Optimized inference with dedicated virtual environment
  • πŸ”’ Privacy First - 100% local processing, no cloud dependencies or data transmission
  • πŸ“Š Compliance Metrics - Real-time safety compliance reporting and audio alerts
  • 🎯 Multi-PPE Detection - Detects helmets, masks, safety vests, and violations

πŸš€ Quick Setup

Prerequisites

  • Python 3.8+ (3.12 recommended)
  • Webcam (for live detection)
  • ~4GB disk space for virtual environment and dependencies

Installation

# Clone the repository
git clone <repository-url>
cd security-checker

# Activate the dedicated YOLO virtual environment
source yolo_env/bin/activate  # On macOS/Linux
# OR
yolo_env\Scripts\activate     # On Windows

# Install additional dependencies if needed
pip install -r requirements.txt

# Run the application
streamlit run .streamlit/app.py

πŸ“ Project Structure

β”œβ”€β”€ .streamlit/              # Streamlit applications
β”‚   β”œβ”€β”€ 01_home.py          # Landing page and navigation
β”‚   β”œβ”€β”€ 02_image.py         # Image analysis interface
β”‚   β”œβ”€β”€ 03_video.py         # Video processing with tracking
β”‚   └── 04_live.py          # Live webcam detection
β”œβ”€β”€ utils/                  # Core utility modules
β”‚   β”œβ”€β”€ __init__.py         # Package initialization
β”‚   └── config.py           # Environment configuration
β”œβ”€β”€ model/                  # Local trained YOLO model
β”‚   └── best.pt             # Custom PPE detection model
β”œβ”€β”€ assets/                 # Static assets
β”‚   β”œβ”€β”€ logo.webp           # Application logo
β”‚   └── emergency-alarm.mp3 # Audio alert sound
β”œβ”€β”€ yolo_env/              # Dedicated virtual environment
β”‚   β”œβ”€β”€ bin/               # Environment executables
β”‚   β”œβ”€β”€ lib/               # Python packages
β”‚   └── ...                # Virtual environment files
β”œβ”€β”€ notebooks/             # Development notebooks
β”‚   β”œβ”€β”€ ppe_v1.ipynb       # Model development
β”‚   └── ppe_v2.ipynb       # Model training iterations
β”œβ”€β”€ requirements.txt       # Python dependencies
β”œβ”€β”€ docker-compose.yaml    # Docker deployment (optional)
└── README.md             # This file

πŸ”§ Configuration

The system uses environment-based configuration with sensible defaults:

Model Configuration

  • Local Model: model/best.pt - Custom-trained PPE detection model
  • Detection Classes: Helmet, Mask, Safety Vest, Person, and violation classes
  • Confidence Threshold: Adjustable per-page (default varies by use case)

Virtual Environment

The app uses a dedicated virtual environment (yolo_env/) with optimized dependencies:

  • PyTorch: GPU-accelerated inference (when available)
  • Ultralytics YOLO: Latest YOLO implementation
  • OpenCV: Computer vision processing
  • Streamlit: Web interface framework

🎯 Detection Classes

The custom-trained model detects the following PPE items and violations:

βœ… Positive PPE Detection

  • πŸͺ– Helmet/Hard Hat - Safety headgear compliance
  • 😷 Mask - Face covering detection
  • 🦺 Safety Vest - High-visibility clothing detection
  • πŸ‘€ Person - Human detection for context

❌ Violation Detection

  • NO-Helmet - Missing headgear violations
  • NO-Mask - Missing face covering violations
  • NO-Safety Vest - Missing vest violations

🚧 Environment Detection

  • Safety Cone - Work zone markers
  • Machinery - Industrial equipment
  • Vehicle - Construction vehicles

⚑ Performance & Architecture

Direct YOLO Integration

The system uses direct integration with a custom-trained YOLO model:

# Custom model trained specifically for PPE detection
# Optimized for construction and industrial environments
# Real-time processing with dedicated virtual environment

Architecture Benefits:

  • Custom Training - Model specifically trained on PPE scenarios
  • Fast Inference - Direct model access with optimized environment
  • No Network Dependencies - Completely offline processing
  • Memory Efficient - Model loads once and stays in memory
  • Privacy Focused - No data transmission to external services

Key Features

  1. Real-time Tracking - DeepSORT integration for person tracking in videos
  2. Compliance Metrics - Continuous calculation based on all 3 PPE items
  3. Audio Alerts - Customizable sound notifications for violations
  4. Multi-format Support - Images, videos, and live webcam streams

πŸ“Š Usage Guide

πŸ–ΌοΈ Image Analysis

  1. Navigate to the Image Analysis page
  2. Upload an image file (JPG, PNG, etc.)
  3. Adjust confidence threshold as needed
  4. View detection results and compliance metrics
  5. Download annotated image with bounding boxes

πŸŽ₯ Video Processing

  1. Go to the Video Processing page
  2. Upload a video file (MP4, AVI, MOV, etc.)
  3. Configure detection parameters and playback speed
  4. Process video with frame-by-frame analysis
  5. Monitor real-time compliance metrics during processing
  6. Download processed video with annotations

πŸ“Ή Live Detection

  1. Go to the Live Detection page
  2. Allow camera access when prompted by browser
  3. Adjust detection settings and persistence
  4. Monitor real-time PPE compliance
  5. Enable audio alerts for immediate violation notifications

πŸ› οΈ Development & Customization

Model Management

  • Current Model: Custom-trained on PPE datasets
  • Model Location: model/best.pt
  • Training Notebooks: Available in notebooks/ directory
  • Model Updates: Replace best.pt with new trained models

Adding New Detection Classes

  1. Retrain model with new classes
  2. Update color mapping in utility functions
  3. Modify compliance calculation logic
  4. Update UI class displays and icons

πŸ“ Recent Updates & Features

  • βœ… Custom Model Training - Dedicated PPE model trained on construction datasets
  • βœ… Dedicated Virtual Environment - Optimized dependency management with yolo_env/
  • βœ… Enhanced Live Detection - Continuous compliance tracking with audio alerts
  • βœ… Video Processing Improvements - DeepSORT tracking and real-time metrics
  • βœ… Privacy-First Architecture - Complete offline processing, no external dependencies
  • βœ… Streamlined Interface - Clean, focused UI without unnecessary model status messages
  • βœ… Real-time Compliance - Dynamic metrics that update as PPE is added/removed
  • βœ… Audio Alert System - Customizable sound notifications for safety violations

πŸ” Troubleshooting

Environment Issues

  • Activate Environment: Ensure yolo_env is activated before running
  • Dependencies: Check requirements.txt for any missing packages
  • Python Version: Use Python 3.8+ (3.12 recommended)

Model Issues

  • Model Location: Verify model/best.pt exists and is accessible
  • Model Format: Ensure model is compatible with Ultralytics YOLO
  • Memory: Ensure sufficient RAM (4GB+ recommended)

Performance Issues

  • GPU Acceleration: PyTorch will use GPU if available (CUDA/MPS)
  • Detection Interval: Increase interval for slower hardware
  • Confidence Threshold: Adjust for optimal detection vs. performance balance

Camera/Browser Issues

  • Permissions: Allow camera access in browser settings
  • Browser Support: Use Chrome, Firefox, Safari, or Edge
  • WebRTC: Ensure browser supports WebRTC for live detection
  • Refresh: Try refreshing the page or restarting Streamlit

🐳 Docker Deployment (Optional)

For containerized deployment, use the included Docker configuration:

# Build and run with Docker Compose
docker-compose up --build

# Access the application at http://localhost:8501

🀝 Contributing

  1. Model Improvements: Train new models with additional PPE classes
  2. Performance Optimization: Enhance inference speed and accuracy
  3. UI/UX Enhancements: Improve user interface and experience
  4. Documentation: Update documentation and examples

πŸ“„ License

This project is designed for educational and safety monitoring purposes. Please ensure compliance with local privacy and surveillance regulations when deploying in workplace environments.

About

A Streamlit-based PPE detection system with real-time webcam and video analysis, powered by a custom-trained YOLO model for complete offline privacy.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •