YOLO11模型训练 | 目标检测与跟踪 | 实例分割 | 关键点姿态估计

news2024/11/26 22:26:40

前言

本文分享YOLO11的模型推理,检测任务包括物体分类、目标检测与跟踪、实例分割 、关键点姿态估计、旋转目标检测等。

安装方式支持:默认的使用pip进行安装;也支持直接调用YOLO11源码,灵活便捷修改源码。

本文支持自定义数据集,并提供详细训练参数的train.py版本,方便大家训练测试。

首先安装YOLO11

1、官方默认安装方式

通过运行 pip install ultralytics 来快速安装 Ultralytics 包

安装要求

  • Python 版本要求:Python 版本需为 3.8 及以上,支持 3.8、3.9、3.10、3.11、3.12 这些版本。
  • PyTorch 版本要求:需要 PyTorch 版本不低于 1.8。

然后使用清华源,进行加速安装

pip install ultralytics -i https://pypi.tuna.tsinghua.edu.cn/simple/

2、直接调用YOLO11源码方式(推荐)

首先到YOLO11代码地址,下载源代码:https://github.com/ultralytics/ultralytics

  • 在 GitHub 仓库页面上,用户点击绿色的 "Code" 按钮后,会弹出一个选项框。
  • 选择通过 HTTPS 或 GitHub CLI 克隆仓库,也可以点击框中的 "Download ZIP" 按钮,将整个仓库下载为 ZIP 压缩包到本地。

解压ultralytics-main.zip文件,目录结构如下所示

ultralytics-main/
    .github/
    docker/
    docs/
    examples/
    runs/
    tests/
    ultralytics/
    .gitignore
    CITATION.cff
    CONTRIBUTING.md
    LICENSE
    mkdocs.yml
    pyproject.toml
    README.md
    README.zh-CN.md

然后在ultralytics同级目录中,添加需要训练的代码(train.py)

以及测试数据的文件夹:datasets,权重文件目录:weights

ultralytics-main/
    .github/
    datasets/
    docker/
    docs/
    examples/
    runs/
    tests/
    ultralytics/
    weights/
    .gitignore
    CITATION.cff
    CONTRIBUTING.md
    LICENSE
    mkdocs.yml
    print_dir.py
    pyproject.toml
    README.md
    README.zh-CN.md
    train.py

weights目录可以存放不同任务的权重,比如:yolo11m-cls.pt、yolo11m-obb.pt、yolo11m-pose.pt、yolo11m-seg.pt、yolo11m.pt、yolo11n.pt等。

train.py文件是和ultralytics文件夹同一级目录的

后面可以直接调用ultralytics源代码中的函数、类和依赖库等,如果有需要直接修改ultralytics中的代码,比较方便。

一、YOLO11模型训练——实例分割

1、模型训练简洁版

YOLO11模型训练,整体思路流程:

  • 加载模型:使用 YOLO 类指定模型的配置文件 yolo11m-seg.yaml 并加载预训练权重 yolo11m-seg.pt
  • 执行训练:调用 model.train() 方法,指定数据集 coco8_lgp.yaml,设置训练轮数为 10,图像大小为 640 像素。
  • 保存训练结果:训练完成后,结果保存在 results 中,包含损失和精度等信息。

示例代码,如下所示: 

from ultralytics import YOLO

# 加载YOLO模型的配置文件,并加载预训练权重文件
model = YOLO("yolo11m-seg.yaml").load("weights/yolo11m-seg.pt")  

# 使用coco8_lgp.yaml数据集进行训练,训练10个epoch,并将图像大小设置为640像素
results = model.train(data="coco8_lgp.yaml", epochs=10, imgsz=640)

然后执行程序,开始训练:

Ultralytics 8.3.7 🚀 Python-3.8.16 torch-1.13.1 CPU (unknown)

......
Logging results to runs\segment\train6
Starting training for 10 epochs...
Closing dataloader mosaic

      Epoch    GPU_mem   box_loss   seg_loss   cls_loss   dfl_loss  Instances       Size
       1/10         0G     0.6116      2.282      1.139      1.125         13        640: 100%|██████████| 1/1 [00:15<00:00, 15.61s/it]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95)     Mask(P          R      mAP50  mAP50-95): 100%|██████████| 1/1 [00:04<00:00,  4.62s/it]
                   all          4         17      0.778      0.963       0.97      0.776      0.778      0.963      0.967      0.691

.....

Epoch    GPU_mem   box_loss   seg_loss   cls_loss   dfl_loss  Instances       Size
      10/10         0G     0.6489      1.423     0.6046     0.9767         13        640: 100%|██████████| 1/1 [00:13<00:00, 13.47s/it]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95)     Mask(P          R      mAP50  mAP50-95): 100%|██████████| 1/1 [00:04<00:00,  4.76s/it]
                   all          4         17      0.836      0.965      0.968      0.753      0.836      0.965      0.963      0.666

10 epochs completed in 0.061 hours.
Optimizer stripped from runs\segment\train6\weights\last.pt, 45.3MB
Optimizer stripped from runs\segment\train6\weights\best.pt, 45.3MB

模型结构的配置文件:yolo11m-seg.yaml,模型权重:weights/yolo11m-seg.pt,存放数据集文件:coco8_lgp.yaml;这些后面在详细分析。

训练完成后,能看到runs\segment\train6保存的权重和训练信息

训练图像和标签的示例:

2、详细训练参数版本(重要)

YOLO11模型训练,详细参数版本的思路流程:

  • 加载模型:使用 YOLO 类指定模型的配置文件 yolo11s-seg.yaml 并加载预训练权重 yolo11s-seg.pt
  • 定义训练参数:通过字典 train_params 定义了一系列训练参数,涵盖了训练过程中可能涉及的配置项,如数据集路径、训练轮数、图像大小、优化器、数据增强等。
  • 执行训练:使用 model.train(**train_params) 将定义的训练参数传入模型,开始训练。
  • 保存训练结果:训练完成后,结果保存在 results 中,包含损失和精度等信息。

示例代码,如下所示: 

from ultralytics import YOLO

# 加载预训练的模型
model = YOLO("yolo11s-seg.yaml").load("weights_yolo/yolo11s-seg.pt")  

