YOLO11-pose关键点检测:训练实战篇 | 自己数据集从labelme标注到生成yolo格式的关键点数据以及训练教程

本文涉及的产品
RDS DuckDB + QuickBI 企业套餐,8核32GB + QuickBI 专业版
简介: 本文介绍了如何将个人数据集转换为YOLO11-pose所需的数据格式,并详细讲解了手部关键点检测的训练过程。内容涵盖数据集标注、格式转换、配置文件修改及训练参数设置,最终展示了训练结果和预测效果。适用于需要进行关键点检测的研究人员和开发者。

  💡💡💡本文解决什么问题:教会你如何用自己的数据集转换成对应格式的数据集以及如何训练YOLO11-pose关键点检测

image.gif


1.YOLO11介绍

Ultralytics YOLO11是一款尖端的、最先进的模型,它在之前YOLO版本成功的基础上进行了构建,并引入了新功能和改进,以进一步提升性能和灵活性。YOLO11设计快速、准确且易于使用,使其成为各种物体检测和跟踪、实例分割、图像分类以及姿态估计任务的绝佳选择。

image.gif

image.gif

pose官方在COCO数据集上做了更多测试:

image.gif

结构图如下:

image.gif

1.1 C3k2

C3k2,结构图如下

image.gif

C3k2,继承自类C2f,其中通过c3k设置False或者Ture来决定选择使用C3k还是Bottleneck

image.gif

实现代码ultralytics/nn/modules/block.py

1.2 C2PSA介绍

借鉴V10 PSA结构,实现了C2PSA和C2fPSA,最终选择了基于C2的C2PSA(可能涨点更好?)

image.gif

实现代码ultralytics/nn/modules/block.py

1.3 11 Detect介绍

分类检测头引入了DWConv(更加轻量级,为后续二次创新提供了改进点),结构图如下(和V8的区别):

image.gif

实现代码ultralytics/nn/modules/head.py

2.如何标注自己的关键点数据集

2.1 labelme下载

# 安装labelme
pip install labelme

image.gif

2.2使用labelme下

直接在python环境下运行

labelme

image.gif

2.3 labelme介绍

关键点标记主要使用

1)Create Rectangle生成矩形框;

2)Create Point生成关键点;

image.gif

2.4 数据集标注

image.gif

3.数据集格式转换

3.1标记后的数据格式如下

一张图片对应一个json文件

image.gif

json部分内容如下:

