Self-hosted service
yihong1120/Construction-Hazard-Detection avatar
yihong1120/Construction-Hazard-Detection

Construction-Hazard-Detection: YOLO site monitoring that needs PostgreSQL, Redis, MediaMTX and Python 3.14

Enhances construction site safety using YOLO for object detection, identifying hazards like workers without helmets or safety vests, and proximity to machinery or vehicles. HDBSCAN clusters safety cone coordinates to create monitored zones. Post-processing algorithms improve detection accuracy.

352 stars46 forksPythonAGPL-3.0

At a glance

What is it?
Construction-Hazard-Detection watches live camera streams for missing hard hats and vests, workers near machinery and cone-defined zones. It is a multi-service system, not a script, and its runtime requirements are strict.
Who is it for?
Construction-Hazard-Detection suits a team that can run PostgreSQL, Redis, MediaMTX and a GPU worker, and that accepts AGPL-3.0 terms. It is a poor fit for a quick helmet-detection experiment on a single image.
Can I use it commercially?
Yes, with strict conditions. AGPL-3.0 is a network copyleft licence: if people use a modified version over a network, for example as a hosted service, you must offer them its source code under the same licence.
Is it still maintained?
Yes. The repository last received commits 3 days ago.
What is it written in?
Mainly Python, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on November 23, 2026, and from our analysis. They are not legal advice.

From daily snapshots

Star history

  • yihong1120/Construction-Hazard-Detection352 ★ · +5
Star history
Repository2026-09-132026-11-23
yihong1120/Construction-Hazard-Detection347352

5 Stars in the last 71 days, measured from the daily GitHub snapshot. Compare with other projects

Editorial analysis

Five fixed hazard rules decide what counts as a violation

The detection logic is a list of rules, not a free-form detector. The project flags workers without hard hats, workers without safety vests, workers too close to machinery or vehicles, workers inside cone-derived controlled areas, and machinery or vehicles too close to utility poles. The runtime diagram refers to 11 configured detection classes.

The description explains the cone rule: HDBSCAN clusters safety cone coordinates to create monitored zones, and post-processing algorithms improve detection accuracy. Two consequences follow. Hazards outside these five rules, such as missing gloves or unguarded edges, are not flagged by the described logic, and the cone rule only works if cones are visible and placed where you want a boundary. Labels and notifications are available in Traditional Chinese, Simplified Chinese, English, French, Thai, Vietnamese, Indonesian and Japanese.

Redis carries coordination state, and MediaMTX owns the video

The architecture keeps heavy video out of the cache. Redis is not used to store live video frames. MediaMTX owns live playback, serving RTSP ingest plus HLS and WebRTC playback, while Redis keeps only small coordination state: authentication cache, FCM token cache, compact warning metadata, overlay demand keys and overlay ready keys.

In docker-compose.yml, the media-server service uses bluenviron/mediamtx:1.18.2 with MTX_RTSPTRANSPORTS set to tcp, HLS and WebRTC switched on, and HLS creation only for active viewers by default. Redis is bound to 127.0.0.1:6379 and the compose file refuses to start unless REDIS_PASSWORD is set. If you plan remote viewing, you need to publish the media server deliberately, because the Redis port is not meant to be reachable from outside.

Python must be 3.14, and every dependency is pinned exactly

pyproject.toml sets requires-python to >=3.14,<3.15, so Python 3.13 and 3.15 are both out. The core dependencies are fixed with exact versions, for example fastapi==0.139.2, aiohttp==3.14.5, sqlalchemy[asyncio]==2.0.46 and redis==7.1.0. The setup command is:

bash
uv sync --locked --all-extras --no-extra yolo-gpu

The default dependency set holds only shared API runtime packages. Extras split the rest: streaming, violation, notification, yolo, mcp, social-notifications, training and yolo-gpu. The yolo extra pins torch==2.13.0, torchvision==0.28.0 and ultralytics==8.4.115. Exact pins give you reproducible installs, but they also make it hard to merge this project into an environment that holds other packages.

The model weights are not in the repository

Weights live in a Hugging Face model repository and must be downloaded before any worker starts:

bash
hf download yihong1120/Construction-Hazard-Detection \
  --repo-type model \
  --include "models/pt/*.pt" \
  --local-dir .