# 定义训练参数,添加默认值、范围和中文注释
train_params = {
    'data': "coco8_lgp.yaml",   # 数据集配置文件路径,需要自定义修改
    'epochs': 10,               # 总训练轮次,默认值 100,范围 >= 1
    'imgsz': 640,               # 输入图像大小,默认值 640,范围 >= 32
    'batch': 8,                # 批次大小,默认值 16,范围 >= 1
    'save': True,               # 是否保存训练结果和模型,默认值 True
    'save_period': -1,          # 模型保存频率,默认值 -1,表示只保存最终结果
    'cache': False,             # 是否缓存数据集,默认值 False
    'device': None,             # 训练设备,默认值 None,支持 "cpu", "gpu"(device=0,1), "mps"
    'workers': 8,               # 数据加载线程数,默认值 8,影响数据预处理速度
    'project': None,            # 项目名称,保存训练结果的目录,默认值 None
    'name': None,            # 训练运行的名称,用于创建子目录保存结果,默认值 None
    'exist_ok': False,          # 是否覆盖已有项目/名称目录,默认值 False
    'optimizer': 'auto',        # 优化器,默认值 'auto',支持 'SGD', 'Adam', 'AdamW'
    'verbose': True,            # 是否启用详细日志输出,默认值 False
    'seed': 0,                  # 随机种子,确保结果的可重复性,默认值 0
    'deterministic': True,      # 是否强制使用确定性算法,默认值 True
    'single_cls': False,        # 是否将多类别数据集视为单一类别,默认值 False
    'rect': False,              # 是否启用矩形训练(优化批次图像大小),默认值 False
    'cos_lr': False,            # 是否使用余弦学习率调度器,默认值 False
    'close_mosaic': 10,         # 在最后 N 轮次中禁用 Mosaic 数据增强,默认值 10
    'resume': False,            # 是否从上次保存的检查点继续训练,默认值 False
    'amp': True,                # 是否启用自动混合精度(AMP)训练,默认值 True
    'fraction': 1.0,            # 使用数据集的比例,默认值 1.0
    'profile': False,           # 是否启用 ONNX 或 TensorRT 模型优化分析,默认值 False
    'freeze': None,             # 冻结模型的前 N 层,默认值 None
    'lr0': 0.01,                # 初始学习率,默认值 0.01,范围 >= 0
    'lrf': 0.01,                # 最终学习率与初始学习率的比值,默认值 0.01
    'momentum': 0.937,          # SGD 或 Adam 的动量因子,默认值 0.937,范围 [0, 1]
    'weight_decay': 0.0005,     # 权重衰减,防止过拟合,默认值 0.0005
    'warmup_epochs': 3.0,       # 预热学习率的轮次,默认值 3.0
    'warmup_momentum': 0.8,     # 预热阶段的初始动量,默认值 0.8
    'warmup_bias_lr': 0.1,      # 预热阶段的偏置学习率,默认值 0.1
    'box': 7.5,                 # 边框损失的权重,默认值 7.5
    'cls': 0.5,                 # 分类损失的权重,默认值 0.5
    'dfl': 1.5,                 # 分布焦点损失的权重,默认值 1.5
    'pose': 12.0,               # 姿态损失的权重,默认值 12.0
    'kobj': 1.0,                # 关键点目标损失的权重,默认值 1.0
    'label_smoothing': 0.0,     # 标签平滑处理,默认值 0.0
    'nbs': 64,                  # 归一化批次大小,默认值 64
    'overlap_mask': True,       # 是否在训练期间启用掩码重叠,默认值 True
    'mask_ratio': 4,            # 掩码下采样比例,默认值 4
    'dropout': 0.0,             # 随机失活率,用于防止过拟合,默认值 0.0
    'val': True,                # 是否在训练期间启用验证,默认值 True
    'plots': True,             # 是否生成训练曲线和验证指标图,默认值 True 

    # 数据增强相关参数
    'hsv_h': 0.015,             # 色相变化范围 (0.0 - 1.0),默认值 0.015
    'hsv_s': 0.7,               # 饱和度变化范围 (0.0 - 1.0),默认值 0.7
    'hsv_v': 0.4,               # 亮度变化范围 (0.0 - 1.0),默认值 0.4
    'degrees': 0.0,             # 旋转角度范围 (-180 - 180),默认值 0.0
    'translate': 0.1,           # 平移范围 (0.0 - 1.0),默认值 0.1
    'scale': 0.5,               # 缩放比例范围 (>= 0.0),默认值 0.5
    'shear': 0.0,               # 剪切角度范围 (-180 - 180),默认值 0.0
    'perspective': 0.0,         # 透视变化范围 (0.0 - 0.001),默认值 0.0
    'flipud': 0.0,              # 上下翻转概率 (0.0 - 1.0),默认值 0.0
    'fliplr': 0.5,              # 左右翻转概率 (0.0 - 1.0),默认值 0.5
    'bgr': 0.0,                 # BGR 色彩顺序调整概率 (0.0 - 1.0),默认值 0.0
    'mosaic': 1.0,              # Mosaic 数据增强 (0.0 - 1.0),默认值 1.0
    'mixup': 0.0,               # Mixup 数据增强 (0.0 - 1.0),默认值 0.0
    'copy_paste': 0.0,          # Copy-Paste 数据增强 (0.0 - 1.0),默认值 0.0
    'copy_paste_mode': 'flip',  # Copy-Paste 增强模式 ('flip' 或 'mixup'),默认值 'flip'
    'auto_augment': 'randaugment',  # 自动增强策略 ('randaugment', 'autoaugment', 'augmix'),默认值 'randaugment'
    'erasing': 0.4,             # 随机擦除增强比例 (0.0 - 0.9),默认值 0.4
    'crop_fraction': 1.0,       # 裁剪比例 (0.1 - 1.0),默认值 1.0

}

# 进行训练
results = model.train(**train_params)

在ultralytics工程中,没有了超参数文件了,需要从model.train( )函数参数设置,所以才会有上面的示例代码。

然后执行程序,开始训练~

这里的训练参数可以再看看官方的:https://docs.ultralytics.com/modes/train/#train-settings

3、模型结构的配置文件

首先分析模型结构的配置文件:yolo11m-seg.yaml,它所在位置是

ultralytics/cfg/models/11/yolo11-seg.yaml

里面有详细的模型结构参数信息

如果需要修改YOLO11的实例分割-模型结构,可以在这个文件进行修改

# Parameters
nc: 80 # number of classes
scales: # model compound scaling constants, i.e. 'model=yolo11n-seg.yaml' will call yolo11-seg.yaml with scale 'n'
  # [depth, width, max_channels]
  n: [0.50, 0.25, 1024] # summary: 355 layers, 2876848 parameters, 2876832 gradients, 10.5 GFLOPs
  s: [0.50, 0.50, 1024] # summary: 355 layers, 10113248 parameters, 10113232 gradients, 35.8 GFLOPs
  m: [0.50, 1.00, 512] # summary: 445 layers, 22420896 parameters, 22420880 gradients, 123.9 GFLOPs
  l: [1.00, 1.00, 512] # summary: 667 layers, 27678368 parameters, 27678352 gradients, 143.0 GFLOPs
  x: [1.00, 1.50, 512] # summary: 667 layers, 62142656 parameters, 62142640 gradients, 320.2 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, 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, 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, Segment, [nc, 32, 256]] # Detect(P3, P4, P5)

4、模型权重

然后看看weights/yolo11m-seg.pt,这样就是模型权重的路径,可以根据放置的路径,进行修改。

5、数据集路径

最后看看coco8_lgp.yaml文件,这个是存放数据集的,比较重要。

它所在位置是:ultralytics/cfg/datasets/coco8_lgp.yaml,同级目录下还存在许多数据集配置文件

比如:coco128.yaml、coco.yaml、DOTAv1.5.yaml、VOC.yaml、Objects365.yaml、Argoverse.yaml等等

 即下面代码的作用是一样的:

results = model.train(data="coco8_lgp.yaml", epochs=10, imgsz=640)
# results = model.train(data=r"C:/Users/liguopu/Downloads/ultralytics-main/ultralytics/cfg/datasets/coco8_lgp.yaml", epochs=10, imgsz=640)

coco8_lgp.yaml这个文件是我自定义的,内容如下:

里面指定了数据集的路径:path: C:\Users\liguopu\Downloads\ultralytics-main\datasets\coco8-seg,

数据集的路径path,需要根据实际数据路径进行修改

下面看看这个文件的内容:

# Ultralytics YOLO 🚀, AGPL-3.0 license

path: C:\Users\liguopu\Downloads\ultralytics-main\datasets\coco8-seg # dataset root dir
train: images\train # train images (relative to 'path') 4 images
val: images\val # val images (relative to 'path') 4 images
test: # test images (optional)

# Classes
names:
  0: person
  1: bicycle
  2: car
  3: motorcycle
  4: airplane
  5: bus
  6: train
  7: truck
  8: boat
  9: traffic light
  10: fire hydrant
  11: stop sign
  12: parking meter
  13: bench
  14: bird
  15: cat
  16: dog
  17: horse
  18: sheep
  19: cow
  20: elephant
  21: bear
  22: zebra
  23: giraffe
  24: backpack
  25: umbrella
  26: handbag
  27: tie
  28: suitcase
  29: frisbee
  30: skis
  31: snowboard
  32: sports ball
  33: kite
  34: baseball bat
  35: baseball glove
  36: skateboard
  37: surfboard
  38: tennis racket
  39: bottle
  40: wine glass
  41: cup
  42: fork
  43: knife
  44: spoon
  45: bowl
  46: banana
  47: apple
  48: sandwich
  49: orange
  50: broccoli
  51: carrot
  52: hot dog
  53: pizza
  54: donut
  55: cake
  56: chair
  57: couch
  58: potted plant
  59: bed
  60: dining table
  61: toilet
  62: tv
  63: laptop
  64: mouse
  65: remote
  66: keyboard
  67: cell phone
  68: microwave
  69: oven
  70: toaster
  71: sink
  72: refrigerator
  73: book
  74: clock
  75: vase
  76: scissors
  77: teddy bear
  78: hair drier
  79: toothbrush

