一、在yolo11源码文件夹创建一个train.py
内容如下:
from ultralytics import YOLOif __name__ == '__main__':model = YOLO(r'ultralytics/cfg/models/11/yolo11.yaml')model.train(data=r'D:/yolo11/WiderPerson_yolo/WiderPerson_yolo/WiderPerson_yolo.yaml',imgsz=(640,384), # 训练图片大小,默认640workers=5,epochs=200, # 训练轮次,默认100batch=5, # 训练批次,默认16project='runs', # 项目文件夹的名,默认为runsname='exp', # 用于保存训练文件夹名,默认exp,依次累加device='0', # 要运行的设备 device =0 是GPU显卡训练,device = cpu)
二、指定数据集路径
2.1 WiderPerson_yolo.yaml内容:
# train and val data as 1) directory: path/images/, 2) file: path/images.txt, or 3) list: [path1/images/, path2/images/]
train: images/train #8000张图片
val: images/val #1000张图片
test:# number of classes
nc: 1# class names
names: ["person"]
2.2 训练集图像
2.3 训练集标签
2.4 验证集图像
2.5 验证集标签
三、运行pycharm
配置conda环境,然后点击运行