Skip to content

Enhances construction site safety using YOLOv8 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.

License

Notifications You must be signed in to change notification settings

yihong1120/Construction-Hazard-Detection

🇬🇧 English | 🇹🇼 繁體中文

AI-Driven Construction Safety Banner



"Construction-Hazard-Detection" is an AI-driven tool aimed at enhancing safety on construction sites. Utilising the YOLOv8 model for object detection, this system identifies potential hazards such as workers without helmets, workers without safety vests, workers in close proximity to machinery, and workers near vehicles. Post-processing algorithms are employed to enhance the accuracy of the detections. The system is designed for deployment in real-time environments, providing immediate analysis and alerts for detected hazards.

A newly developed feature allows the system to use safety cones to draw polygons, defining controlled zones and calculating the number of people within these zones. Notifications can be sent if people enter these controlled areas.

Additionally, the system can integrate AI recognition results in real-time through a web interface or use LINE, Messenger, WeChat, and Telegram notifications to send messages and real-time on-site images for prompt alerts and reminders.

TODO: Add supports for WhatsApp notification.


Hazard Detection Diagram

Contents

Usage

Before running the application, you need to configure the system by specifying the details of the video streams and other parameters in a YAML configuration file. An example configuration file configuration.yaml should look like this:

# This is a list of video configurations
- video_url: "rtsp://example1.com/stream"  # URL of the video
   image_name: "cam1"  # Name of the image
   label: "label1"  # Label of the video
   model_key: "yolov8n"  # Model key for the video
   line_token: "token1"  # Line token for notification
   run_local: True  # Run object detection locally
- video_url: "rtsp://example2.com/stream"
   image_name: "cam2"
   label: "label2"
   model_key: "yolov8n"
   line_token: "token2"
   run_local: 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
  • image_name: The name assigned to the image or camera.
  • label: The label assigned to the video stream.
  • model_key: The key identifier for the machine learning model to use.
  • line_token: The LINE messaging API token for sending notifications. For information on how to obtain a LINE token, please refer to line_notify_guide_en.
  • run_local: Boolean value indicating whether to run object detection locally.

Now, you could launch the hazard-detection system in Docker or Python env:

Docker

Usage for 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:

  1. Clone the repository to your local machine.

    git clone https://github.com/yihong1120/Construction-Hazard-Detection.git
    
  2. Navigate to the cloned directory.

    cd Construction-Hazard-Detection
    
  3. Build and run the services using Docker Compose:

    docker-compose up --build
  4. To run the main application with a specific configuration file, use the following command:

    docker-compose run main-application python main.py --config /path/in/container/configuration.yaml

    Replace /path/in/container/configuration.yaml with the actual path to your configuration file inside the container.

  5. To stop the services, use the following command:

    docker-compose down
Python

Usage for Python

To run the hazard detection system with Python, follow these steps:

  1. Clone the repository to your local machine:

    git clone https://github.com/yihong1120/Construction-Hazard-Detection.git
  2. Navigate to the cloned directory:

    cd Construction-Hazard-Detection
  3. Install required packages:

    pip install -r requirements.txt
  4. Install and launch MySQL service (if required):

    sudo apt install mysql-server
    sudo systemctl start mysql.service
  5. Start user management API:

    gunicorn -w 1 -b 0.0.0.0:8000 "examples.User-Management.app:user-managements-app"
  6. Run object detection API:

    gunicorn -w 1 -b 0.0.0.0:8001 "examples.Model-Server.app:app"
  7. Run the main application with a specific configuration file:

    python3 main.py --config /path/to/your/configuration.yaml

    Replace /path/to/your/configuration.yaml with the actual path to your configuration file.

  8. Start the streaming web service:

    gunicorn -w 1 -k eventlet -b 127.0.0.1:8002 "examples.Stream-Web.app:streaming-web-app"

Additional Information

  • 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.

Notes

  • Ensure that the Dockerfile is present in the root directory of the project and is properly configured as per your application's requirements.
  • The -p 8080:8080 flag maps port 8080 of the container to port 8080 on your host machine, allowing you to access the application via the host's IP address and port number.

For more information on Docker usage and commands, refer to the Docker documentation.

Dataset Information

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'
Models for detection
Model size
(pixels)
mAPval
50
mAPval
50-95
params
(M)
FLOPs
(B)
YOLOv8n 640 59.3 35.0 3.2 8.7
YOLOv8s 640 73.1 47.6 11.2 28.6
YOLOv8m 640 76.8 53.9 25.9 78.9
YOLOv8l 640 // // 43.7 165.2
YOLOv8x 640 82.9 60.9 68.2 257.8

Our comprehensive dataset ensures that the model is well-equipped to identify a wide range of potential hazards commonly found in construction environments.

Contributing

We welcome contributions to this project. Please follow these steps:

  1. Fork the repository.
  2. Make your changes.
  3. Submit a pull request with a clear description of your improvements.

Development Roadmap

  • Data collection and preprocessing.
  • Training YOLOv8 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.

License

This project is licensed under the AGPL-3.0 License.

About

Enhances construction site safety using YOLOv8 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.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published