Skip to content

Commit

Permalink
Upgrade from YOLOv8 to YOLO11
Browse files Browse the repository at this point in the history
  • Loading branch information
yihong1120 committed Oct 8, 2024
1 parent 34ba6c6 commit 408a7c9
Show file tree
Hide file tree
Showing 55 changed files with 446 additions and 648 deletions.
32 changes: 16 additions & 16 deletions README-zh-tw.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +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/YOLO_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/YOLO_data_augmentation">YOLO 數據增強</a> |
<a href="examples/YOLO_evaluation">YOLO 評估</a> |
<a href="examples/YOLO_train">YOLO 訓練</a>
</div>

<br>
Expand All @@ -18,7 +18,7 @@
<img src="https://img.shields.io/badge/python-3.12.7-blue?logo=python" alt="Python 3.12.7">
</a>
<a href="https://github.com/ultralytics/ultralytics">
<img src="https://img.shields.io/badge/YOLOv8-ultralytics-blue?logo=yolo" alt="YOLOv8">
<img src="https://img.shields.io/badge/YOLO11-ultralytics-blue?logo=yolo" alt="YOLO11">
</a>
<a href="https://scikit-learn.org/stable/modules/generated/sklearn.cluster.HDBSCAN.html">
<img src="https://img.shields.io/badge/HDBSCAN-sklearn-orange?logo=scikit-learn" alt="HDBSCAN sklearn">
Expand All @@ -39,7 +39,7 @@

<br>

"建築工地危險檢測系統" 是一款以人工智慧驅動的工具,旨在提升工地的安全性。該系統利用 YOLOv8 模型進行物件偵測,能夠識別以下潛在危險:
"建築工地危險檢測系統" 是一款以人工智慧驅動的工具,旨在提升工地的安全性。該系統利用 YOLO 模型進行物件偵測,能夠識別以下潛在危險:

- 未佩戴安全帽的工人
- 未穿著安全背心的工人
Expand All @@ -60,7 +60,7 @@

多語言支援使該系統在全球範圍內的使用者都能方便使用,提升了不同地區的可用性。

> **待辦事項**:新增對 WhatsApp 通知的支援
> **待辦事項**:新增對 WhatsApp 通知的支援,從YOLOv8轉換至YOLO11
<br>
<br>
Expand Down Expand Up @@ -114,14 +114,14 @@
- video_url: "rtsp://example1.com/stream" # 視頻的 URL
image_name: "cam1" # 圖像的名稱
label: "label1" # 視頻的標籤
model_key: "yolov8n" # 視頻使用的模型鍵
model_key: "yolo11n" # 視頻使用的模型鍵
line_token: "token1" # 用於通知的 Line Token
run_local: True # 本地運行物件檢測
language: "en" # 將語言設置成英文
- video_url: "rtsp://example2.com/stream"
image_name: "cam2"
label: "label2"
model_key: "yolov8n"
model_key: "yolo11n"
line_token: "token2"
run_local: True
language: "zh-TW"
Expand Down Expand Up @@ -213,7 +213,7 @@

6. 要運行物體檢測 API,使用以下命令:
```bash
gunicorn -w 1 -b 0.0.0.0:8001 "examples.YOLOv8_server_api.app:YOLOv8-server-api-app"
gunicorn -w 1 -b 0.0.0.0:8001 "examples.YOLO_server_api.app:YOLO-server-api-app"
```

7. 使用特定的配置文件運行主應用程序,使用以下命令:
Expand Down Expand Up @@ -260,11 +260,11 @@