{
  "version": "5.1.1",
  "flags": {},
  "shapes": [
    {
      "label": "Ulna",
      "points": [
        [
          474.71929824561397,
          1443.4035087719294
        ]
      ],
      "group_id": null,
      "shape_type": "point",
      "flags": {}
    },
    {
      "label": "Radius",
      "points": [
        [
          639.6315789473683,
          1445.1578947368416
        ]
      ],
      "group_id": null,
      "shape_type": "point",
      "flags": {}
    },
    {
      "label": "FMCP",
      "points": [
        [
          832.6140350877192,
          1222.3508771929824
        ]
      ],
      "group_id": null,
      "shape_type": "point",
      "flags": {}
    },
    {
      "label": "FPIP",
      "points": [
        [
          1023.8421052631577,
          1089.0175438596489
        ]
      ],
      "group_id": null,
      "shape_type": "point",
      "flags": {}
    },
    {
      "label": "FDIP",
      "points": [
        [
          1157.1754385964912,
          987.2631578947367
        ]
      ],
      "group_id": null,
      "shape_type": "point",
      "flags": {}
    },
    {
      "label": "MCP5",
      "points": [
        [
          430.85964912280696,
          946.9122807017543
        ]
      ],
      "group_id": null,
      "shape_type": "point",
      "flags": {}
    },
    {
      "label": "MCP4",
      "points": [
        [
          543.1403508771929,
          910.0701754385964
        ]
      ],
      "group_id": null,
      "shape_type": "point",
      "flags": {}
    },
    {
      "label": "MCP3",
      "points": [
        [
          657.1754385964912,
          881.9999999999998
        ]
      ],
      "group_id": null,
      "shape_type": "point",
      "flags": {}
    },
    {
      "label": "MCP2",
      "points": [
        [
          797.5263157894736,
          896.035087719298
        ]
      ],
      "group_id": null,
      "shape_type": "point",
      "flags": {}
    },
    {
      "label": "PIP5",
      "points": [
        [
          401.0350877192982,
          864.4561403508769
        ]
      ],
      "group_id": null,
      "shape_type": "point",
      "flags": {}
    },
    {
      "label": "PIP4",
      "points": [
        [
          529.1052631578947,
          801.2982456140348
        ]
      ],
      "group_id": null,
      "shape_type": "point",
      "flags": {}
    },
    {
      "label": "PIP3",
      "points": [
        [
          678.2280701754386,
          773.2280701754385
        ]
      ],
      "group_id": null,
      "shape_type": "point",
      "flags": {}
    },
    {
      "label": "PIP2",
      "points": [
        [
          843.1403508771929,
          810.0701754385964
        ]
      ],
      "group_id": null,
      "shape_type": "point",
      "flags": {}
    },
    {
      "label": "MIP5",
      "points": [
        [
          329.1052631578947,
          696.035087719298
        ]
      ],
      "group_id": null,
      "shape_type": "point",
      "flags": {}
    },
    {
      "label": "MIP4",
      "points": [
        [
          513.3157894736842,
          562.7017543859647
        ]
      ],
      "group_id": null,
      "shape_type": "point",
      "flags": {}
    },
    {
      "label": "MIP3",
      "points": [
        [
          713.3157894736842,
          515.3333333333333
        ]
      ],
      "group_id": null,
      "shape_type": "point",
      "flags": {}
    },
    {
      "label": "MIP2",
      "points": [
        [
          944.8947368421052,
          608.3157894736839
        ]
      ],
      "group_id": null,
      "shape_type": "point",
      "flags": {}
    },
    {
      "label": "DIP5",
      "points": [
        [
          313.31578947368416,
          601.2982456140348
        ]
      ],
      "group_id": null,
      "shape_type": "point",
      "flags": {}
    },
    {
      "label": "DIP4",
      "points": [
        [
          509.8070175438596,
          411.8245614035086
        ]
      ],
      "group_id": null,
      "shape_type": "point",
      "flags": {}
    },
    {
      "label": "DIP3",
      "points": [
        [
          727.3508771929824,
          345.15789473684185
        ]
      ],
      "group_id": null,
      "shape_type": "point",
      "flags": {}
    },
    {
      "label": "DIP2",
      "points": [
        [
          994.017543859649,
          492.52631578947353
        ]
      ],
      "group_id": null,
      "shape_type": "point",
      "flags": {}
    },
    {
      "label": "hand",
      "points": [
        [
          204.82608695652186,
          183.95652173913044
        ],
        [
          1265.695652173913,
          1775.2608695652175
        ]
      ],
      "group_id": null,
      "shape_type": "rectangle",
      "flags": {}
    }
  ],
  "imagePath": "1525.png",

image.gif

3.2 生成适合yolo格式的关键点数据集

labelme2yolo-keypoint

源码见博客:

https://blog.csdn.net/m0_63774211/article/details/142981705

生成的txt内容如下:

0 0.48481 0.47896 0.70079 0.77886 0.31308 0.70597 2 0.42206 0.70695 2 0.54954 0.59785 2 0.67569 0.53278 2 0.76420 0.48288 2 0.28402 0.46282 2 0.35865 0.44521 2 0.43395 0.43102 2 0.52642 0.43836 2 0.26486 0.42270 2 0.34941 0.39188 2 0.44782 0.37818 2 0.55680 0.39628 2 0.21731 0.34051 2 0.33884 0.27495 2 0.47094 0.25196 2 0.62351 0.29746 2 0.20674 0.29403 2 0.33620 0.20108 2 0.48018 0.16879 2 0.65654 0.24070 2

image.gif

讲解:

第一个0代表:框的类别,因为只有hand一类,所以为0

0.48481 0.47896 0.70079 0.77886 代表:归一化后的 框的中心点横纵坐标、宽、高

0.31308 0.70597 2代表:归一化后的 第一个关键点的横纵坐标、关键点可见性

关键点可见性理解:0代表不可见、1代表遮挡、2代表可见

3.3生成的yolo数据集如下

hand_keypoint:
-images:
 --train: png图片
 --val:png图片
-labels:
 --train: txt文件
 --val:txt文件

image.gif

4.手部关键点训练

4.1 新建data/hand_keypoint.yaml

参考coco8-pose.yaml即可

# Ultralytics YOLO 🚀, AGPL-3.0 license
# COCO8-pose dataset (first 8 images from COCO train2017) by Ultralytics
# Example usage: yolo train data=coco8-pose.yaml
# parent
# ├── ultralytics
# └── datasets
#     └── coco8-pose  ← downloads here (1 MB)
# Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
path: ./ultralytics-7.31/data/hand_keypoint  # 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)
# Keypoints
kpt_shape: [21, 3]  # number of keypoints, number of dims (2 for x,y or 3 for x,y,visible)
flip_idx: [0, 2, 1, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11, 14, 13, 16, 15,17,18,19,20]
# Classes
names:
  0: hand
# Download script/URL (optional)
#download: https://ultralytics.com/assets/coco8-pose.zip

image.gif

4.2修改ultralytics/cfg/models/11/yolo11-pose.yaml

修改为21个关键点和一个类别nc:1

# Ultralytics YOLO 🚀, AGPL-3.0 license
# YOLO11-pose keypoints/pose estimation model. For Usage examples see https://docs.ultralytics.com/tasks/pose
# Parameters
nc: 1 # number of classes
kpt_shape: [21, 3] # number of keypoints, number of dims (2 for x,y or 3 for x,y,visible)
scales: # model compound scaling constants, i.e. 'model=yolo11n-pose.yaml' will call yolo11.yaml with scale 'n'
  # [depth, width, max_channels]
  n: [0.50, 0.25, 1024] # summary: 344 layers, 2908507 parameters, 2908491 gradients, 7.7 GFLOPs
  s: [0.50, 0.50, 1024] # summary: 344 layers, 9948811 parameters, 9948795 gradients, 23.5 GFLOPs
  m: [0.50, 1.00, 512] # summary: 434 layers, 20973273 parameters, 20973257 gradients, 72.3 GFLOPs
  l: [1.00, 1.00, 512] # summary: 656 layers, 26230745 parameters, 26230729 gradients, 91.4 GFLOPs
  x: [1.00, 1.50, 512] # summary: 656 layers, 58889881 parameters, 58889865 gradients, 204.3 GFLOPs

image.gif

4.3默认参数开启训练

import warnings
warnings.filterwarnings('ignore')
from ultralytics import YOLO
if __name__ == '__main__':
    model = YOLO('ultralytics/cfg/models/11/yolo11-pose.yaml')
    model.train(data='data/hand_keypoint.yaml',
                cache=False,
                imgsz=640,
                epochs=200,
                batch=8,
                close_mosaic=10,
                device='0',
                optimizer='SGD', # using SGD
                project='runs/train-pose',
                name='exp',
                )

image.gif

4.4 训练结果分析

200个epoch以后,训练结果可视化如下:

image.gif

Pose mAP50 为  0.871  

YOLO11-pose summary (fused): 300 layers, 3,199,712 parameters, 0 gradients, 7.8 GFLOPs
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95)     Pose(P          R      mAP50  mAP50-95): 100%|██████████| 4/4 [00:04<00:00,  1.23s/it]
                   all         64         64      0.999          1      0.995      0.668      0.922      0.922      0.871      0.638

