| --- |
| license: agpl-3.0 |
| library_name: ultralytics |
| language: |
| - en |
| tags: |
| - object-detection |
| - yolo26 |
| - yolo11 |
| - ultralytics |
| - pytorch |
| - onnx |
| - construction-safety |
| - hazard-detection |
| datasets: |
| - custom |
| --- |
| |
| # Construction-Hazard-Detection |
|
|
| YOLO-based (primarily YOLO26) models for construction-site hazard detection. These models detect: |
|
|
| - Workers without helmets and/or safety vests |
| - Workers near machinery or vehicles |
| - Workers in restricted areas (derived from safety cone clustering) |
| - Machinery/vehicles near utility poles |
|
|
| This repository provides ready-to-use weights in PyTorch (.pt) and ONNX (.onnx) formats, a demo image, and the class label mapping for easy integration. |
|
|
| π For the full end-to-end system (APIs, web UI, training, evaluation, data tools), see the main project: https://github.com/yihong1120/Construction-Hazard-Detection |
|
|
|  |
|
|
| ## Labels |
|
|
| Index-to-name mapping used across all provided models (also in `class_names.txt`): |
|
|
| ``` |
| 0: Hardhat |
| 1: Mask |
| 2: NO-Hardhat |
| 3: NO-Mask |
| 4: NO-Safety Vest |
| 5: Person |
| 6: Safety Cone |
| 7: Safety Vest |
| 8: Machinery |
| 9: Utility Pole |
| 10: Vehicle |
| ``` |
|
|
| ## Available models |
|
|
| Models are organized by model family (e.g., YOLO26 vs YOLO11). |
|
|
| ### YOLO26 (Recommended) |
|
|
| - PyTorch (Ultralytics): |
| - `models/yolo26/pt/yolo26n.pt` |
| - `models/yolo26/pt/yolo26s.pt` |
| - `models/yolo26/pt/yolo26m.pt` |
| - `models/yolo26/pt/yolo26l.pt` |
| - `models/yolo26/pt/yolo26x.pt` |
| - ONNX: |
| - `models/yolo26/onnx/yolo26n.onnx` |
| - `models/yolo26/onnx/yolo26s.onnx` |
| - `models/yolo26/onnx/yolo26m.onnx` |
| - `models/yolo26/onnx/yolo26l.onnx` |
| - `models/yolo26/onnx/yolo26x.onnx` |
|
|
| ### YOLO11 (Legacy) |
|
|
| - PyTorch (Ultralytics): |
| - `models/yolo11/pt/yolo11n.pt` |
| - `models/yolo11/pt/yolo11s.pt` |
| - `models/yolo11/pt/yolo11m.pt` |
| - `models/yolo11/pt/yolo11l.pt` |
| - `models/yolo11/pt/yolo11x.pt` |
| - ONNX: |
| - `models/yolo11/onnx/yolo11n.onnx` |
| - `models/yolo11/onnx/yolo11s.onnx` |
| - `models/yolo11/onnx/yolo11m.onnx` |
| - `models/yolo11/onnx/yolo11l.onnx` |
| - `models/yolo11/onnx/yolo11x.onnx` |
|
|
| Large binaries are tracked with Git LFS. |
|
|
| ## Quick start |
|
|
| ### A) Ultralytics (PyTorch) |
|
|
| ```python |
| from ultralytics import YOLO |
| |
| # Load a model (choose the variant that fits your needs) |
| model = YOLO("models/yolo26/pt/yolo26x.pt") |
| |
| # Inference on the demo image |
| results = model("data/examples/demo.jpg", imgsz=640, conf=0.25) |
| |
| # Parse results (first image) |
| res = results[0] |
| boxes = res.boxes # xyxy, confidence, class |
| for xyxy, conf, cls_id in zip(boxes.xyxy.tolist(), boxes.conf.tolist(), boxes.cls.tolist()): |
| print(xyxy, conf, int(cls_id)) |
| ``` |
|
|
| CLI option: |
|
|
| ```bash |
| yolo predict model=models/yolo26/pt/yolo26x.pt source=data/examples/demo.jpg imgsz=640 conf=0.25 |
| ``` |
|
|
| ### B) ONNX Runtime |
|
|
| ```python |
| import cv2 |
| import numpy as np |
| import onnxruntime as ort |
| |
| # Load and preprocess image to 640x640 |
| img = cv2.imread("data/examples/demo.jpg") |
| img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) |
| size = 640 |
| inp = cv2.resize(img_rgb, (size, size)).astype(np.float32) / 255.0 |
| inp = np.transpose(inp, (2, 0, 1))[None, ...] # 1x3x640x640 |
| |
| # Run ONNX model |
| session = ort.InferenceSession("models/yolo26/onnx/yolo26x.onnx", providers=["CPUExecutionProvider"]) |
| input_name = session.get_inputs()[0].name |
| outputs = session.run(None, {input_name: inp}) |
| |
| pred = outputs[0] # Typically (1, N, no) |
| print(pred.shape) |
| ``` |
|
|
| Post-processing (NMS, scaling back to original image) follows standard Ultralytics/YOLO routines. |
|
|
| ## File structure |
|
|
| ``` |
| . |
| ββ README.md |
| ββ LICENSE |
| ββ models/ |
| β ββ yolo26/ |
| β β ββ pt/ |
| β β β ββ yolo26n.pt |
| β β β ββ yolo26s.pt |
| β β β ββ yolo26m.pt |
| β β β ββ yolo26l.pt |
| β β β ββ yolo26x.pt |
| β β ββ onnx/ |
| β β ββ yolo26n.onnx |
| β β ββ yolo26s.onnx |
| β β ββ yolo26m.onnx |
| β β ββ yolo26l.onnx |
| β β ββ yolo26x.onnx |
| β ββ yolo11/ |
| β ββ pt/ |
| β β ββ yolo11n.pt |
| β β ββ ... |
| β ββ onnx/ |
| β ββ yolo11n.onnx |
| β ββ ... |
| ββ data/ |
| β ββ examples/ |
| β ββ demo.jpg |
| ββ class_names.txt |
| ``` |
|
|
| ## Intended use and limitations |
|
|
| - Intended for research and prototyping in construction safety monitoring. |
| - Performance depends on camera viewpoint, lighting, occlusion, and domain gap. |
| - For production, evaluate thoroughly on your target environment and consider rule-based filters and tracking. |
|
|
| ## Acknowledgements and sources |
|
|
| - Main project and docs: https://github.com/yihong1120/Construction-Hazard-Detection |
| - Dataset concept inspired by Roboflow construction safety datasets with extended annotations. |
| - Roboflow dataset: https://app.roboflow.com/object-detection-qn97p/construction-hazard-detection |
| - Models trained/exported using Ultralytics YOLO. |
|
|
| ## License |
|
|
| This repository is distributed under the AGPL-3.0 license. See `LICENSE` for details and ensure compliance, especially for networked deployments. |
|
|