# Download script/URL (optional)
download: https://github.com/ultralytics/assets/releases/download/v0.0.0/coco8.zip

二、YOLO11模型训练——目标检测

 其实和上面的代码,基本是一样的,只需改变模型权重和吗模型配置文件就可以了。

模型训练简洁版

YOLO11模型训练,整体思路流程:

  • 加载模型:使用 YOLO 类指定模型的配置文件 yolo11s.yaml 并加载预训练权重 yolo11s.pt
  • 执行训练:调用 model.train() 方法,指定数据集 coco8.yaml,设置训练轮数为 10,图像大小为 640 像素。
  • 保存训练结果:训练完成后,结果保存在 results 中,包含损失和精度等信息。

示例代码,如下所示: 

from ultralytics import YOLO

# 加载YOLO模型的配置文件,并加载预训练权重文件
model = YOLO("yolo11s.yaml").load("weights/yolo11s.pt")  

# 使用coco8.yaml数据集进行训练,训练10个epoch,并将图像大小设置为640像素
results = model.train(data="coco8.yaml", epochs=10, imgsz=640)

然后执行程序,开始训练:

Transferred 499/499 items from pretrained weights
Ultralytics 8.3.7 🚀 Python-3.8.16 torch-1.13.1 CPU (unknown) 
WARNING ⚠️ Upgrade to torch>=2.0.0 for deterministic training.
engine\trainer: task=detect, mode=train, model=yolo11s.yaml, data=coco8.yaml, epochs=10, time=None, patience=100, batch=16, imgsz=640, save=True, save_period=-1, cache=False, device=None, workers=8, project=None, name=train, exist_ok=False, pretrained=weights/yolo11s.pt, optimizer=auto, verbose=True, seed=0, deterministic=True, single_cls=False, rect=False, cos_lr=False, close_mosaic=10, resume=False, amp=True, fraction=1.0, profile=False, freeze=None, multi_scale=False, overlap_mask=True, mask_ratio=4, dropout=0.0, val=True, split=val, save_json=False, save_hybrid=False, conf=None, iou=0.7, max_det=300, half=False, dnn=False, plots=True, source=None, vid_stride=1, stream_buffer=False, visualize=False, augment=False, agnostic_nms=False, classes=None, retina_masks=False, embed=None, show=False, save_frames=False, save_txt=False, save_conf=False, save_crop=False, show_labels=True, show_conf=True, show_boxes=True, line_width=None, format=torchscript, keras=False, optimize=False, int8=False, dynamic=False, simplify=True, opset=None, workspace=4, nms=False, lr0=0.01, lrf=0.01, momentum=0.937, weight_decay=0.0005, warmup_epochs=3.0, warmup_momentum=0.8, warmup_bias_lr=0.1, box=7.5, cls=0.5, dfl=1.5, pose=12.0, kobj=1.0, label_smoothing=0.0, nbs=64, hsv_h=0.015, hsv_s=0.7, hsv_v=0.4, degrees=0.0, translate=0.1, scale=0.5, shear=0.0, perspective=0.0, flipud=0.0, fliplr=0.5, bgr=0.0, mosaic=1.0, mixup=0.0, copy_paste=0.0, copy_paste_mode=flip, auto_augment=randaugment, erasing=0.4, crop_fraction=1.0, cfg=None, tracker=botsort.yaml, save_dir=runs\detect\train

Dataset 'coco8.yaml' images not found ⚠️, missing path 'C:\Users\liguopu\Downloads\ultralytics-main\datasets\coco8\images\val'
Downloading https://ultralytics.com/assets/coco8.zip to 'C:\Users\liguopu\Downloads\ultralytics-main\datasets\coco8.zip'...
100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 433k/433k [00:10<00:00, 42.1kB/s]
Unzipping C:\Users\liguopu\Downloads\ultralytics-main\datasets\coco8.zip to C:\Users\liguopu\Downloads\ultralytics-main\datasets\coco8...: 100%|██████████| 25/25 [00:00<00:00, 1081.86file/s]
Dataset download success ✅ (14.1s), saved to C:\Users\liguopu\Downloads\ultralytics-main\datasets


                   from  n    params  module                                       arguments
  0                  -1  1       928  ultralytics.nn.modules.conv.Conv             [3, 32, 3, 2]
  1                  -1  1     18560  ultralytics.nn.modules.conv.Conv             [32, 64, 3, 2]
  2                  -1  1     26080  ultralytics.nn.modules.block.C3k2            [64, 128, 1, False, 0.25]
  3                  -1  1    147712  ultralytics.nn.modules.conv.Conv             [128, 128, 3, 2]
  4                  -1  1    103360  ultralytics.nn.modules.block.C3k2            [128, 256, 1, False, 0.25]
  5                  -1  1    590336  ultralytics.nn.modules.conv.Conv             [256, 256, 3, 2]
  6                  -1  1    346112  ultralytics.nn.modules.block.C3k2            [256, 256, 1, True]
  7                  -1  1   1180672  ultralytics.nn.modules.conv.Conv             [256, 512, 3, 2]
  8                  -1  1   1380352  ultralytics.nn.modules.block.C3k2            [512, 512, 1, True]
  9                  -1  1    656896  ultralytics.nn.modules.block.SPPF            [512, 512, 5]
 10                  -1  1    990976  ultralytics.nn.modules.block.C2PSA           [512, 512, 1]
 11                  -1  1         0  torch.nn.modules.upsampling.Upsample         [None, 2, 'nearest']
 12             [-1, 6]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 13                  -1  1    443776  ultralytics.nn.modules.block.C3k2            [768, 256, 1, False]
 14                  -1  1         0  torch.nn.modules.upsampling.Upsample         [None, 2, 'nearest']
 15             [-1, 4]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 16                  -1  1    127680  ultralytics.nn.modules.block.C3k2            [512, 128, 1, False]
 17                  -1  1    147712  ultralytics.nn.modules.conv.Conv             [128, 128, 3, 2]
 18            [-1, 13]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 19                  -1  1    345472  ultralytics.nn.modules.block.C3k2            [384, 256, 1, False]
 20                  -1  1    590336  ultralytics.nn.modules.conv.Conv             [256, 256, 3, 2]
 21            [-1, 10]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 22                  -1  1   1511424  ultralytics.nn.modules.block.C3k2            [768, 512, 1, True]
 23        [16, 19, 22]  1    850368  ultralytics.nn.modules.head.Detect           [80, [128, 256, 512]]
YOLO11s summary: 319 layers, 9,458,752 parameters, 9,458,736 gradients, 21.7 GFLOPs

