Skip to content

Commit

Permalink
Add diagram
Browse files Browse the repository at this point in the history
  • Loading branch information
yihong1120 committed Jul 13, 2024
1 parent 75a02ae commit 794e5fa
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 124 deletions.
54 changes: 38 additions & 16 deletions README-zh-tw.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
<img width="100%" src="./assets/images/project_graphics/banner.gif" alt="AI-Driven Construction Safety Banner">

<div align="center">
<a href="examples/YOLOv8_server_api">模型伺服器</a> | <a href="examples/streaming_web">串流網頁</a> | <a href="examples/user_management">用戶管理</a> | <a href="examples/YOLOv8_data_augmentation">YOLOv8 數據增強</a> | <a href="examples/YOLOv8_evaluation">YOLOv8 評估</a> | <a href="examples/YOLOv8_train">YOLOv8 訓練</a>
<a href="examples/YOLOv8_server_api">模型伺服器</a> |
<a href="examples/streaming_web">串流網頁</a> |
<a href="examples/user_management">用戶管理</a> |
<a href="examples/YOLOv8_data_augmentation">YOLOv8 數據增強</a> |
<a href="examples/YOLOv8_evaluation">YOLOv8 評估</a> |
<a href="examples/YOLOv8_train">YOLOv8 訓練</a>
</div>

<br>
Expand All @@ -30,7 +35,16 @@

"建築工地危險檢測系統" 是一個以人工智能驅動的工具,旨在提高建築工地的安全性。利用 YOLOv8 模型進行物體檢測,此系統能夠識別潛在的危險,如高空重物和鋼管。對訓練好的模型進行後處理以提高準確性。該系統設計用於實時環境中,提供對檢測到的危險的即時分析和警告。

## 配置
<br>
<br>

<div style="text-align: center;">
<img src="./assets/images/hazard-detection.png" alt="diagram" style="width: 80%;">
</div>

<br>

## 操作說明

在運行應用程式之前,您需要配置系統,指定視頻流的詳細信息和其他參數,這些信息需要在 YAML 配置文件中進行設置。示例配置文件 `configuration.yaml` 應該看起來像這樣:

Expand Down Expand Up @@ -64,7 +78,10 @@
- `line_token`: 用於發送通知的 LINE 訊息 API Token。
- `run_local`: 布爾值,指示是否在本地運行物件檢測。

## 使用 Docker
<br>

<details>
<summary>使用 Docker</summary>

要運行危險檢測系統,您需要在機器上安裝 Docker 和 Docker Compose。按照以下步驟來啟動系統:

Expand Down Expand Up @@ -92,7 +109,10 @@
docker-compose down
```

## 使用 Python
</details>

<details>
<summary>使用 Python</summary>

要在終端運行危險檢測系統,您需要在機器上安裝 Python。按照以下步驟來啟動系統:

Expand Down Expand Up @@ -139,6 +159,20 @@
gunicorn -w 1 -k eventlet -b 127.0.0.1:8002 "examples.Stream-Web.app:streaming-web-app"
```

</details>

## 附加信息

- 系統日誌可在 Docker 容器內部訪問,可用於調試目的。
- 如果啟用,檢測到的輸出圖像將保存到指定的輸出路徑。
- 如果檢測到危險,將在指定小時通過 LINE 消息 API 發送通知。

### 注意事項
- 確保 `Dockerfile` 存在於項目的根目錄中,並根據您的應用程序的要求進行了正確配置。
- `-p 8080:8080` 標誌將容器的 8080 端口映射到主機機器的 8080 端口,允許您通過主機的 IP 地址和端口號訪問應用程序。

