"Construction-Hazard-Detection" is an AI-powered tool designed to enhance safety on construction sites. By leveraging the YOLO model for object detection, it identifies potential hazards such as:
- Workers without helmets
- Workers without safety vests
- Workers near machinery or vehicles
- Workers in restricted areas, restricted areas will be automatically generated by computing and clustering the coordinates of safety cones.
Post-processing algorithms further improve detection accuracy. The system is built for real-time deployment, offering instant analysis and alerts for identified hazards.
Additionally, the system integrates AI recognition results in real-time via a web interface. It can send notifications and real-time on-site images through messaging apps like LINE, Messenger, WeChat, and Telegram for prompt alerts and reminders. The system also supports multiple languages, enabling users to receive notifications and interact with the interface in their preferred language. Supported languages include:
- 🇹🇼 Traditional Chinese (Taiwan)
- 🇨🇳 Simplified Chinese (Mainland China)
- 🇫🇷 French
- 🇬🇧 English
- 🇹🇭 Thai
- 🇻🇳 Vietnamese
- 🇮🇩 Indonesian
This multi-language support makes the system accessible to a global audience, improving usability across different regions.
- Hazard Detection Examples
- Usage
- Additional Information
- Dataset Information
- Contributing
- Development Roadmap
- License
Below are examples of real-time hazard detection by the system:
Before running the application, you need to configure the system by specifying the details of the video streams and other parameters in a JSON configuration file. An example configuration file config/configuration.json
should look like this:
[
{
"video_url": "https://cctv1.kctmc.nat.gov.tw/6e559e58/",
"site": "Kaohsiung",
"stream_name": "Test",
"model_key": "yolo11n",
"notifications": {
"line_token_1": "language_1",
"line_token_2": "language_2"
},
"detect_with_server": true,
"expire_date": "2024-12-31T23:59:59",
"detection_items": {
"detect_no_safety_vest_or_helmet": true,
"detect_near_machinery_or_vehicle": true,
"detect_in_restricted_area": true
},
"work_start_hour": 7,
"work_end_hour": 18,
"store_in_redis": true
},
{
"video_url": "streaming URL",
"site": "Factory_1",
"stream_name": "camera_1",
"model_key": "yolo11n",
"notifications": {
"line_token_3": "language_3",
"line_token_4": "language_4"
},
"detect_with_server": false,
"expire_date": "No Expire Date",
"detection_items": {
"detect_no_safety_vest_or_helmet": true,
"detect_near_machinery_or_vehicle": false,
"detect_in_restricted_area": true
},
"work_start_hour": 0,
"work_end_hour": 24,
"store_in_redis": true
}
]
Each object in the array represents a video stream configuration with the following fields:
-
video_url
: The URL of the live video stream. This can include:- Surveillance streams
- RTSP streams
- Secondary streams
- YouTube videos or live streams
- Discord streams
-
site
: The location of the monitoring system (e.g., construction site, factory). -
stream_name
: The name assigned to the camera or stream (e.g., "Front Gate", "Camera 1"). -
model_key
: The key identifier for the machine learning model to use (e.g., "yolo11n"). -
notifications
: A list of LINE messaging API tokens and corresponding languages for sending notifications.line_token_1
,line_token_2
, etc.: These are the LINE API tokens.language_1
,language_2
, etc.: The languages for the notifications (e.g., "en" for English, "zh-TW" for Traditional Chinese).
Supported languages for notifications include:
zh-TW
: Traditional Chinesezh-CN
: Simplified Chineseen
: Englishfr
: Frenchvi
: Vietnameseid
: Indonesianth
: Thai
For information on how to obtain a LINE token, please refer to line_notify_guide_en.
-
detect_with_server
: Boolean value indicating whether to run object detection using a server API. IfTrue
, the system will use the server for object detection. IfFalse
, object detection will run locally on the machine. -
expire_date
: Expire date for the video stream configuration in ISO 8601 format (e.g., "2024-12-31T23:59:59"). If there is no expiration date, a string like "No Expire Date" can be used. -
detection_items
: Specifies the safety detection items for monitoring specific scenarios. Each item can be set toTrue
to enable orFalse
to disable. The available detection items are:detect_no_safety_vest_or_helmet
: Detects if a person is not wearing a safety vest or helmet. This is essential for monitoring compliance with safety gear requirements on sites where such equipment is mandatory for personnel protection.detect_near_machinery_or_vehicle
: Detects if a person is dangerously close to machinery or vehicles. This helps prevent accidents caused by close proximity to heavy equipment or moving vehicles, often encountered in construction sites or industrial areas.detect_in_restricted_area
: Detects if a person has entered a restricted or controlled area. Restricted areas may be dangerous for untrained personnel or may contain sensitive equipment, so this setting aids in controlling access to such zones.
-
work_start_hour
: Specifies the hour (in 24-hour format) when the system should start monitoring the video stream. This allows monitoring to be restricted to active work hours, reducing unnecessary processing outside the defined timeframe (e.g.,7
for 7:00 AM). -
work_end_hour
: Specifies the hour (in 24-hour format) when the system should stop monitoring the video stream. Monitoring will cease after this time to optimise resource usage (e.g.,18
for 6:00 PM).Together,
work_start_hour
andwork_end_hour
define the monitoring period during a day. For 24-hour monitoring, setwork_start_hour
to0
andwork_end_hour
to24
. -
store_in_redis
: A boolean value that determines whether to store processed frames and associated detection data in Redis. IfTrue
, the system will save the data to a Redis database for further use, such as real-time monitoring or integration with other services. IfFalse
, no data will be saved in Redis.
Now, you could launch the hazard-detection system in Docker or Python env:
Docker
To run the hazard detection system, you need to have Docker and Docker Compose installed on your machine. Follow these steps to get the system up and running:
-
Clone the repository to your local machine.
git clone https://github.com/yihong1120/Construction-Hazard-Detection.git
-
Navigate to the cloned directory.
cd Construction-Hazard-Detection
-
Build and run the services using Docker Compose:
docker-compose build
-
To run the application, use the following command:
docker-compose up
You can view the detection results at http://localhost
-
To stop the services, use the following command:
docker-compose down
Python
To run the hazard detection system with Python, follow these steps:
Use the following command to clone the repository from GitHub:
git clone https://github.com/yihong1120/Construction-Hazard-Detection.git
Change the directory to the newly cloned repository:
cd Construction-Hazard-Detection
Run the following command to install the necessary Python packages:
pip install -r requirements.txt
-
Open the terminal and execute the following commands to install and start the MySQL server:
sudo apt update sudo apt install mysql-server sudo systemctl start mysql.service
- Download and install the appropriate version of MySQL for your operating system from the MySQL Downloads page.
After installing MySQL, use the following command to initialise the construction_hazard_detection
database and create the users
table:
mysql -u root -p < scripts/init.sql
You will be prompted to enter the MySQL root password. Ensure that the scripts/init.sql
file contains the necessary SQL commands to set up the database and tables as described earlier.
Redis is needed only when using the Streaming Web functionality. Follow the steps below to set up Redis.
-
Install Redis
Open the terminal and run the following commands:
sudo apt update sudo apt install redis-server
-
Configure Redis (Optional)
If you need custom settings, edit the Redis configuration file:
sudo vim /etc/redis/redis.conf
To enhance security, enable password protection by adding or modifying the following line:
requirepass YourStrongPassword
Replace
YourStrongPassword
with a secure password. -
Start and Enable Redis Service
Start the Redis service:
sudo systemctl start redis.service
Enable Redis to start automatically on boot:
sudo systemctl enable redis.service
Refer to the official Redis installation guide for instructions specific to your operating system.
Start the object detection API with the following command:
uvicorn examples.YOLO_server.backend.app:sio_app --host 0.0.0.0 --port 8001
Use the following command to run the main application and specify the configuration file:
python3 main.py --config config/configuration.json
Replace config/configuration.json
with the actual path to your configuration file.
Run the following command to start the backend service on a Linux system:
uvicorn examples.streaming_web.backend.app:sio_app --host 127.0.0.1 --port 8002
To start the backend service on a Windows system, use the following command:
waitress-serve --host=127.0.0.1 --port=8002 "examples.streaming_web.backend.app:streaming-web-app"
Refer to the examples/YOLO_server_api/frontend/nginx.conf
file for deployment instructions. Place the static web files in the following directory:
examples/YOLO_server_api/frontend/dist
- The system logs are available within the Docker container and can be accessed for debugging purposes.
- The output images with detections (if enabled) will be saved to the specified output path.
- Notifications will be sent through LINE messaging API during the specified hours if hazards are detected.
- Ensure that the
Dockerfile
is present in the root directory of the project and is properly configured as per your application's requirements.
For more information on Docker usage and commands, refer to the Docker documentation.
The primary dataset for training this model is the Construction Site Safety Image Dataset from Roboflow. We have enriched this dataset with additional annotations and made it openly accessible on Roboflow. The enhanced dataset can be found here: Construction Hazard Detection on Roboflow. This dataset includes the following labels:
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: 'Vehicle'
Model | size (pixels) |
mAPval 50 |
mAPval 50-95 |
params (M) |
FLOPs (B) |
---|---|---|---|---|---|
YOLO11n | 640 | 58.0 | 34.2 | 2.6 | 6.5 |
YOLO11s | 640 | 70.1 | 44.8 | 9.4 | 21.6 |
YOLO11m | 640 | 73.3 | 42.6 | 20.1 | 68.0 |
YOLO11l | 640 | 77.3 | 54.6 | 25.3 | 86.9 |
YOLO11x | 640 | 82.0 | 61.7 | 56.9 | 194.9 |
Our comprehensive dataset ensures that the model is well-equipped to identify a wide range of potential hazards commonly found in construction environments.
We welcome contributions to this project. Please follow these steps:
- Fork the repository.
- Make your changes.
- Submit a pull request with a clear description of your improvements.
- Data collection and preprocessing.
- Training YOLO model with construction site data.
- Developing post-processing techniques for enhanced accuracy.
- Implementing real-time analysis and alert system.
- Testing and validation in simulated environments.
- Deployment in actual construction sites for field testing.
- Ongoing maintenance and updates based on user feedback.
- Add support for WhatsApp notifications.
This project is licensed under the AGPL-3.0 License.