Transferred 499/499 items from pretrained weights
TensorBoard: Start with 'tensorboard --logdir runs\detect\train', view at http://localhost:6006/
Freezing layer 'model.23.dfl.conv.weight'
train: Scanning C:\Users\liguopu\Downloads\ultralytics-main\datasets\coco8\labels\train... 4 images, 0 backgrounds, 0 corrupt: 100%|██████████| 4/4 [00:00<00:00, 88.74it/s]
train: New cache created: C:\Users\liguopu\Downloads\ultralytics-main\datasets\coco8\labels\train.cache
val: Scanning C:\Users\liguopu\Downloads\ultralytics-main\datasets\coco8\labels\val... 4 images, 0 backgrounds, 0 corrupt: 100%|██████████| 4/4 [00:00<00:00, 124.99it/s]
val: New cache created: C:\Users\liguopu\Downloads\ultralytics-main\datasets\coco8\labels\val.cache
Plotting labels to runs\detect\train\labels.jpg... 
optimizer: 'optimizer=auto' found, ignoring 'lr0=0.01' and 'momentum=0.937' and determining best 'optimizer', 'lr0' and 'momentum' automatically... 
optimizer: AdamW(lr=0.000119, momentum=0.9) with parameter groups 81 weight(decay=0.0), 88 weight(decay=0.0005), 87 bias(decay=0.0)
TensorBoard: model graph visualization added ✅
Image sizes 640 train, 640 val
Using 0 dataloader workers
Logging results to runs\detect\train
Starting training for 10 epochs...
Closing dataloader mosaic

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
       1/10         0G     0.7464      1.726      1.177         13        640: 100%|██████████| 1/1 [00:05<00:00,  5.23s/it]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100%|██████████| 1/1 [00:02<00:00,  2.30s/it]
                   all          4         17      0.934      0.788      0.935      0.733

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
       2/10         0G     0.8044      1.794      1.126         13        640: 100%|██████████| 1/1 [00:04<00:00,  4.63s/it]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100%|██████████| 1/1 [00:01<00:00,  1.97s/it]
                   all          4         17      0.845      0.884      0.962      0.719

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
       3/10         0G     0.8128      1.746      1.216         13        640: 100%|██████████| 1/1 [00:05<00:00,  5.02s/it]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100%|██████████| 1/1 [00:02<00:00,  2.20s/it]
                   all          4         17      0.922      0.793      0.934      0.711

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
       4/10         0G     0.8673      1.121      1.161         13        640: 100%|██████████| 1/1 [00:05<00:00,  5.02s/it]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100%|██████████| 1/1 [00:02<00:00,  2.94s/it]
                   all          4         17      0.919      0.794      0.934      0.711

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
       5/10         0G     0.7821      1.427       1.17         13        640: 100%|██████████| 1/1 [00:05<00:00,  5.27s/it]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100%|██████████| 1/1 [00:02<00:00,  2.78s/it]
                   all          4         17      0.917      0.795      0.934      0.695

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
       6/10         0G     0.5842       1.11      1.014         13        640: 100%|██████████| 1/1 [00:05<00:00,  5.54s/it]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100%|██████████| 1/1 [00:02<00:00,  2.01s/it]
                   all          4         17      0.908      0.798      0.933      0.696

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
       7/10         0G     0.7791       1.15      1.104         13        640: 100%|██████████| 1/1 [00:04<00:00,  4.39s/it]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100%|██████████| 1/1 [00:01<00:00,  1.81s/it]
                   all          4         17      0.898        0.8      0.936      0.696

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
       8/10         0G     0.8725      1.353      1.201         13        640: 100%|██████████| 1/1 [00:04<00:00,  4.56s/it]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100%|██████████| 1/1 [00:01<00:00,  1.82s/it]
                   all          4         17      0.883      0.805      0.933       0.71

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
       9/10         0G     0.6213      1.023      1.066         13        640: 100%|██████████| 1/1 [00:04<00:00,  4.51s/it]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100%|██████████| 1/1 [00:01<00:00,  1.78s/it]
                   all          4         17      0.878      0.839       0.96      0.712

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
      10/10         0G     0.6774      1.118      1.038         13        640: 100%|██████████| 1/1 [00:04<00:00,  4.54s/it]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100%|██████████| 1/1 [00:01<00:00,  1.79s/it]
                   all          4         17      0.814      0.859      0.959      0.647

10 epochs completed in 0.024 hours.
Optimizer stripped from runs\detect\train\weights\last.pt, 19.2MB
Optimizer stripped from runs\detect\train\weights\best.pt, 19.2MB

Validating runs\detect\train\weights\best.pt...
WARNING ⚠️ validating an untrained model YAML will result in 0 mAP.
Ultralytics 8.3.7 🚀 Python-3.8.16 torch-1.13.1 CPU (unknown)
YOLO11s summary (fused): 238 layers, 9,443,760 parameters, 0 gradients, 21.5 GFLOPs
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100%|██████████| 1/1 [00:01<00:00,  1.54s/it]
                   all          4         17      0.935      0.788      0.935      0.733
                person          3         10          1       0.23      0.804      0.435
                   dog          1          1      0.963          1      0.995      0.895
                 horse          1          2      0.925          1      0.995      0.699
              elephant          1          2      0.948        0.5      0.828      0.477
              umbrella          1          1      0.849          1      0.995      0.995
          potted plant          1          1      0.923          1      0.995      0.895
Speed: 3.1ms preprocess, 368.9ms inference, 0.0ms loss, 3.0ms postprocess per image
Results saved to runs\detect\train
PS C:\Users\liguopu\Downloads\ultralytics-main> 

 训练完成后,能看到runs\detect\train保存的权重和训练信息

训练图像和标签的示例:

 三、YOLO11模型训练——旋转目标检测

 其实和上面的代码,基本是一样的,只需改变模型权重和吗模型配置文件就可以了。

模型训练简洁版

YOLO11模型训练,整体思路流程:

  • 加载模型:使用 YOLO 类指定模型的配置文件 yolo11s-obb.yaml 并加载预训练权重 yolo11s-obb.pt
  • 执行训练:调用 model.train() 方法,指定数据集 dota8.yaml,设置训练轮数为 10,图像大小为 640 像素。
  • 保存训练结果:训练完成后,结果保存在 results 中,包含损失和精度等信息。

示例代码,如下所示: 

from ultralytics import YOLO

# 加载YOLO模型的配置文件,并加载预训练权重文件
model = YOLO("yolo11s-obb.yaml").load("weights/yolo11s-obb.pt")  

# 使用dota8.yaml数据集进行训练,训练10个epoch,并将图像大小设置为640像素
results = model.train(data="dota8.yaml", epochs=10, imgsz=640)

然后执行程序,开始训练:

Transferred 535/541 items from pretrained weights
Ultralytics 8.3.7 🚀 Python-3.8.16 torch-1.13.1 CPU (unknown)
WARNING ⚠️ Upgrade to torch>=2.0.0 for deterministic training.
engine\trainer: task=obb, mode=train, model=yolo11s-obb.yaml, data=dota8.yaml, epochs=10, time=None, patience=100, batch=16, imgsz=640, save=True, save_period=-1, cache=False, device=None, workers=8, project=None, name=train, exist_ok=False, pretrained=weights/yolo11s-obb.pt, optimizer=auto, verbose=True, seed=0, deterministic=True, single_cls=False, rect=False, cos_lr=False, close_mosaic=10, resume=False, amp=True, fraction=1.0, profile=False, freeze=None, multi_scale=False, overlap_mask=True, mask_ratio=4, dropout=0.0, val=True, split=val, save_json=False, save_hybrid=False, conf=None, iou=0.7, max_det=300, half=False, dnn=False, plots=True, source=None, vid_stride=1, stream_buffer=False, visualize=False, augment=False, agnostic_nms=False, classes=None, retina_masks=False, embed=None, show=False, save_frames=False, save_txt=False, save_conf=False, save_crop=False, show_labels=True, show_conf=True, show_boxes=True, line_width=None, format=torchscript, keras=False, optimize=False, int8=False, dynamic=False, simplify=True, opset=None, workspace=4, nms=False, lr0=0.01, lrf=0.01, momentum=0.937, weight_decay=0.0005, warmup_epochs=3.0, warmup_momentum=0.8, warmup_bias_lr=0.1, box=7.5, cls=0.5, dfl=1.5, pose=12.0, kobj=1.0, label_smoothing=0.0, nbs=64, hsv_h=0.015, hsv_s=0.7, hsv_v=0.4, degrees=0.0, translate=0.1, scale=0.5, shear=0.0, perspective=0.0, flipud=0.0, fliplr=0.5, bgr=0.0, mosaic=1.0, mixup=0.0, copy_paste=0.0, copy_paste_mode=flip, auto_augment=randaugment, erasing=0.4, crop_fraction=1.0, cfg=None, tracker=botsort.yaml, save_dir=runs\obb\train
Overriding model.yaml nc=80 with nc=15

                   from  n    params  module                                       arguments
  0                  -1  1       928  ultralytics.nn.modules.conv.Conv             [3, 32, 3, 2]
  1                  -1  1     18560  ultralytics.nn.modules.conv.Conv             [32, 64, 3, 2]
  2                  -1  1     26080  ultralytics.nn.modules.block.C3k2            [64, 128, 1, False, 0.25]
  3                  -1  1    147712  ultralytics.nn.modules.conv.Conv             [128, 128, 3, 2]
  4                  -1  1    103360  ultralytics.nn.modules.block.C3k2            [128, 256, 1, False, 0.25]
  5                  -1  1    590336  ultralytics.nn.modules.conv.Conv             [256, 256, 3, 2]
  6                  -1  1    346112  ultralytics.nn.modules.block.C3k2            [256, 256, 1, True]
  7                  -1  1   1180672  ultralytics.nn.modules.conv.Conv             [256, 512, 3, 2]
  8                  -1  1   1380352  ultralytics.nn.modules.block.C3k2            [512, 512, 1, True]
  9                  -1  1    656896  ultralytics.nn.modules.block.SPPF            [512, 512, 5]
 10                  -1  1    990976  ultralytics.nn.modules.block.C2PSA           [512, 512, 1]
 11                  -1  1         0  torch.nn.modules.upsampling.Upsample         [None, 2, 'nearest']
 12             [-1, 6]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 13                  -1  1    443776  ultralytics.nn.modules.block.C3k2            [768, 256, 1, False]
 14                  -1  1         0  torch.nn.modules.upsampling.Upsample         [None, 2, 'nearest']
 15             [-1, 4]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 16                  -1  1    127680  ultralytics.nn.modules.block.C3k2            [512, 128, 1, False]
 17                  -1  1    147712  ultralytics.nn.modules.conv.Conv             [128, 128, 3, 2]
 18            [-1, 13]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 19                  -1  1    345472  ultralytics.nn.modules.block.C3k2            [384, 256, 1, False]
 20                  -1  1    590336  ultralytics.nn.modules.conv.Conv             [256, 256, 3, 2]
 21            [-1, 10]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 22                  -1  1   1511424  ultralytics.nn.modules.block.C3k2            [768, 512, 1, True]
 23        [16, 19, 22]  1   1111392  ultralytics.nn.modules.head.OBB              [15, 1, [128, 256, 512]]      
