DetectionModelTraining/README.md

157 lines
3.1 KiB
Markdown
Raw 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.

# 鞋子检测模型训练指南
## 方案640x640 单模型部署时用2窗口
**训练阶段**
- 输入640x640 完整图片
- 模型YOLOv8s
- 输出640x640 模型文件
**部署阶段**pipeline配置
- 原图 1920x1080
- 分成 2 个 960x1080 窗口
- 每个窗口 resize 到 640x640 送入模型
- 合并检测结果
---
## 目录结构
```
train/
├── README.md # 本文件
├── 01_download_dataset.py # 下载鞋子数据集(推荐 Open Images
├── 02_train.bat # Windows 一键训练脚本
├── 03_export_onnx.bat # 导出 ONNX 脚本
├── 04_convert_rknn.py # 转换为 RKNN 脚本
├── 05_prepare_ppe_shoe_subset.py # 提取 PPE 鞋子单类子集
├── 06_finetune_ppe.bat # 用 PPE 鞋子子集做二阶段微调
├── data.yaml.template # 数据集配置文件
└── samples/ # 示例图片
├── calibration/
├── test_images/
└── README.md
```
---
## 快速开始
### 1. 下载数据集
```bash
cd train
python 01_download_dataset.py --source openimages --max-samples 5000
```
### 2. 准备配置
```bash
脚本会自动生成 datasets/openimages-shoes-yolo/data.yaml
```
### 3. 训练640x640
```bash
02_train.bat
```
或手动:
```bash
yolo detect train \
data=datasets/openimages-shoes-yolo/data.yaml \
model=yolov8s.pt \
epochs=150 \
imgsz=640 \
batch=16 \
device=0
```
**训练参数**
- 模型YOLOv8s速度和精度平衡
- 输入640x640
- 预计时间30-60分钟
### 4. 导出 ONNX
```bash
03_export_onnx.bat
```
### 5. 转换为 RKNN
在 Ubuntu PC 上:
```bash
python 04_convert_rknn.py runs/detect/train/weights/best.onnx -o shoe_detector_640.rknn -t rk3588
```
### 6. 部署2窗口配置
复制到 RK3588
```bash
scp shoe_detector_640.rknn orangepi@<rk3588_ip>:/home/orangepi/apps/OrangePi3588Media/models/
```
Pipeline 配置部署阶段用2窗口
```json
{
"id": "pre_shoe",
"type": "preprocess",
"windows": [
{"x": 0, "y": 0, "w": 960, "h": 1080},
{"x": 960, "y": 0, "w": 960, "h": 1080}
],
"dst_w": 640,
"dst_h": 640
}
```
### 7. 方案 APPE 二阶段微调
当 Open Images 基础模型训练完成后,可继续用 PPE 鞋子子集做场景微调:
```bash
python 05_prepare_ppe_shoe_subset.py
06_finetune_ppe.bat
```
PPE 鞋子子集来源:
- `boots`
- `no_boots`
这两个类会统一映射成单类:
- `shoe`
---
## 类别说明Open Images
Open Images 官方鞋类层级中,`Footwear` 的子类包括:
- `Boot`
- `Sandal`
- `High heels`
- `Roller skates`
本项目推荐下载:
- `Footwear`
- `Boot`
可选补充:
- `Sandal`
不建议默认加入:
- `High heels`
- `Roller skates`
训练时统一映射为单一类别:
- `0: shoe`
这样模型目标更聚焦,先尽量把鞋子稳定检出,再在后处理里判断是否为黑色鞋。
---
## 相关链接
- [Open Images 数据集](https://storage.googleapis.com/openimages/web/index.html)
- [Ultralytics YOLOv8](https://docs.ultralytics.com/)