有關 Docker 使用和命令的更多信息,請參閱 [Docker 文檔](https://docs.docker.com/)。

## 數據集信息
訓練此模型的主要數據集是 [Roboflow 的建築工地安全圖像數據集](https://www.kaggle.com/datasets/snehilsanyal/construction-site-safety-image-dataset-roboflow/data)。我們已經用額外的註釋豐富了這個數據集,並在 Roboflow 上公開訪問。增強的數據集可以在這裡找到:[Roboflow 上的建築危險檢測](https://universe.roboflow.com/side-projects/construction-hazard-detection)。此數據集包括以下標籤:

Expand All @@ -155,18 +189,6 @@

我們的全面數據集確保模型能夠識別建築環境中常見的各種潛在危險。

## 附加信息

- 系統日誌可在 Docker 容器內部訪問,可用於調試目的。
- 如果啟用,檢測到的輸出圖像將保存到指定的輸出路徑。
- 如果檢測到危險,將在指定小時通過 LINE 消息 API 發送通知。

### 注意事項
- 確保 `Dockerfile` 存在於項目的根目錄中,並根據您的應用程序的要求進行了正確配置。
- `-p 8080:8080` 標誌將容器的 8080 端口映射到主機機器的 8080 端口,允許您通過主機的 IP 地址和端口號訪問應用程序。

有關 Docker 使用和命令的更多信息,請參閱 [Docker 文檔](https://docs.docker.com/)。

## 貢獻
我們歡迎對此項目的貢獻。請按照以下步驟操作:
1. 分叉存儲庫。
Expand Down
238 changes: 130 additions & 108 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
🇬🇧 [English](./README.md) | 🇹🇼 [繁體中文](./README-zh-tw.md)

<img width="100%" src="./assets/images/project_graphics/banner.gif" alt="AI-Driven Construction Safety Banner">
<img width="100%" src="./assets/images/project_graphics/banner.gif" alt="AI-Driven Construction Safety Banner">

<div align="center">
<a href="examples
/YOLOv8_server_api">Server-API</a> | <a href="examples
/streaming_web">Streaming-Web</a> | <a href="examples
/user_management">User-Management</a> | <a href="examples
/YOLOv8_data_augmentation">Data-Augmentation</a> | <a href="examples
/YOLOv8_evaluation">Evaluation</a> | <a href="examples
/YOLOv8_train">Train</a>
<a href="examples/YOLOv8_server_api">Server-API</a> |
<a href="examples/streaming_web">Streaming-Web</a> |
<a href="examples/user_management">User-Management</a> |
<a href="examples/YOLOv8_data_augmentation">Data-Augmentation</a> |
<a href="examples/YOLOv8_evaluation">Evaluation</a> |
<a href="examples/YOLOv8_train">Train</a>
</div>

<br>
Expand All @@ -36,120 +35,152 @@

"Construction-Hazard-Detection" is an AI-driven tool aimed at enhancing safety at construction sites. Utilising the YOLOv8 model for object detection, this system identifies potential hazards like overhead heavy loads and steel pipes. Post-processing is applied to the trained model for improved accuracy. The system is designed for deployment in real-time environments, providing instant analysis and warnings for any detected hazards.

## Configuration
<br>
<br>

<div style="text-align: center;">
<img src="./assets/images/hazard-detection.png" alt="diagram" style="width: 80%;">
</div>

<br>


## 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:

```yaml
# 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 objection detection locally
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
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
- 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.
- `run_local`: Boolean value indicating whether to run object detection locally.

## 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:

```bash
docker-compose up --build
```

4. To run the main application with a specific configuration file, use the following command:

```bash
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:

```bash
docker-compose down
```

## Usage for Python

To run the hazard detection system with terminal, you need to have Python installed on your machine. Follow these steps to get the system up and running:

1. Clone the repository to your local machine.
```bash
git clone https://github.com/yihong1120/Construction-Hazard-Detection.git
```

2. Navigate to the cloned directory.
```bash
cd Construction-Hazard-Detection
```
<br>

3. Install required packages:
```bash
pip install -r requirements.txt
```
Now, you could launch the hazard-detection system in Docker or Python env:

<details>
<summary>Usage for Docker</summary>

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:

```bash
docker-compose up --build
```

4. To run the main application with a specific configuration file, use the following command:
```bash
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:
```bash
docker-compose down
```

</details>

<details>
<summary>Usage for Python</summary>

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

1. Clone the repository to your local machine:
```bash
git clone https://github.com/yihong1120/Construction-Hazard-Detection.git
```

2. Navigate to the cloned directory:
```bash
cd Construction-Hazard-Detection
```

3. Install required packages:
```bash
pip install -r requirements.txt
```

4. Install and launch MySQL service (if required):
```bash
sudo apt install mysql-server
sudo systemctl start mysql.service
```

5. Start user management API:
```bash
gunicorn -w 1 -b 0.0.0.0:8000 "examples.User-Management.app:user-managements-app"
```

6. Run object detection API:
```bash
gunicorn -w 1 -b 0.0.0.0:8001 "examples.Model-Server.app:app"
```

7. Run the main application with a specific configuration file:
```bash
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:
```bash
gunicorn -w 1 -k eventlet -b 127.0.0.1:8002 "examples.Stream-Web.app:streaming-web-app"
```

</details>

4. Install and launch MySQL service:
```bash
sudo apt install mysql-server
sudo systemctl start mysql.service
```
## Additional Information

5. Set up user accounts and passcodes. Use the following command to start the user management API:
```bash
gunicorn -w 1 -b 0.0.0.0:8000 "examples.User-Management.app:user-managements-app"
```
It is suggested to use Postman app to interact with the app.
- 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.

6. To run the object-detection API, use the following command:
```bash
gunicorn -w 1 -b 0.0.0.0:8001 "examples.Model-Server.app:app"
```
### Notes

7. To run the main application with a specific configuration file, use the following command:
```bash
python3 main.py --config /path/to/your/configuration.yaml
```
Replace `/path/to/your/configuration.yaml` with the actual path to your configuration file.
- 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.

8. To start the streaming web service, execute the following command:
```bash
gunicorn -w 1 -k eventlet -b 127.0.0.1:8002 "examples.Stream-Web.app:streaming-web-app"
```
For more information on Docker usage and commands, refer to the [Docker documentation](https://docs.docker.com/).

## Dataset Information

The primary dataset for training this model is the [Construction Site Safety Image Dataset from Roboflow](https://www.kaggle.com/datasets/snehilsanyal/construction-site-safety-image-dataset-roboflow/data). 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](https://universe.roboflow.com/side-projects/construction-hazard-detection). This dataset includes the following labels:

- `0: 'Hardhat'`
Expand All @@ -165,25 +196,15 @@ The primary dataset for training this model is the [Construction Site Safety Ima

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

## 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](https://docs.docker.com/).

## 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

- [x] Data collection and preprocessing.
- [x] Training YOLOv8 model with construction site data.
- [x] Developing post-processing techniques for enhanced accuracy.
Expand All @@ -193,4 +214,5 @@ We welcome contributions to this project. Please follow these steps:
- [x] Ongoing maintenance and updates based on user feedback.

## License

This project is licensed under the [AGPL-3.0 License](LICENSE.md).
Binary file added assets/images/hazard-detection.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 794e5fa

Please sign in to comment.