YOLO11s-obb summary: 344 layers, 9,719,776 parameters, 9,719,760 gradients, 22.6 GFLOPs

Transferred 535/541 items from pretrained weights
TensorBoard: Start with 'tensorboard --logdir runs\obb\train', view at http://localhost:6006/
Freezing layer 'model.23.dfl.conv.weight'
train: Scanning C:\Users\liguopu\Downloads\ultralytics-main\datasets\dota8\labels\train... 4 images, 0 backgrounds, 0 corrupt: 100%|██████████| 4/4 [00:00<00:00, 83.05it/s]
train: New cache created: C:\Users\liguopu\Downloads\ultralytics-main\datasets\dota8\labels\train.cache
val: Scanning C:\Users\liguopu\Downloads\ultralytics-main\datasets\dota8\labels\val... 4 images, 0 backgrounds, 0 corrupt: 100%|██████████| 4/4 [00:00<00:00, 138.08it/s]
val: New cache created: C:\Users\liguopu\Downloads\ultralytics-main\datasets\dota8\labels\val.cache
Plotting labels to runs\obb\train\labels.jpg... 
optimizer: 'optimizer=auto' found, ignoring 'lr0=0.01' and 'momentum=0.937' and determining best 'optimizer', 'lr0' and 'momentum' automatically... 
optimizer: AdamW(lr=0.000526, momentum=0.9) with parameter groups 87 weight(decay=0.0), 97 weight(decay=0.0005), 96 bias(decay=0.0)
TensorBoard: model graph visualization added ✅
Image sizes 640 train, 640 val
Using 0 dataloader workers
Logging results to runs\obb\train
Starting training for 10 epochs...
Closing dataloader mosaic

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
       1/10         0G     0.7968      4.385      1.142        121        640: 100%|██████████| 1/1 [00:15<00:00, 15.43s/it]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95):   0%|          | 0/1 [00:00<?, ?it/s]WARNING ⚠️ NMS time limit 2.200s exceeded
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100%|██████████| 1/1 [00:05<00:00,  5.70s/it]
                   all          4          8     0.0849       0.75      0.491      0.326

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
       2/10         0G     0.8239      4.402      1.148        124        640: 100%|██████████| 1/1 [00:07<00:00,  7.68s/it]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95):   0%|          | 0/1 [00:00<?, ?it/s]WARNING ⚠️ NMS time limit 2.200s exceeded
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100%|██████████| 1/1 [00:04<00:00,  4.94s/it]
                   all          4          8     0.0863       0.75      0.486      0.322

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
       3/10         0G     0.7333      4.395      1.144        107        640: 100%|██████████| 1/1 [00:07<00:00,  7.14s/it]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95):   0%|          | 0/1 [00:00<?, ?it/s]WARNING ⚠️ NMS time limit 2.200s exceeded
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100%|██████████| 1/1 [00:04<00:00,  4.63s/it]
                   all          4          8     0.0841       0.75      0.484      0.311

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
       4/10         0G     0.7834      4.376      1.167         99        640: 100%|██████████| 1/1 [00:05<00:00,  5.75s/it]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95):   0%|          | 0/1 [00:00<?, ?it/s]WARNING ⚠️ NMS time limit 2.200s exceeded
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100%|██████████| 1/1 [00:04<00:00,  4.22s/it]
                   all          4          8     0.0822       0.75       0.48      0.314

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
       5/10         0G     0.8125      4.363      1.454         84        640: 100%|██████████| 1/1 [00:06<00:00,  6.60s/it]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95):   0%|          | 0/1 [00:00<?, ?it/s]WARNING ⚠️ NMS time limit 2.200s exceeded
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100%|██████████| 1/1 [00:04<00:00,  4.45s/it]
                   all          4          8     0.0691      0.639      0.469      0.295

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
       6/10         0G     0.8424      4.348      1.417        125        640: 100%|██████████| 1/1 [00:06<00:00,  6.89s/it]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95):   0%|          | 0/1 [00:00<?, ?it/s]WARNING ⚠️ NMS time limit 2.200s exceeded
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100%|██████████| 1/1 [00:04<00:00,  4.89s/it]
                   all          4          8     0.0527      0.806      0.464      0.287

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
       7/10         0G     0.8203      4.349      1.783        123        640: 100%|██████████| 1/1 [00:05<00:00,  5.66s/it]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95):   0%|          | 0/1 [00:00<?, ?it/s]WARNING ⚠️ NMS time limit 2.200s exceeded
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100%|██████████| 1/1 [00:04<00:00,  4.61s/it]
                   all          4          8     0.0532      0.806      0.464      0.288

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
       8/10         0G     0.8241      4.314      1.475         98        640: 100%|██████████| 1/1 [00:05<00:00,  5.90s/it]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95):   0%|          | 0/1 [00:00<?, ?it/s]WARNING ⚠️ NMS time limit 2.200s exceeded
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100%|██████████| 1/1 [00:04<00:00,  4.19s/it]
                   all          4          8     0.0842       0.75      0.405      0.288

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
       9/10         0G     0.8575      4.347      1.505        116        640: 100%|██████████| 1/1 [00:05<00:00,  5.11s/it]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95):   0%|          | 0/1 [00:00<?, ?it/s]WARNING ⚠️ NMS time limit 2.200s exceeded
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100%|██████████| 1/1 [00:04<00:00,  4.69s/it]
                   all          4          8     0.0864       0.75      0.403      0.282

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
      10/10         0G     0.8994      4.323      1.629        125        640: 100%|██████████| 1/1 [00:05<00:00,  5.21s/it]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95):   0%|          | 0/1 [00:00<?, ?it/s]WARNING ⚠️ NMS time limit 2.200s exceeded
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100%|██████████| 1/1 [00:04<00:00,  4.81s/it]
                   all          4          8     0.0652      0.917      0.397      0.277

10 epochs completed in 0.038 hours.
Optimizer stripped from runs\obb\train\weights\last.pt, 19.9MB
Optimizer stripped from runs\obb\train\weights\best.pt, 19.9MB

