YOLOv8m PPE (Personal Protective Equipment) Detection
Real-time PPE compliance detection model for construction sites. Detects whether workers are wearing required safety equipment.
π Quick Start
Train from scratch (single command)
pip install ultralytics huggingface_hub trackio opencv-python-headless onnx onnxsim
python train_ppe.py
This script handles everything end-to-end:
- Downloads and merges datasets from HF Hub
- Converts COCO annotations to YOLO format
- Trains YOLOv8m for 100 epochs
- Evaluates against acceptance criteria
- Exports to ONNX
- Pushes trained model back to this repo
Use a trained model
from huggingface_hub import hf_hub_download
from ultralytics import YOLO
model_path = hf_hub_download(
repo_id="introvert6162/yolov8m-ppe-detection",
filename="best.pt"
)
model = YOLO(model_path)
results = model("construction_site.jpg", conf=0.25, iou=0.45)
for r in results:
for box in r.boxes:
cls_name = r.names[int(box.cls)]
conf = float(box.conf)
print(f"{cls_name}: {conf:.2f}")
Model Details
| Property | Value |
|---|---|
| Architecture | YOLOv8m (25M params) |
| Input size | 640Γ640 |
| Framework | Ultralytics + PyTorch |
| Training data | 19,638 images (merged from 2 sources) |
| License | AGPL-3.0 (Ultralytics) |
| Inference speed | ~7.8ms/frame on T4 GPU |
Classes (11)
| ID | Class | Description | Training samples |
|---|---|---|---|
| 0 | helmet_on |
Worker wearing hard hat | 42,863 |
| 1 | helmet_off |
Worker without hard hat | 13,073 |
| 2 | jacket_on |
Worker wearing hi-vis jacket | 53 |
| 3 | jacket_off |
Worker without hi-vis jacket | 38 |
| 4 | boots_on |
Worker wearing safety boots | 22 |
| 5 | boots_off |
Worker without safety boots | β |
| 6 | gloves_on |
Worker wearing safety gloves | 18 |
| 7 | gloves_off |
Worker without safety gloves | β |
| 8 | harness_on |
Worker wearing safety harness | β |
| 9 | harness_off |
Worker without safety harness | β |
| 10 | person |
Person (parent class) | 69 |
β οΈ Classes with few/no samples (boots_off, gloves_off, harness_on/off) need additional data. See "Improving the Model" below.
Dataset
Merged from two CC BY 4.0 construction safety datasets:
| Source | Images | Classes covered |
|---|---|---|
| keremberke/hard-hat-detection | 19,745 | helmet_on, helmet_off |
| keremberke/construction-safety-object-detection | 398 | helmet, jacket, boots, gloves, person |
Split: 13,693 train / 3,949 val / 1,996 test (70/20/10)
Annotations: YOLO format (class_id cx cy w h, normalized)
Training Configuration
model: yolov8m.pt # COCO-pretrained
epochs: 100
imgsz: 640
batch: 16
optimizer: AdamW
lr0: 0.001
lrf: 0.01 # cosine decay to lr0 * lrf
weight_decay: 0.0005
warmup_epochs: 5
cos_lr: true
mosaic: 1.0
mixup: 0.1
degrees: 10.0 # rotation augmentation
scale: 0.5 # random scale
erasing: 0.1 # random erasing (occlusion sim)
hsv_h: 0.015
hsv_s: 0.7
hsv_v: 0.4
close_mosaic: 10
patience: 20 # early stopping
amp: true # mixed precision
Acceptance Criteria
| Metric | Threshold | Status |
|---|---|---|
| mAP@0.5 (overall) | β₯ 0.85 | β³ Awaiting training |
| mAP@0.5 (helmet) | β₯ 0.88 | β³ |
| mAP@0.5 (jacket) | β₯ 0.85 | β³ |
| Precision | β₯ 0.82 | β³ |
| Recall | β₯ 0.80 | β³ |
| Inference speed | β€ 35ms/frame | β (~7.8ms on T4) |
| False positive rate | β€ 5% crowded | β³ |
Deployment Options
Edge β NVIDIA Jetson (Option A)
model.export(format="engine", half=True) # TensorRT FP16
# Target: β€25ms/frame/stream on Jetson AGX Orin
Cloud β Docker + FastAPI (Option B)
model.export(format="onnx", opset=12, simplify=True)
# Deploy on EC2 g4dn.xlarge or GCP n1+T4
Mobile/Edge β TFLite (Option C)
model.export(format="tflite", int8=True)
Real-Time Inference Pipeline
See inference_pipeline.py for a complete production-grade system:
- Multi-stream RTSP ingestion with frame skipping (every 3rd frame)
- ByteTrack worker tracking for persistent anonymized IDs across frames
- Rolling-window compliance logic β 30-frame window, 10 consecutive non-compliant frames triggers alert
- Multi-channel alerts β dashboard WebSocket, SMS via Twilio, PostgreSQL audit log, audible alarm for high-severity zones
- GDPR compliance β anonymized worker IDs only, no biometric storage
- Offline resilience β local violation buffering when connectivity drops
from inference_pipeline import PPECompliancePipeline, PipelineConfig
config = PipelineConfig(
conf_threshold=0.25, # Favor recall over precision
frame_skip=3,
consecutive_threshold=10,
required_ppe=["helmet_on", "jacket_on"],
)
pipeline = PPECompliancePipeline(config)
pipeline.load_model_from_hub("introvert6162/yolov8m-ppe-detection")
pipeline.add_camera("gate_entrance", "rtsp://192.168.1.10:554/stream1")
pipeline.add_camera("crane_zone", "rtsp://192.168.1.11:554/stream1")
pipeline.start()
Improving the Model
Add more data for underrepresented classes
- Harness detection: Search Roboflow Universe for "fall protection harness" datasets
- Safety boots: Search for "safety boots detection" or "steel toe detection"
- Gloves (construction): Mix with CPPE-5 gloves + search "construction gloves"
- Synthetic augmentation: Use Albumentations 2-4Γ on rare classes
Recommended additional data sources
| Dataset | Source | Images | Covers |
|---|---|---|---|
| SHWD | GitHub | 7,581 | helmet_on/off |
| Construction Safety v23 | Roboflow | ~10,000 | Full PPE |
| PPE-Detect | Roboflow | ~5,000 | Multi-PPE |
| CPPE-5 | rishitdagli/cppe-5 | 1,029 | Gloves, masks |
Post-deployment monitoring
- Route 5% of detections to human review queue
- Track weekly average confidence scores for drift detection
- Auto-retrain if mAP on new data drops below 0.78
- Version models with semantic versioning in this repo
Files in This Repo
| File | Description |
|---|---|
train_ppe.py |
End-to-end training script (data prep β train β eval β push) |
inference_pipeline.py |
Production real-time multi-camera compliance pipeline |
prepare_dataset.py |
Standalone dataset preparation script |
ppe_dataset.yaml |
YOLO dataset configuration |
best.pt |
Best model weights (after training) |
best.onnx |
ONNX export (after training) |
Hardware Requirements
| Phase | Minimum | Recommended |
|---|---|---|
| Training | T4 16GB, 4h | A10G 24GB, 2.5h |
| Inference (per stream) | Jetson Nano | Jetson AGX Orin |
| Inference (cloud) | T4 GPU | A10G GPU |
Citation
@misc{ppe-detection-2026,
title={YOLOv8m PPE Detection for Construction Safety},
author={introvert6162},
year={2026},
url={https://huggingface.co/introvert6162/yolov8m-ppe-detection}
}
- Downloads last month
- -