yolov11用wider face数据集进行人脸检测任务map70+怎么提高 train.py如下:from ultralytics import YOLO
def main_train():
model = YOLO('/mnt/d/yolov11/ultralytics-main/ultralytics/cfg/models/11/yolo11s.yaml') # 或者选择其他预训练模型,例如 'yolov5m.pt', 'yolov5l.pt', 'yolov5x.pt
results = model.train(
data='/mnt/d/yolov11/ultralytics-main/data.yaml', # 替换为你的data.yaml路径
epochs=300,
imgsz=640, #根据需要调整图像大小
batch=4,
project='./runs/detect',
name='wider_face_detection',
optimizer='AdamW',
device='0', # 使用GPU编号,'0'表示第一个GPU
save=True,
cache='disk',
lr0=0.01, # 初始学习率
lrf=0.005, # 最终学习率
warmup_epochs=15, # 学习率预热
copy_paste=0.1,
close_mosaic=10,
overlap_mask=True, # 增强mask预测
cos_lr=True,
workers=4,
)
if __name__ == '__main__':
main_train() data.yaml如下:train: /mnt/d/yolov11/ultralytics-main/datasets/images/train/
val: /mnt/d/yolov11/ultralytics-main/datasets/images/val/
test: /mnt/d/yolov11/ultralytics-main/datasets/images/test/
nc: 1
# class names
names: ['face']
augment:
# 几何变换
mosaic: 1.0
mixup: 0.2
copy_paste: 0.5 # 小目标复制增强
degrees: 10.0 # ±10°旋转增强:ml-citation{ref="3,6" data="citationList"}
perspective: 0.0005 # 微透视变形:ml-citation{ref="5" data="citationList"}
# 色彩扰动
hsv_h: 0.015 #减少色相扰动
hsv_s: 0.7 # 增强饱和度扰动
hsv_v: 0.4 # 亮度扰动:ml-citation{ref="10" data="citationList"}
translate: 0.1 # 减少平移避免小目标丢失
# 小目标优化
small_object_scale: 3.0 # 避免过度放大小目标:ml-citation{ref="5" data="citationList"}
fliplr: 0.5 # 水平翻转(人脸对称性):ml-citation{ref="6" data="citationList"}
flipud: 0.2 # 新增上下翻转
yolo11.yaml如下:# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
# Ultralytics YOLO11 object detection model with P3/8 - P5/32 outputs
# Model docs: https://docs.ultralytics.com/models/yolo11
# Task docs: https://docs.ultralytics.com/tasks/detect
# Parameters
nc: 1 # number of classes
scales: # model compound scaling constants, i.e. 'model=yolo11n.yaml' will call yolo11.yaml with scale 'n'
# [depth, width, max_channels]
n: [0.50, 0.25, 1024] # summary: 181 layers, 2624080 parameters, 2624064 gradients, 6.6 GFLOPs
s: [0.50, 0.50, 1024] # summary: 181 layers, 9458752 parameters, 9458736 gradients, 21.7 GFLOPs
m: [0.50, 1.00, 512] # summary: 231 layers, 20114688 parameters, 20114672 gradients, 68.5 GFLOPs
l: [1.00, 1.00, 512] # summary: 357 layers, 25372160 parameters, 25372144 gradients, 87.6 GFLOPs
x: [1.00, 1.50, 512] # summary: 357 layers, 56966176 parameters, 56966160 gradients, 196.0 GFLOPs
# YOLO11n backbone
backbone:
# [from, repeats, module, args]
- [-1, 1, Conv, [64, 3, 2]] # 0-P1/2
- [-1, 1, Conv, [128, 3, 2]] # 1-P2/4
- [-1, 2, C3k2, [256, False, 0.25]]
- [-1, 1, Conv, [256, 3, 2]] # 3-P3/8
- [-1, 2, C3k2, [512, False, 0.25]]
- [-1, 1, Conv, [512, 3, 2]] # 5-P4/16
- [-1, 2, C3k2, [512, True]]
- [-1, 1, Conv, [1024, 3, 2]] # 7-P5/32
- [-1, 2, C3k2, [1024, True]]
- [-1, 1, SPPF, [1024, 5]] # 9
- [-1, 2, SE, [1024]] #添加注意力模块
- [-1, 2, C2PSA, [1024]] # 10
# YOLO11n head
head:
- [-1, 1, nn.Upsample, [None, 2, "nearest"]]
- [[-1, 6], 1, Concat, [1]] # cat backbone P4
- [-1, 2, C3k2, [512, False]] # 13
- [-1, 1, nn.Upsample, [None, 2, "nearest"]]
- [[-1, 4], 1, Concat, [1]] # cat backbone P3
- [-1, 2, C3k2, [256, False]] # 16 (P3/8-small)
- [-1, 1, nn.Upsample, [None, 2, "nearest"]] #新添P2
- [[-1, 2], 1, Concat, [1]] # cat backbone P2
- [-1, 2, C3k2, [128, False]] # 19 (P2/4-xsmall)
- [-1, 1, Conv, [256, 3, 2]]
- [[-1, 16], 1, Concat, [1]] # cat head P3 #新添P2
- [-1, 2, C3k2, [256, False]] # 22 (P3/8-medium)
- [-1, 1, Conv, [256, 3, 2]]
- [[-1, 13], 1, Concat, [1]] # cat head P4
- [-1, 2, C3k2, [512, False]] # 19 (P4/16-medium)
- [-1, 1, Conv, [512, 3, 2]]
- [[-1, 10], 1, Concat, [1]] # cat head P5
- [-1, 2, C3k2, [1024, True]] # 22 (P5/32-large)
- [[16, 19, 22], 1, Detect, [nc]] # Detect(P3, P4, P5)