Validating runs\obb\train\weights\best.pt...
WARNING ⚠️ validating an untrained model YAML will result in 0 mAP.
Ultralytics 8.3.7 🚀 Python-3.8.16 torch-1.13.1 CPU (unknown)
YOLO11s-obb summary (fused): 257 layers, 9,704,592 parameters, 0 gradients, 22.3 GFLOPs
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95):   0%|          | 0/1 [00:00<?, ?it/s]WARNING ⚠️ NMS time limit 2.200s exceeded
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100%|██████████| 1/1 [00:04<00:00,  4.70s/it]
                   all          4          8      0.104      0.667      0.509      0.342
      baseball diamond          3          4          0          0          0          0
      basketball court          1          3        0.2          1      0.533      0.329
     soccer ball field          1          1      0.111          1      0.995      0.697
Speed: 1.9ms preprocess, 376.6ms inference, 0.0ms loss, 740.0ms postprocess per image
Results saved to runs\obb\train

训练完成后,能看到保存的权重和训练信息

训练图像和标签的示例:

 四、YOLO11模型训练——关键点姿态估计

 其实和上面的代码,基本是一样的,只需改变模型权重和吗模型配置文件就可以了。

模型训练简洁版

YOLO11模型训练,整体思路流程:

  • 加载模型:使用 YOLO 类指定模型的配置文件 yolo11s-pose.yaml 并加载预训练权重 yolo11s-pose.pt
  • 执行训练:调用 model.train() 方法,指定数据集 coco8-pose.yaml,设置训练轮数为 10,图像大小为 640 像素。
  • 保存训练结果:训练完成后,结果保存在 results 中,包含损失和精度等信息。

示例代码,如下所示: 

from ultralytics import YOLO

# 加载YOLO模型的配置文件,并加载预训练权重文件
model = YOLO("yolo11s-pose.yaml").load("weights/yolo11s-pose.pt")  

# 使用coco8-pose.yaml数据集进行训练,训练10个epoch,并将图像大小设置为640像素
results = model.train(data="coco8-pose.yaml", epochs=10, imgsz=640)

然后执行程序,开始训练:

Transferred 535/541 items from pretrained weights
Ultralytics 8.3.7 🚀 Python-3.8.16 torch-1.13.1 CPU (unknown) 
WARNING ⚠️ Upgrade to torch>=2.0.0 for deterministic training.
engine\trainer: task=pose, mode=train, model=yolo11s-pose.yaml, data=coco8-pose.yaml, epochs=10, time=None, patience=100, batch=16, imgsz=640, save=True, save_period=-1, cache=False, device=None, workers=8, project=None, name=train, exist_ok=False, pretrained=weights/yolo11s-pose.pt, optimizer=auto, verbose=True, seed=0, deterministic=True, single_cls=False, rect=False, cos_lr=False, close_mosaic=10, resume=False, amp=True, fraction=1.0, profile=False, freeze=None, multi_scale=False, overlap_mask=True, mask_ratio=4, dropout=0.0, val=True, split=val, save_json=False, save_hybrid=False, conf=None, iou=0.7, max_det=300, half=False, dnn=False, plots=True, source=None, vid_stride=1, stream_buffer=False, visualize=False, augment=False, agnostic_nms=False, classes=None, retina_masks=False, embed=None, show=False, save_frames=False, save_txt=False, save_conf=False, save_crop=False, show_labels=True, show_conf=True, show_boxes=True, line_width=None, format=torchscript, keras=False, optimize=False, int8=False, dynamic=False, simplify=True, opset=None, workspace=4, nms=False, lr0=0.01, lrf=0.01, momentum=0.937, weight_decay=0.0005, warmup_epochs=3.0, warmup_momentum=0.8, warmup_bias_lr=0.1, box=7.5, cls=0.5, dfl=1.5, pose=12.0, kobj=1.0, label_smoothing=0.0, nbs=64, hsv_h=0.015, hsv_s=0.7, hsv_v=0.4, degrees=0.0, translate=0.1, scale=0.5, shear=0.0, perspective=0.0, flipud=0.0, fliplr=0.5, bgr=0.0, mosaic=1.0, mixup=0.0, copy_paste=0.0, copy_paste_mode=flip, auto_augment=randaugment, erasing=0.4, crop_fraction=1.0, cfg=None, tracker=botsort.yaml, save_dir=runs\pose\train

Dataset 'coco8-pose.yaml' images not found ⚠️, missing path 'C:\Users\liguopu\Downloads\ultralytics-main\datasets\coco8-pose\images\val'
Downloading https://ultralytics.com/assets/coco8-pose.zip to 'C:\Users\liguopu\Downloads\ultralytics-main\datasets\coco8-pose.zip'...
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 334k/334k [00:03<00:00, 108kB/s]
Unzipping C:\Users\liguopu\Downloads\ultralytics-main\datasets\coco8-pose.zip to C:\Users\liguopu\Downloads\ultralytics-main\datasets\coco8-pose...: 100%|██████████| 27/27 [00:00<00:00, 1018.29file/s]
Dataset download success ✅ (5.6s), saved to C:\Users\liguopu\Downloads\ultralytics-main\datasets

Overriding model.yaml nc=80 with nc=1

                   from  n    params  module                                       arguments
  0                  -1  1       928  ultralytics.nn.modules.conv.Conv             [3, 32, 3, 2]
  1                  -1  1     18560  ultralytics.nn.modules.conv.Conv             [32, 64, 3, 2]
  2                  -1  1     26080  ultralytics.nn.modules.block.C3k2            [64, 128, 1, False, 0.25]
  3                  -1  1    147712  ultralytics.nn.modules.conv.Conv             [128, 128, 3, 2]
  4                  -1  1    103360  ultralytics.nn.modules.block.C3k2            [128, 256, 1, False, 0.25]
  5                  -1  1    590336  ultralytics.nn.modules.conv.Conv             [256, 256, 3, 2]
  6                  -1  1    346112  ultralytics.nn.modules.block.C3k2            [256, 256, 1, True]
  7                  -1  1   1180672  ultralytics.nn.modules.conv.Conv             [256, 512, 3, 2]
  8                  -1  1   1380352  ultralytics.nn.modules.block.C3k2            [512, 512, 1, True]
  9                  -1  1    656896  ultralytics.nn.modules.block.SPPF            [512, 512, 5]
 10                  -1  1    990976  ultralytics.nn.modules.block.C2PSA           [512, 512, 1]
 11                  -1  1         0  torch.nn.modules.upsampling.Upsample         [None, 2, 'nearest']
 12             [-1, 6]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 13                  -1  1    443776  ultralytics.nn.modules.block.C3k2            [768, 256, 1, False]
 14                  -1  1         0  torch.nn.modules.upsampling.Upsample         [None, 2, 'nearest']
 15             [-1, 4]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 16                  -1  1    127680  ultralytics.nn.modules.block.C3k2            [512, 128, 1, False]
 17                  -1  1    147712  ultralytics.nn.modules.conv.Conv             [128, 128, 3, 2]
 18            [-1, 13]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 19                  -1  1    345472  ultralytics.nn.modules.block.C3k2            [384, 256, 1, False]
 20                  -1  1    590336  ultralytics.nn.modules.conv.Conv             [256, 256, 3, 2]
 21            [-1, 10]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 22                  -1  1   1511424  ultralytics.nn.modules.block.C3k2            [768, 512, 1, True]
 23        [16, 19, 22]  1   1309854  ultralytics.nn.modules.head.Pose             [1, [17, 3], [128, 256, 512]] 
YOLO11s-pose summary: 344 layers, 9,918,238 parameters, 9,918,222 gradients, 23.3 GFLOPs