| Model | size<br><sup>(pixels) | mAP<sup>val<br>50 | mAP<sup>val<br>50-95 | params<br><sup>(M) | FLOPs<br><sup>(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 |
| YOLO11n | 640 | 54.1 | 31.0 | 2.6 | 6.5 |
| YOLO11s | 640 | // | // | 9.4 | 21.6 |
| YOLO11m | 640 | // | // | 20.1 | 68.0 |
| YOLO11l | 640 | // | // | 25.3 | 86.9 |
| YOLO11x | 640 | 76.8 | 52.5 | 56.9 | 194.9 |

</details>

Expand All @@ -280,7 +280,7 @@

## 開發路線圖
- [x] 數據收集和預處理。
- [x] 使用建築工地數據訓練 YOLOv8 模型。
- [x] 使用建築工地數據訓練 YOLO 模型。
- [x] 開發後處理技術以提高準確性。
- [x] 實施實時分析和警報系統。
- [x] 在模擬環境中進行測試和驗證。
Expand Down
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +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">Server-API</a> |
<a href="examples/YOLO_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/YOLO_data_augmentation">Data-Augmentation</a> |
<a href="examples/YOLO_evaluation">Evaluation</a> |
<a href="examples/YOLO_train">Train</a>
</div>

<br>
Expand All @@ -18,7 +18,7 @@
<img src="https://img.shields.io/badge/python-3.12.7-blue?logo=python" alt="Python 3.12.7">
</a>
<a href="https://github.com/ultralytics/ultralytics">
<img src="https://img.shields.io/badge/YOLOv8-ultralytics-blue?logo=yolo" alt="YOLOv8">
<img src="https://img.shields.io/badge/YOLO11-ultralytics-blue?logo=yolo" alt="YOLO11">
</a>
<a href="https://scikit-learn.org/stable/modules/generated/sklearn.cluster.HDBSCAN.html">
<img src="https://img.shields.io/badge/HDBSCAN-sklearn-orange?logo=scikit-learn" alt="HDBSCAN sklearn">
Expand All @@ -42,7 +42,7 @@

<br>

"Construction-Hazard-Detection" is an AI-powered tool designed to enhance safety on construction sites. By leveraging the YOLOv8 model for object detection, it identifies potential hazards such as:
"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
Expand Down Expand Up @@ -117,14 +117,14 @@ Before running the application, you need to configure the system by specifying t
- 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
model_key: "yolo11n" # Model key for the video
line_token: "token1" # Line token for notification
run_local: True # Run object detection locally
language: "en" # Set language to English
- video_url: "rtsp://example2.com/stream"
image_name: "cam2"
label: "label2"
model_key: "yolov8n"
model_key: "yolo11n"
line_token: "token2"
run_local: True
language: "zh-TW"
Expand Down Expand Up @@ -268,11 +268,11 @@ The primary dataset for training this model is the [Construction Site Safety Ima

| Model | size<br><sup>(pixels) | mAP<sup>val<br>50 | mAP<sup>val<br>50-95 | params<br><sup>(M) | FLOPs<br><sup>(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 |
| YOLO11n | 640 | 54.1 | 31.0 | 2.6 | 6.5 |
| YOLO11s | 640 | // | // | 9.4 | 21.6 |
| YOLO11m | 640 | // | // | 20.1 | 68.0 |
| YOLO11l | 640 | // | // | 25.3 | 86.9 |
| YOLO11x | 640 | 76.8 | 52.5 | 56.9 | 194.9 |

</details>

Expand All @@ -290,7 +290,7 @@ We welcome contributions to this project. Please follow these steps:
## Development Roadmap

- [x] Data collection and preprocessing.
- [x] Training YOLOv8 model with construction site data.
- [x] Training YOLO model with construction site data.
- [x] Developing post-processing techniques for enhanced accuracy.
- [x] Implementing real-time analysis and alert system.
- [x] Testing and validation in simulated environments.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
🇬🇧 [English](./README.md) | 🇹🇼 [繁體中文](./README-zh-tw.md)

# YOLOv8 資料增強範例
# YOLO 資料增強範例

本倉庫包含用於對影像資料集進行資料增強的範例和腳本,特別是旨在提高 YOLOv8 物件偵測模型的表現。對於需要豐富資料集以改善模型訓練的機器學習項目尤其有用。
本倉庫包含用於對影像資料集進行資料增強的範例和腳本,特別是旨在提高 YOLO 物件偵測模型的表現。對於需要豐富資料集以改善模型訓練的機器學習項目尤其有用。

## 使用方式

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
🇬🇧 [English](./README.md) | 🇹🇼 [繁體中文](./README-zh-tw.md)

# YOLOv8 Data Augmentation Example
# YOLO Data Augmentation Example

This repository contains examples and scripts for performing data augmentation on image datasets, particularly aimed at enhancing the performance of YOLOv8 object detection models. It is particularly useful for machine learning projects requiring enriched datasets for improved model training.
This repository contains examples and scripts for performing data augmentation on image datasets, particularly aimed at enhancing the performance of YOLO object detection models. It is particularly useful for machine learning projects requiring enriched datasets for improved model training.

## Usage

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -407,4 +407,4 @@ def main():


if __name__ == '__main__':
main()
main()
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,15 @@ def random_transform(self) -> A.Compose:
A.Perspective(scale=(0.05, 0.1), p=1),
A.ElasticTransform(alpha=1, sigma=50, alpha_affine=None, p=1),
A.Lambda(image=self.random_crop_with_random_size, p=1),
# A.RandomResizedCrop(height=640, width=640, scale=(0.3, 1.0), p=1),
A.RandomResizedCrop(size=(640, 640), scale=(0.3, 1.0), p=1),
]

# Augmentations that do not affect bounding boxes
non_bbox_augmentations = [
# Colour and brightness adjustments
A.RandomBrightnessContrast(
brightness_limit=(-0.03, 0.03),
contrast_limit=(-0.03, 0.03),
brightness_limit=(0.0, 0.03),
contrast_limit=(0.0, 0.03),
p=1.0
),
A.RGBShift(r_shift_limit=3, g_shift_limit=3, b_shift_limit=3, p=1.0),
Expand All @@ -137,9 +136,9 @@ def random_transform(self) -> A.Compose:
A.PlanckianJitter(p=1),
# Blur and noise
A.MotionBlur(blur_limit=(3, 7), p=1.0),
A.GaussianBlur(blur_limit=(3, 7), p=1.0),
A.GaussianBlur(blur_limit=(1, 3), p=1.0),
A.GaussNoise(var_limit=(10.0, 50.0), p=1.0),
A.ISONoise(color_shift=(0.01, 0.05), intensity=(0.1, 0.5), p=1.0),
A.ISONoise(color_shift=(0.01, 0.05), intensity=(0.05, 0.2), p=1.0),
A.MedianBlur(blur_limit=3, p=1.0),
# Colour space and contrast adjustments
A.CLAHE(clip_limit=2, p=1.0),
Expand All @@ -150,18 +149,18 @@ def random_transform(self) -> A.Compose:
A.Posterize(num_bits=4, p=1.0),
A.InvertImg(p=1),
# Special effects
A.RandomShadow(shadow_roi=(0.3, 0.3, 0.7, 0.7), num_shadows_limit = (1, 2), shadow_dimension=2, p=1.0),
A.RandomShadow(shadow_roi=(0.3, 0.3, 0.7, 0.7), num_shadows_limit = (1, 1), shadow_dimension=1, p=1.0),
# A.RandomFog(fog_coef_lower=0.05, fog_coef_upper=0.1, p=1.0),
A.RandomSnow(snow_point_range=(0.05, 0.15), brightness_coeff=1.2, p=1.0),
A.RandomRain(slant_range=(-5,5), drop_length=5, drop_width=1, blur_value=2, p=1.0),
A.RandomRain(slant_range=(-5,5), drop_length=5, drop_width=1, blur_value=1, p=1.0),
A.ChannelShuffle(p=1),
A.RandomSunFlare(flare_roi=(0.02, 0.04, 0.08, 0.08), angle_range=(0, 1), p=1),
A.Defocus(radius=(3, 5), p=1),
# Other augmentations
A.RandomToneCurve(scale=0.05, p=1.0),
A.RandomGamma(gamma_limit=(90, 110), p=1.0),
A.Superpixels(p_replace=0.1, n_segments=100, p=1),
A.ImageCompression(quality_range = (50, 90), p=1.0),
A.ImageCompression(quality_range = (70, 90), p=1.0),
A.GlassBlur(sigma=0.5, max_delta=1, p=1.0),
A.PixelDropout(dropout_prob=0.05, p=1),
A.OpticalDistortion(distort_limit=(0.05, 0.1), shift_limit=(0.05, 0.1), p=1.0)
Expand Down Expand Up @@ -255,6 +254,9 @@ def augment_image(self, image_path: Path) -> None:
image_aug_path = self.train_path / 'images' / aug_image_filename
label_aug_path = self.train_path / 'labels' / aug_label_filename

# Convert the image back to uint8
image_aug = (image_aug * 255).clip(0, 255).astype(np.uint8)

# Save the image using OpenCV
cv2.imwrite(str(image_aug_path), cv2.cvtColor(image_aug * 255, cv2.COLOR_RGB2BGR))
self.write_label_file(bboxes_aug, class_labels_aug, str(label_aug_path))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
🇬🇧 [English](./README.md) | 🇹🇼 [繁體中文](./README-zh-tw.md)

# YOLOv8 評估範例
# YOLO 評估範例

此儲存庫提供了用於評估 YOLOv8 物件偵測模型的範例和腳本,特別著重於評估特定數據集上模型的準確度和性能。
此儲存庫提供了用於評估 YOLO 物件偵測模型的範例和腳本,特別著重於評估特定數據集上模型的準確度和性能。

## 使用方法

Expand All @@ -16,26 +16,26 @@ python convert_yolo_to_coco.py --labels_dir dataset/valid/labels --images_dir da

### 使用 SAHI 評估模型

要使用 SAHI 庫來評估 YOLOv8 模型,請運行 `evaluate_sahi_yolov8.py` 腳本。提供模型、COCO JSON 和圖片目錄的路徑:
要使用 SAHI 庫來評估 YOLO 模型,請運行 `evaluate_sahi_yolo.py` 腳本。提供模型、COCO JSON 和圖片目錄的路徑:

```bash
python evaluate_sahi_yolov8.py --model_path "../../models/best_yolov8n.pt" --coco_json "dataset/coco_annotations.json" --image_dir "dataset/valid/images"
python evaluate_sahi_yolo.py --model_path "../../models/best_yolov8n.pt" --coco_json "dataset/coco_annotations.json" --image_dir "dataset/valid/images"
```

此腳本將輸出各種 IoU 閾值下的評估指標,如平均精度和召回率。

### 使用 Ultralytics YOLO 評估模型

要使用 Ultralytics 框架進行評估,請執行 `evaluate_yolov8.py` 腳本。同樣地,指定模型和數據配置文件的路徑:
要使用 Ultralytics 框架進行評估,請執行 `evaluate_yolo.py` 腳本。同樣地,指定模型和數據配置文件的路徑:

```bash
python evaluate_yolov8.py --model_path "../../models/best_yolov8n.pt" --data_path "dataset/data.yaml"
python evaluate_yolo.py --model_path "../../models/best_yolov8n.pt" --data_path "dataset/data.yaml"
```

### 功能

- **YOLO 至 COCO 轉換**:將您的數據集標註從 YOLO 格式轉換為 COCO 格式,以便與各種評估工具兼容。
- **模型評估**:使用 SAHI 庫或 Ultralytics 框架來評估您的 YOLOv8 模型。
- **模型評估**:使用 SAHI 庫或 Ultralytics 框架來評估您的 YOLO 模型。
- **性能指標**:透過像是 mAP、精度和召回率等指標,獲得模型性能的深入見解。
- **可自訂的評估**:腳本允許針對您特定的數據集和模型進行靈活的評估設置。

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
🇬🇧 [English](./README.md) | 🇹🇼 [繁體中文](./README-zh-tw.md)

# YOLOv8 Evaluation Example
# YOLO Evaluation Example

This repository provides examples and scripts for evaluating YOLOv8 object detection models, particularly focusing on assessing the model's accuracy and performance on specific datasets.
This repository provides examples and scripts for evaluating YOLO object detection models, particularly focusing on assessing the model's accuracy and performance on specific datasets.

## Usage

Expand All @@ -16,26 +16,26 @@ python convert_yolo_to_coco.py --labels_dir dataset/valid/labels --images_dir da

### Evaluating Models with SAHI

To evaluate a YOLOv8 model using the SAHI library, run the `evaluate_sahi_yolov8.py` script. Provide the paths to the model, COCO JSON, and image directory:
To evaluate a YOLO model using the SAHI library, run the `evaluate_sahi_yolo.py` script. Provide the paths to the model, COCO JSON, and image directory:

```bash
python evaluate_sahi_yolov8.py --model_path "../../models/best_yolov8n.pt" --coco_json "dataset/coco_annotations.json" --image_dir "dataset/valid/images"
python evaluate_sahi_yolo.py --model_path "../../models/best_yolov8n.pt" --coco_json "dataset/coco_annotations.json" --image_dir "dataset/valid/images"
```

This script will output evaluation metrics such as Average Precision and Recall across different IoU thresholds.

### Evaluating Models with Ultralytics YOLO

For evaluation using the Ultralytics framework, execute the `evaluate_yolov8.py` script. Again, specify the model and data configuration file paths:
For evaluation using the Ultralytics framework, execute the `evaluate_yolo.py` script. Again, specify the model and data configuration file paths:

```bash
python evaluate_yolov8.py --model_path "../../models/best_yolov8n.pt" --data_path "dataset/data.yaml"
python evaluate_yolo.py --model_path "../../models/best_yolov8n.pt" --data_path "dataset/data.yaml"
```

### Features

- **YOLO to COCO Conversion**: Convert your dataset annotations from YOLO format to COCO format for compatibility with various evaluation tools.
- **Model Evaluation**: Utilise the SAHI library or Ultralytics framework to evaluate your YOLOv8 models.
- **Model Evaluation**: Utilise the SAHI library or Ultralytics framework to evaluate your YOLO models.
- **Performance Metrics**: Gain insights into model performance with metrics like mAP, Precision, and Recall.
- **Customisable Evaluation**: Scripts allow for flexible evaluation setups tailored to your specific dataset and model.

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@


class COCOConverter:
"""Converts YOLO format annotations to COCO format."""
"""
Converts YOLO format annotations to COCO format.
"""

def __init__(self, categories: list[str]):
"""
Expand Down
Loading

0 comments on commit 408a7c9

Please sign in to comment.