image.gif

PosePR_curve.png

image.gif

预测结果如下:

image.gif

目录
相关文章
|
人工智能 JSON 数据可视化
yolov8+动物+姿态识别(训练教程+代码)
yolov8+动物+姿态识别(训练教程+代码)
|
算法 数据库 计算机视觉
Dataset之COCO数据集:COCO数据集的简介、下载、使用方法之详细攻略
Dataset之COCO数据集:COCO数据集的简介、下载、使用方法之详细攻略
|
JSON 人工智能 数据格式
AI计算机视觉笔记二十六:YOLOV8自训练关键点检测
本文档详细记录了使用YOLOv8训练关键点检测模型的过程。首先通过清华源安装YOLOv8,并验证安装。接着通过示例权重文件与测试图片`bus.jpg`演示预测流程。为准备训练数据,文档介绍了如何使用`labelme`标注工具进行关键点标注,并提供了一个Python脚本`labelme2yolo.py`将标注结果从JSON格式转换为YOLO所需的TXT格式。随后,通过Jupyter Notebook可视化标注结果确保准确性。最后,文档展示了如何组织数据集目录结构,并提供了训练与测试代码示例,包括配置文件`smoke.yaml`及训练脚本`train.py`,帮助读者完成自定义模型的训练与评估。
6197 2
|
XML 数据格式 Python
Labelimg标注自己的数据集,及如何划分训练集和验证集,应用于Yolov5
Labelimg标注自己的数据集,及如何划分训练集和验证集,应用于Yolov5
4359 0
|
机器学习/深度学习 数据可视化 测试技术
YOLO26如何训练自己的关键点pose数据集 | (手部关键点为案列)
本文详解YOLO26全新发布:原理创新(移除DFL、无NMS推理、ProgLoss/STAL损失、MuSGD优化器)、结构框图及手部关键点数据集训练全流程,含代码实现与可视化效果,助力高效落地边缘端多任务检测。
370 1
|
机器学习/深度学习 人工智能 算法
Python+YOLO v8 实战:手把手教你打造专属 AI 视觉目标检测模型
本文介绍了如何使用 Python 和 YOLO v8 开发专属的 AI 视觉目标检测模型。首先讲解了 YOLO 的基本概念及其高效精准的特点,接着详细说明了环境搭建步骤,包括安装 Python、PyCharm 和 Ultralytics 库。随后引导读者加载预训练模型进行图片验证,并准备数据集以训练自定义模型。最后,展示了如何验证训练好的模型并提供示例代码。通过本文,你将学会从零开始打造自己的目标检测系统,满足实际场景需求。
13147 1
Python+YOLO v8 实战:手把手教你打造专属 AI 视觉目标检测模型
|
机器学习/深度学习 计算机视觉
YOLOv11改进策略【注意力机制篇】| 添加SE、CBAM、ECA、CA、Swin Transformer等注意力和多头注意力机制
YOLOv11改进策略【注意力机制篇】| 添加SE、CBAM、ECA、CA、Swin Transformer等注意力和多头注意力机制
4650 2
YOLOv11改进策略【注意力机制篇】| 添加SE、CBAM、ECA、CA、Swin Transformer等注意力和多头注意力机制
|
XML 机器学习/深度学习 数据格式
YOLOv8训练自己的数据集+常用传参说明
YOLOv8训练自己的数据集+常用传参说明
26423 3
|
编解码 算法 计算机视觉
YOLOv11改进策略【小目标改进】| 添加专用于小目标的检测层 附YOLOv1~YOLOv11的检测头变化详解
YOLOv11改进策略【小目标改进】| 添加专用于小目标的检测层 附YOLOv1~YOLOv11的检测头变化详解
2847 11
|
机器学习/深度学习
YOLOv11改进策略【损失函数篇】| 替换激活函数为Mish、PReLU、Hardswish、LeakyReLU、ReLU6
YOLOv11改进策略【损失函数篇】| 替换激活函数为Mish、PReLU、Hardswish、LeakyReLU、ReLU6
3241 4