Transferred 535/541 items from pretrained weights
TensorBoard: Start with 'tensorboard --logdir runs\pose\train', view at http://localhost:6006/
Freezing layer 'model.23.dfl.conv.weight'
train: Scanning C:\Users\liguopu\Downloads\ultralytics-main\datasets\coco8-pose\labels\train... 4 images, 0 backgrounds, 0 corrupt: 100%|██████████| 4/4 [00:00<00:00, 111.81it/s]
train: New cache created: C:\Users\liguopu\Downloads\ultralytics-main\datasets\coco8-pose\labels\train.cache
val: Scanning C:\Users\liguopu\Downloads\ultralytics-main\datasets\coco8-pose\labels\val... 4 images, 0 backgrounds, 0 corrupt: 100%|██████████| 4/4 [00:00<00:00, 116.71it/s]
val: New cache created: C:\Users\liguopu\Downloads\ultralytics-main\datasets\coco8-pose\labels\val.cache
Plotting labels to runs\pose\train\labels.jpg... 
optimizer: 'optimizer=auto' found, ignoring 'lr0=0.01' and 'momentum=0.937' and determining best 'optimizer', 'lr0' and 'momentum' automatically... 
optimizer: AdamW(lr=0.002, momentum=0.9) with parameter groups 87 weight(decay=0.0), 97 weight(decay=0.0005), 96 bias(decay=0.0)
TensorBoard: model graph visualization added ✅
Image sizes 640 train, 640 val
Using 0 dataloader workers
Logging results to runs\pose\train
Starting training for 10 epochs...
Closing dataloader mosaic

      Epoch    GPU_mem   box_loss  pose_loss  kobj_loss   cls_loss   dfl_loss  Instances       Size
       1/10         0G     0.9547        1.8     0.3144      2.728      1.214          7        640: 100%|██████████| 1/1 [00:05<00:00,  5.14s/it]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95)     Pose(P          R      mAP50  mAP50-95): 100%|██████████| 1/1 [00:02<00:00,  2.41s/it]
                   all          4         14      0.891      0.429      0.709      0.588          1      0.354      0.561      0.315

      Epoch    GPU_mem   box_loss  pose_loss  kobj_loss   cls_loss   dfl_loss  Instances       Size
       2/10         0G     0.6826      1.566     0.3834      2.278       1.16          7        640: 100%|██████████| 1/1 [00:06<00:00,  6.06s/it]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95)     Pose(P          R      mAP50  mAP50-95): 100%|██████████| 1/1 [00:02<00:00,  2.42s/it]
                   all          4         14      0.915        0.5      0.717      0.593          1      0.443      0.562      0.329

      Epoch    GPU_mem   box_loss  pose_loss  kobj_loss   cls_loss   dfl_loss  Instances       Size
       3/10         0G     0.8437      1.375     0.3163      3.233      1.011          7        640: 100%|██████████| 1/1 [00:05<00:00,  5.30s/it]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95)     Pose(P          R      mAP50  mAP50-95): 100%|██████████| 1/1 [00:02<00:00,  2.15s/it]
                   all          4         14      0.786        0.5      0.704      0.568      0.833        0.5      0.531      0.307

      Epoch    GPU_mem   box_loss  pose_loss  kobj_loss   cls_loss   dfl_loss  Instances       Size
       4/10         0G     0.7555      1.297     0.3225       2.15      1.057          7        640: 100%|██████████| 1/1 [00:06<00:00,  6.90s/it]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95)     Pose(P          R      mAP50  mAP50-95): 100%|██████████| 1/1 [00:02<00:00,  2.33s/it]
                   all          4         14          1       0.57      0.748      0.606      0.916        0.5      0.563       0.31

      Epoch    GPU_mem   box_loss  pose_loss  kobj_loss   cls_loss   dfl_loss  Instances       Size
       5/10         0G     0.6532      1.069      0.276      2.608     0.9624          7        640: 100%|██████████| 1/1 [00:06<00:00,  6.12s/it]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95)     Pose(P          R      mAP50  mAP50-95): 100%|██████████| 1/1 [00:02<00:00,  2.28s/it]
                   all          4         14          1      0.624      0.771      0.645      0.901        0.5      0.632      0.335

      Epoch    GPU_mem   box_loss  pose_loss  kobj_loss   cls_loss   dfl_loss  Instances       Size
       6/10         0G      0.865      1.923      0.268      2.503      1.143          7        640: 100%|██████████| 1/1 [00:05<00:00,  5.51s/it]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95)     Pose(P          R      mAP50  mAP50-95): 100%|██████████| 1/1 [00:02<00:00,  2.15s/it]
                   all          4         14      0.948      0.643      0.775      0.652      0.876      0.571      0.642       0.33

      Epoch    GPU_mem   box_loss  pose_loss  kobj_loss   cls_loss   dfl_loss  Instances       Size
       7/10         0G     0.6749      1.457      0.326      1.908     0.9575          7        640: 100%|██████████| 1/1 [00:05<00:00,  5.49s/it]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95)     Pose(P          R      mAP50  mAP50-95): 100%|██████████| 1/1 [00:02<00:00,  2.15s/it]
                   all          4         14      0.957      0.643      0.763      0.643      0.823      0.571      0.644      0.326

      Epoch    GPU_mem   box_loss  pose_loss  kobj_loss   cls_loss   dfl_loss  Instances       Size
       8/10         0G     0.4598      1.208     0.2935      1.765     0.9645          7        640: 100%|██████████| 1/1 [00:05<00:00,  5.50s/it]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95)     Pose(P          R      mAP50  mAP50-95): 100%|██████████| 1/1 [00:02<00:00,  2.09s/it]
                   all          4         14          1      0.641       0.77      0.647      0.832      0.571      0.651      0.338

      Epoch    GPU_mem   box_loss  pose_loss  kobj_loss   cls_loss   dfl_loss  Instances       Size
       9/10         0G     0.6678      1.003     0.2908      1.754     0.9891          7        640: 100%|██████████| 1/1 [00:05<00:00,  5.70s/it]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95)     Pose(P          R      mAP50  mAP50-95): 100%|██████████| 1/1 [00:02<00:00,  2.27s/it]
                   all          4         14      0.906      0.693      0.766      0.647      0.963        0.5      0.649      0.338

      Epoch    GPU_mem   box_loss  pose_loss  kobj_loss   cls_loss   dfl_loss  Instances       Size
      10/10         0G     0.8137      1.487     0.2731      2.158     0.8752          7        640: 100%|██████████| 1/1 [00:05<00:00,  5.50s/it]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95)     Pose(P          R      mAP50  mAP50-95): 100%|██████████| 1/1 [00:02<00:00,  2.16s/it]
                   all          4         14      0.898       0.63      0.763      0.639      0.967        0.5       0.65      0.329

10 epochs completed in 0.028 hours.
Optimizer stripped from runs\pose\train\weights\last.pt, 20.2MB
Optimizer stripped from runs\pose\train\weights\best.pt, 20.2MB

Validating runs\pose\train\weights\best.pt...
WARNING ⚠️ validating an untrained model YAML will result in 0 mAP.
Ultralytics 8.3.7 🚀 Python-3.8.16 torch-1.13.1 CPU (unknown)
YOLO11s-pose summary (fused): 257 layers, 9,902,940 parameters, 0 gradients, 23.1 GFLOPs
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95)     Pose(P          R      mAP50  mAP50-95): 100%|██████████| 1/1 [00:01<00:00,  1.88s/it]
                   all          4         14          1      0.642      0.769      0.646       0.83      0.571      0.651      0.338
Speed: 2.5ms preprocess, 404.4ms inference, 0.0ms loss, 52.5ms postprocess per image
Results saved to runs\pose\train

训练完成后,能看到保存的权重和训练信息

训练图像和标签的示例:

YOLO11相关文章推荐:

一篇文章快速认识YOLO11 | 关键改进点 | 安装使用 | 模型训练和推理-CSDN博客

YOLO11模型推理 | 目标检测与跟踪 | 实例分割 | 关键点估计 | OBB旋转目标检测-CSDN博客

分享完成~

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2204743.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

2024红队必备工具列表总结_railgun工具

