---
# System prepended metadata

title: Yolov5 使用
tags: [yolov5]

---

###### tags: `yolov5`
# Yolov5 使用

## 建立 Dataset

1. 複製 image, label ( 順便校準 bbox )
2. 將 label 做標準化
3. 儲存成以下格式
:::warning
> - datasets
>    - images
>        - train
>            - 00001.png
>            - ...
>    - labels
>        - train
>            - 00001.txt
>            - ...
> 
:::

<br>

## 訓練 Model
```python=
# 訓練
!python train.py --epochs 100 --batch-size 64  --data drone.yaml --cfg yolov5s.yaml --weights '' --workers 0
```
- `--epochs EPOCHS` : 訓練次數
- `--batch-size BATCH_SIZE`
- `--data DATA資訊檔(.yaml)`
- `--cfg Model檔(.yaml)`
- `--workers WORKER數量`

```python=
# 查看所有訓練參數
!python train.py --help
```

訓練出的結果存放在  **./runs/train/expN/**

<br>

## Data Yaml 檔設定

檔案要存放在  **./data/**

```yaml=
# 路徑
path: ../datasets/drone
train: images/train
val: images/train
test:

# 物件類別設定
nc: 4
names: ['car','hov','person','motorcycle']
```

<br>

## Validate Model
```python=
!python val.py --weights runs/train/exp4/weights/best.pt --data drone.yaml --half --workers 0
```

結果存放在  **./runs/val/expN/**

<br>

## 用 Model 進行偵測
```python=
!python detect.py --weights runs/train/exp4/weights/best.pt --conf 0.25 --source ../public
```

結果存放在  **./runs/detect/expN/**