Yolov5s/README.md
2026-03-18 09:49:28 +00:00

87 lines
1.7 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# YOLOv5 訓練與部署流程
## 環境設置
使用 CMD 操作。
建立一個可以運行 YOLOv5 的 conda 環境。
## 資料集準備
1. 從 Roboflow 下載 **YOLOv8 格式**的資料集,放到專案目錄(例如 `data/` 下)
2. 修改資料集內的 `data.yaml`,依照以下格式調整路徑:
```yaml
path: C:/Users/rd_de/yolov5git/data/your-dataset
train: train/images
val: valid/images
test: test/images
nc: 3 # 類別數量
names: ['class1', 'class2', 'class3']
```
## 訓練模型
`cd``yolov5/` 目錄,再執行:
```bash
python train.py \
--data C:/Users/rd_de/yolov5git/data/10-02+10-01+10-038class/data.yaml \
--weights for720best.pt \
--img 640 \
--batch-size 8 \
--epochs 300 \
--device 0
```
訓練完成後,結果與權重檔位於:
```
runs/train/expX/weights/best.pt
```
## 推論測試
```bash
python detect.py \
--weights runs/train/exp9/weights/best.pt \
--source test14data/test/images \
--img 640 \
--conf 0.25 \
--device 0
```
## 轉換 ONNX
```bash
python exporting/yolov5_export.py --data data/mepretrained_paths_720.yaml
```
簡化 ONNX 模型:
```bash
python -m onnxsim \
runs/train/exp24/weights/best.onnx \
runs/train/exp24/weights/best_simplified.onnx
```
## Kneron ToolchainDocker
啟動 Kneron Toolchain 容器(在 WSL 中執行):
```bash
docker run --rm -it \
-v $(wslpath -u 'C:\Users\rd_de\golfaceyolov5\yolov5'):/workspace/yolov5 \
kneron/toolchain:latest
```
使用onnx2nefxxx.py來轉檔(520、630、720)
520需要使用 removenode.py
從容器複製編譯好的 `.nef` 模型到本機:
```bash
docker cp <container_id>:/data1/kneron_flow/runs/train/exp6/weights/models_630.nef \
C:\Users\rd_de\golfaceyolov5\yolov5\runs\train\exp6\weights
```