一、信息收集 1、AppInfoScanner 一款适用于以HVV行动/红队/渗透测试团队为场景的移动端(Android、iOS、WEB、H5、静态网站)信息收集扫描工具&#xff0c;可以帮助渗透测试工程师、红队成员快速收集到移动端或者静态WEB站点中关键的资产信息并提供基本的信息输出,如&#xff…

OKG Research:如何衡量链上数据的开放价值?

在新加坡Token2049期间&#xff0c;欧科云链研究院受邀参加Bloomberg主办的企业另类资产投资峰会2024&#xff0c;与多位专家围绕未来数据形态与前景进行了深入交流。 活动后&#xff0c;欧科云链研究院负责人Lola Wang与资深研究员Jason Jiang在大公网发表署名文章《如何衡量…

Dinky 字段模式演变 PIPELINE 同步MySQL到Doris

背景 用Dinky数据平台 FlinkCDC收集Mysql BinLog 至 Doris 搭建实时数仓 问题 用Dinky CDCSOURCE 字段模式演变 整库同步Mysql到Doris 字段新增删除不生效 组件信息 Flink 1.17 dinky 1.1 Doris 2.1.6 Mysql 8.0Dinky MySQLCDC 整库到 Doris需要的依赖 Flink/lib 和 dinky/…

家庭酒吧一体化解决方案Bar Assistant

什么是 Bar Assistant &#xff1f; Bar Assistant 是一个用于管理家庭酒吧的自托管应用程序。它允许您添加配料、搜索鸡尾酒和创建自定义鸡尾酒配方。是您所有最爱鸡尾酒配方和饮品的新家。 软件功能&#xff1a; 包含超过 300 个鸡尾酒配方&#xff0c;附带详细信息包含超过…

iPhone 16 Pro 拆解揭秘:设计改进与维修便利性

苹果最新推出的iPhone 16系列在许多方面都进行了更新和改进&#xff0c;而这次我们要聚焦的是其中的高端型号——iPhone 16 Pro。 这款手机不仅在性能上有所提升&#xff0c;在内部构造上也带来了不少变化&#xff0c;让我们一起来看看这些细节吧。 更容易进入的内部结构 对于…

【hadoop报错】JAR does not exist or is not a normal file

1. 环境 linux Ubuntu hadoop 执行 hadoop jar 命令时&#xff0c;一直报错 解决方法 2、确定自己的jar目录是切实存在的 /export/server/hadoop-3.3.6/shares/hadoop/mapreduce/hadoop-mapreduce-client-jobclient-3.3.6-tests.jar 3、网上找了很多解决办法&#xff0c;最后…

QUUID 使用详解

UUID 通常由 128 位&#xff08;16 字节&#xff09;组成&#xff0c;通常表示为 32 个十六进制数字&#xff0c;分为五个部分&#xff0c;格式如下&#xff1a; QUuid 是 Qt 框架中用于生成和处理 UUID&#xff08;通用唯一标识符&#xff09;的类。UUID 是一种标准的标识符格…

厦门网站制作的趋势与最佳实践

厦门网站制作的趋势与最佳实践 随着数字化时代的到来&#xff0c;厦门的网站制作行业也在不断演变&#xff0c;呈现出多样化的趋势与最佳实践。这些变革不仅满足了市场的需求&#xff0c;也为企业的数字化转型提供了强有力的支持。 首先&#xff0c;响应式设计已成为网站制作的…

自由学习记录(5)

git命令行init仓库 mkdir的命令行使用 -p 是 mkdir 命令中的一个选项&#xff0c;表示 "parent"&#xff0c;意思是创建所有必要的父目录。如果使用 -p&#xff0c;即使父目录不存在&#xff0c;命令也会自动创建它们&#xff0c;而不会报错。 在 Git 中&#xff0…

Android复杂问题分析工具bugreportz详解

文章目录 bugreportz详细介绍功能与作用使用方法生成详细报告检查进度bugreportz 的优势分析报告 如何分析1. 解压 ZIP 文件2. 分析主要文件2.1 bugreport.txt2.2 logcat.txt2.3 kernel.log / last_kmsg2.4 events.log2.5 traces.txt2.6 dumpstate_board.txt 3. 工具支持4. 重点…

计算机的错误计算(一百一十九)

摘要 用错数解释计算机的错误计算&#xff08;一百一十八&#xff09;中的错误计算。 计算机的错误计算&#xff08;一百一十八&#xff09;给出一个循环迭代 用C语言或Java编程计算&#xff0c;则 均是错误结果。 下面用错数解释其出错原因。 首先&#xff0c;将迭代看作 …

ARM base instruction -- umull

无符号乘法运算 Unsigned Multiply Long multiplies two 32-bit register values, and writes the result to the 64-bit destination register. 将两个32位寄存器值相乘&#xff0c;并将结果写入64位目标寄存器。 64-bit variant UMULL <Xd>, <Wn>, <Wm&g…

springmvc直接访问 上下文路径 302 后路径更改并跳转源码解析

【问题现状】 application.yml 配置如下属性&#xff1a; server:servlet:context-path: /learning直接访问&#xff1a;http://localhost:8888/learning 路径时&#xff0c;会返回302的响应状态&#xff1b;并跳转路径&#xff1a;http://localhost:8888/learning/ (原路径后…

MapReduce工作机制源码解析

目录 1. MapTask工作机制2. ReduceTask工作机制3. ReduceTask并行度决定机制4. MapTask & ReduceTask源码解析 1. MapTask工作机制 MapTask一共分为五个阶段&#xff1a;Read、Map、Collect、溢写、Merge阶段。 在第4步MrAppMaster启动之前都是job的提交流程&#xff0c;…

keras yolo8目标检测

是从coco数据集提取其中的veh_ids[3,6,8,10] labels[car,bus,truck,traffic light]来做目标检测,分别表示汽车,公交车&#xff0c;卡车&#xff0c;交通灯,用的backbone keras_cv.models.YOLOV8Backbone.from_preset( "yolo_v8_m_backbone_coco" ),不用预训练…

构造mex(牛客周赛 Round 59)

题目链接&#xff1b; D-构造mex_牛客周赛 Round 59 (nowcoder.com) 题目描述&#xff1a; 输出和输出描述&#xff1a; 输入样例&#xff1a; 3 6 3 3 7 4 3 6 6 0 输出样例&#xff1a; NO YES 4 0 1 2 YES 1 1 1 1 1 1 分析&#xff1a; 数学思维题&#xff0c;赛后看了一…

Spring Cloud Bus:实现分布式系统中的消息传递与状态同步

在分布式系统中&#xff0c;服务之间的消息传递和状态同步是一个关键需求。Spring Cloud Bus提供了一个轻量级的消息代理连接分布式系统的节点&#xff0c;用于广播状态更改或管理指令。本文将探讨Spring Cloud Bus的功能、使用场景及其在分布式系统中的作用。 Spring Cloud B…

【星汇极客】STM32 HAL库各种模块开发之1.8TFT屏幕

前言 本人是一名嵌入式学习者&#xff0c;在大学期间也参加了不少的竞赛并获奖&#xff0c;包括&#xff1a;江苏省电子设计竞赛省一、睿抗机器人国二、中国高校智能机器人国二、嵌入式设计竞赛国三、光电设计竞赛国三、节能减排竞赛国三等。 暑假的时候参加了太多的比赛&#…

Node.js+Express毕设论文选题最新推荐题目和方向

目录 一、前言 二、毕设选题推荐 三、总结 四、附录&#xff08;手册、官网、资源教程等&#xff09; 1. Node.js 官方资源 2. Express 官方资源 3.安装方法 4 创建示例 一、前言 Node.js 是一个基于 Chrome V8 引擎的 JavaScript 运行环境&#xff0c;它允许开发者使用…

ARM知识点三和串口代码的编写流程

ARM的一些常见问题 ARM 体系结构的主要特点是什么&#xff1f; 精简指令集 (RISC)&#xff1a;ARM 采用 RISC 结构&#xff0c;指令集较小且简单&#xff0c;执行效率高。相比于复杂指令集 (CISC)&#xff0c;RISC 更强调每条指令的执行速度。低功耗设计&#xff1a;ARM 处理…