1、 下载Funiture数据集
http://kaggle.com/datasets/nicolaasregnier/furniture
并生成数据配置文件 data.yaml
import yaml
import os
dataDir ="你的工程路径/Furniture/sam_preds_training_set"
os.path.join(dataDir, 'train')
num_classes = 2
classes = ['Chair', 'Sofa']
file_dict = {
'train': os.path.join(dataDir, 'train'),
'val': os.path.join(dataDir, 'val'),
'test': os.path.join(dataDir, 'test'),
'nc': num_classes,
'names': classes
}
with open(os.path.join("./", 'data.yaml'), 'w+') as f:
yaml.dump(file_dict, f)
二、训练
from ultralytics import YOLO
# Load YOLOv10n model from scratch
model = YOLO("yolov10n.yaml").load("yolov10n.pt")
model.train(data="data.yaml", epochs=100, imgsz=640,freeze=22)
三、测试
model = YOLO("生成的模型路径/ultralytics/runs/detect/train16/weights/best.pt") # 100epchs
res = model.predict("你的数据集路径/Furniture/sam_preds_training_set/test/images/Sofa--365-_jpg.rf.8ec5e13d87ce8491a9e8b4c999ea7330.jpg")
res[0].save("result-chair.jpg")
注意要训练100epochs 效果好
注意的是这个分割数据集来训练检测数据集,都可以,奇怪了