1. 概述
訓(xùn)練一個(gè)服飾的分類器,這里采用yolo11x的神經(jīng)網(wǎng)絡(luò)架構(gòu)訓(xùn)練。

2. 數(shù)據(jù)集準(zhǔn)備
2.1. 公開數(shù)據(jù)集
DeepFashion2
https://github.com/switchablenorms/DeepFashion2
https://github.com/switchablenorms/DeepFashion2/blob/master/evaluation/deepfashion2_to_coco.py
Coco
https://github.com/ultralytics/ultralytics/blob/main/ultralytics/cfg/datasets/coco128.yaml
2.2. 數(shù)據(jù)標(biāo)注工具
roboflow數(shù)據(jù)標(biāo)注工具,可以export yolo格式數(shù)據(jù)集
https://roboflow.com/Refine high-quality datasets and visual AI models
https://github.com/voxel51/fiftyone
https://voxel51.com/
本文采用一個(gè)私有數(shù)據(jù)集,一共7w+圖片,按照
6:2:2分為訓(xùn)練數(shù)據(jù)集、驗(yàn)證數(shù)據(jù)集和測試數(shù)據(jù)集。
3. 訓(xùn)練
3.1. 訓(xùn)練代碼
from ultralytics import YOLO
from ultralytics import settings
import wandb
from wandb.integration.ultralytics import add_wandb_callback
settings.update(dict(
datasets_dir="/data/yolo/dataset/yolo",
weights_dir="/data/yolo/dataset/yolo/weights",
runs_dir="/data/yolo/dataset/yolo/runs",
wandb=True,
comet=False,
clearml=False,
tensorboard=False,
))
project = "fashion-detector-19cls"
# Load a model
model = YOLO("yolo11x.pt")
# model = YOLO("fashion-detector-19cls/yolo11x/weights/last.pt")
add_wandb_callback(model, enable_model_checkpointing=True)
# Train the model
data_config = "dataset/yolo/haier_fashion.yaml"
results = model.train(
data=data_config, epochs=100,
imgsz=640, device=[2,3,4], batch=60,
project=project, name="yolo11x",
# resume=True
)
注意:上述代碼是預(yù)訓(xùn)練,如果做繼續(xù)訓(xùn)練,只需要
加載續(xù)訓(xùn)練model和resume=True即可。
3.2. WandB訓(xùn)練過程指標(biāo)分析
Epoch=100的訓(xùn)練結(jié)果
| Metric | Value |
|---|---|
| lr/pg0 | 0.0002 |
| lr/pg1 | 0.0002 |
| lr/pg2 | 0.0002 |
| metrics/mAP50(B) | 0.83648 |
| metrics/mAP50-95(B) | 0.6932 |
| metrics/precision(B) | 0.81303 |
| metrics/recall(B) | 0.7881 |
| train/box_loss | 0.45027 |
| train/cls_loss | 0.23466 |
| train/dfl_loss | 0.96325 |
| val/box_loss | 0.65851 |
| val/cls_loss | 0.49071 |
| val/dfl_loss | 1.08395 |


4. 測試
- 服飾類別一共19個(gè)
Dress Coat Top Jacket Skirt Suspender Short Pant Swim-Suit Shoe Cap Glass Watch Bag Belt Glove Scarf Jewelry Non-Fashion
- 對(duì)照Test數(shù)據(jù)集與預(yù)測結(jié)果


注意:正常情況下,需要進(jìn)行
模型評(píng)估,通過mAP、Precission、Recall等指標(biāo)評(píng)價(jià)模型的性能,尤其是泛化能力。這里先不做了。
5. 腳本說明
5.1. 準(zhǔn)備數(shù)據(jù)
python -m "scripts.data_prepare"
5.2. 訓(xùn)練
python train.py
5.3. 預(yù)測
python predict.py
or
python check_data.py