Skip to content

Commit

Permalink
Merge branch 'main' of github.com:yihong1120/Construction-Hazard-Dete…
Browse files Browse the repository at this point in the history
…ction
  • Loading branch information
yihong1120 committed Jul 11, 2024
2 parents c5eba91 + 2b55d60 commit a70c042
Show file tree
Hide file tree
Showing 7 changed files with 280 additions and 311 deletions.
215 changes: 0 additions & 215 deletions docs/Detailed_Cost_Analysis_and_Payback_Plan_Report.md

This file was deleted.

67 changes: 67 additions & 0 deletions examples/YOLOv8_server_api/README-zh-tw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
🇬🇧 [English](./README.md) | 🇹🇼 [繁體中文](./README-zh-tw.md)

# YOLOv8 Server API 範例

本部分提供一個 YOLOv8 Server API 的範例實作,旨在利用 YOLOv8 模型進行物件檢測。此指南提供有關如何使用、配置和了解該 API 功能的信息。

## 使用方式

1. **啟動伺服器:**
```sh
python app.py
```

或者

```sh
gunicorn -w 1 -b 0.0.0.0:8000 "examples.YOLOv8_server_api.app:app"
```

2. **向 API 發送請求:**
- 可以使用 `curl`、Postman 或瀏覽器來向伺服器發送請求。
- 使用 `curl` 的範例:
```sh
curl -X POST -F "file=@path/to/your/image.jpg" http://localhost:8000/detect
```

## 功能

- **身份驗證**:使用身份驗證機制來保護 API。
- **快取**:通過快取檢測結果來提高性能。
- **模型下載**:自動下載和加載 YOLOv8 模型。
- **配置**:靈活的配置選項來定制 API。
- **物件檢測**:使用 YOLOv8 模型對上傳的圖像進行物件檢測。
- **錯誤處理**:強健的錯誤處理機制來管理各種情況。

## 配置

可以通過 `config.py` 文件來配置 API。以下是一些可用的主要配置選項:

- **伺服器設置**
- `HOST`:運行伺服器的主機名。默認為 `0.0.0.0`
- `PORT`:運行伺服器的端口。默認為 `8000`

- **模型設置**
- `MODEL_PATH`:YOLOv8 模型文件的路徑。
- `CONFIDENCE_THRESHOLD`:物件檢測的置信度閾值。

- **快取設置**
- `CACHE_ENABLED`:啟用或禁用快取。默認為 `True`
- `CACHE_EXPIRY`:快取過期時間(以秒為單位)。默認為 `3600`

- **身份驗證設置**
- `AUTH_ENABLED`:啟用或禁用身份驗證。默認為 `True`
- `SECRET_KEY`:JWT 身份驗證的密鑰。

## 文件概述

- **app.py**:啟動伺服器並定義 API 端點的主應用文件。
- **auth.py**:處理身份驗證機制。
- **cache.py**:實現快取功能。
- **config.py**:包含 API 的配置設置。
- **detection.py**:使用 YOLOv8 模型進行物件檢測。
- **model_downloader.py**:處理 YOLOv8 模型的下載和加載。
- **models.py**:定義數據模型和結構。
- **security.py**:實現安全功能。

請確保檢查並調整 `config.py` 中的配置設置以適應您的具體需求。
67 changes: 67 additions & 0 deletions examples/YOLOv8_server_api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
🇬🇧 [English](./README.md) | 🇹🇼 [繁體中文](./README-zh-tw.md)

# YOLOv8 Server API example

This section an example implementation of a YOLOv8 Server API, designed to facilitate object detection using the YOLOv8 model. This guide provides information on how to use, configure, and understand the features of this API.

## Usage

3. **Run the server:**
```sh
python app.py
```

or

```sh
gunicorn -w 1 -b 0.0.0.0:8000 "examples.YOLOv8_server_api.app:app"
```

4. **Send a request to the API:**
- Use tools like `curl`, Postman, or your web browser to send a request to the server.
- Example using `curl`:
```sh
curl -X POST -F "file=@path/to/your/image.jpg" http://localhost:8000/detect
```

## Features

- **Authentication**: Secure the API with authentication mechanisms.
- **Caching**: Improve performance with caching of detection results.
- **Model Download**: Automated downloading and loading of the YOLOv8 model.
- **Configuration**: Flexible configuration options to customise the API.
- **Object Detection**: Perform object detection on uploaded images using YOLOv8.
- **Error Handling**: Robust error handling to manage different scenarios gracefully.

## Configuration

The API can be configured through the `config.py` file. Below are some of the key configuration options available:

- **Server Settings**:
- `HOST`: The hostname to run the server on. Default is `0.0.0.0`.
- `PORT`: The port to run the server on. Default is `8000`.

- **Model Settings**:
- `MODEL_PATH`: Path to the YOLOv8 model file.
- `CONFIDENCE_THRESHOLD`: Confidence threshold for object detection.

- **Cache Settings**:
- `CACHE_ENABLED`: Enable or disable caching. Default is `True`.
- `CACHE_EXPIRY`: Cache expiry time in seconds. Default is `3600`.

- **Authentication Settings**:
- `AUTH_ENABLED`: Enable or disable authentication. Default is `True`.
- `SECRET_KEY`: Secret key for JWT authentication.

## File Overview

- **app.py**: Main application file that starts the server and defines the API endpoints.
- **auth.py**: Handles authentication mechanisms.
- **cache.py**: Implements caching functionalities.
- **config.py**: Contains configuration settings for the API.
- **detection.py**: Performs object detection using the YOLOv8 model.
- **model_downloader.py**: Handles downloading and loading of the YOLOv8 model.
- **models.py**: Defines data models and schemas.
- **security.py**: Implements security features.

Ensure to review and adjust the configuration settings in `config.py` to suit your specific requirements.
Loading

0 comments on commit a70c042

Please sign in to comment.