基于 YOLOv8 的服装类型检测系统,支持多种服装类别的实时检测。
yolo-clothing-detect/
├── configs/
│ └── data.yaml # 核心!定义分类类别和训练/验证集路径
├── scripts/
│ ├── train.py # 启动训练与Resume恢复脚本
│ └── predict.py # 推理测试脚本
├── requirements.txt # 项目依赖
└── README.md # 项目文档
# 克隆项目
git clone https://github.com/cgiaol/cloth-train.git
cd cloth-train
# 安装依赖
pip install -r requirements.txt将你的数据集按照以下结构组织:
dataset/
├── images/
│ ├── train/
│ │ ├── img1.jpg
│ │ └── ...
│ ├── val/
│ │ ├── img2.jpg
│ │ └── ...
│ └── test/
│ └── ...
└── labels/
├── train/
│ ├── img1.txt
│ └── ...
├── val/
│ └── ...
└── test/
└── ...
然后修改 configs/data.yaml 中的路径。
python scripts/train.py --data configs/data.yaml --model yolov8n.pt --epochs 100 --batch 16python scripts/train.py --data configs/data.yaml --resume runs/detect/clothing_detection/weights/last.pt --epochs 150python scripts/train.py --help可用的模型大小:
yolov8n- Nano(最小,速度最快)yolov8s- Smallyolov8m- Mediumyolov8l- Largeyolov8x- Extra Large(精度最高,速度最慢)
python scripts/predict.py --model runs/detect/clothing_detection/weights/best.pt --source path/to/image.jpg --savepython scripts/predict.py --model runs/detect/clothing_detection/weights/best.pt --source path/to/video.mp4 --savepython scripts/predict.py --model runs/detect/clothing_detection/weights/best.pt --source 0python scripts/predict.py --helppath: /path/to/dataset # 数据集根路径
train: images/train # 训练集相对路径
val: images/val # 验证集相对路径
test: images/test # 测试集相对路径
nc: 10 # 类别数量
names: [...] # 类别名称列表训练结果会保存在 runs/detect/clothing_detection/ 目录中:
weights/best.pt- 最优模型权重weights/last.pt- 最后一个检查点results.csv- 训练指标plots/- 可视化结果
✅ 支持 YOLOv8 所有模型大小
✅ 完整的训练恢复(Resume)功能
✅ 灵活的推理选项(图片、视频、实时流)
✅ 自动混合精度训练(AMP)
✅ 早期停止(Early Stopping)
✅ 易用的命令行接口
# 1. 环境设置
pip install -r requirements.txt
# 2. 训练(100个epoch)
python scripts/train.py --data configs/data.yaml --epochs 100 --batch 16
# 3. 模型评估
python scripts/predict.py --model runs/detect/clothing_detection/weights/best.pt --source dataset/images/test
# 4. 如果需要继续训练
python scripts/train.py --data configs/data.yaml --resume runs/detect/clothing_detection/weights/last.pt --epochs 150- 在 GPU 上训练获得最佳性能
- 确保数据集标注格式正确(YOLO 格式)
- 根据硬件调整
--batch大小 - 使用
--patience参数启用早期停止
MIT License
作者: cgiaol
创建时间: 2026-07-23