Workers expect filenames in the form models/pt/best_<model_key>.pt, for example models/pt/best_yolo26n.pt. A file with a different name will not match the model key in your configuration. The same project also publishes a Roboflow Universe dataset page, but the badges there are links, not instructions, so the Hugging Face download is the path to follow. Without the weights, the stream processor has nothing to load, and the first sign of the problem is a worker that cannot find its model.

Database mode is the recommended runtime and it needs an identity provider

The recommended runtime uses PostgreSQL for sites, users, stream configurations and violations, Redis for sessions and notification tokens, MediaMTX for ingest and playback, and main.py, which polls stream configuration and starts one stream process per active camera. Local YOLO workers share GPU inference across cameras through shared memory. A short-lived local JSON config is the only case where the README suggests skipping database mode.

The .env example shows DATABASE_URL with the postgresql+asyncpg driver, REDIS_PASSWORD, and a block of OIDC values: OIDC_ENABLED=true, OIDC_ISSUER_URL, OIDC_JWKS_URL, OIDC_AUDIENCE and OIDC_ACCOUNT_URL. The API services share the configured issuer, JWKS URL and audience, so you must have an OIDC provider before the APIs can authenticate anyone. The service URLs in the example use ports 8005 for data management, 8003 for FCM notifications and 8002 for violation records.

The GPU image and the pinned requirements.txt are tied to NVIDIA and x86_64 Linux

The Dockerfile begins with FROM base-gpu:latest and says the stream processor uses TensorRT and YOLO, so only this image inherits CUDA. It exports the streaming, yolo and yolo-gpu extras, adds ffmpeg, Noto fonts, libglib2.0-0 and libgl1, and runs main.py as a non-root appuser with `--config /app/config/configuration.json` as the default command.

requirements.txt is generated by uv and every line carries the marker platform_machine == 'x86_64' and sys_platform == 'linux'. The yolo-gpu extra pins tensorrt==11.1.0.106 and onnxruntime-gpu==1.27.0, and the project says to use it only on CUDA or TensorRT hosts. If your site cameras feed an ARM box or a Mac, the exported requirements do not apply to you, and the TensorRT path is unavailable.

AGPL-3.0, a separate Flutter app, and release history

The licence is AGPL-3.0. If you modify the code and offer it to users over a network, the licence's source-sharing terms apply, so a company that wants to keep changes private should read the terms before building on it. The Flutter app is maintained in a separate repository, visionnaire-flutter. The frontend/web folder here is an ignored, generated deployment artifact, not editable frontend source.

The latest release is v5.0.0, dated 2026-08-23, preceded by v4.1.0 on 2025-08-26. The most recent push was on 2026-10-29, and the repository is not archived. The notification layer covers FCM, LINE Messaging API, Messenger, Telegram, WeChat and HTTP broadcast, while examples/mcp_server holds optional AI tools for detection, records, models and multi-platform notifications.

Editorial conclusion

Construction-Hazard-Detection suits a team that can run PostgreSQL, Redis, MediaMTX and a GPU worker, and that accepts AGPL-3.0 terms. It is a poor fit for a quick helmet-detection experiment on a single image. Before adopting it, confirm you can run Python 3.14, obtain the model weights from Hugging Face, and wire an OIDC provider for the API services.

Frequently asked questions

How to identify hazards in a construction site?

Construction-Hazard-Detection applies YOLO to camera streams to flag workers without hard hats or vests, workers too close to machinery or vehicles, workers inside cone-derived zones, and machinery near utility poles.

What Python version does Construction-Hazard-Detection require?

pyproject.toml requires Python >=3.14,<3.15, and the quick start installs with uv sync --locked --all-extras --no-extra yolo-gpu.

Where do I get the Construction-Hazard-Detection model weights?

They are downloaded from the yihong1120/Construction-Hazard-Detection model repository on Hugging Face with hf download. Workers expect files named models/pt/best_<model_key>.pt.

Official sources

  1. License: AGPL-3.0
  2. Project website
  3. README
  4. Releases
  5. yihong1120/Construction-Hazard-Detection on GitHub
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/yihong1120-construction-hazard-detection.svg)](https://hysenlabs.com/projects/yihong1120-construction-hazard-detection)

Star history chart for your README

markdown
[![Star history](https://hysenlabs.com/chart/yihong1120-construction-hazard-detection.svg)](https://hysenlabs.com/projects/yihong1120-construction-hazard-detection)

Was this useful?