前言
YOLOv11 由 Ultralytics 团队在 2024 年 9 月 30 日发布,最新的 YOLOv11 模型在之前的 YOLO 版本引入了新功能和改进,以进一步提高性能和灵活性。YOLOv11 快速、准确且易于使用,使其成为各种目标检测和跟踪、实例分割、图像分类和姿态估计任务的绝佳选择。

一、YOLOv11 代码下载地址
官网源码下载地址:Ultralytics GitHub
1. YOLOv11 模型结构图
根据 yolov11.yaml 画出 yolo 整体结构图,如下图所示

二、数据集准备
1. 数据集标注软件
推荐使用 labelimg 或 labelme 进行标注。安装命令如下:
pip install labelimg
启动标注软件后,设置自动保存标注生成的文件。
2. VOC 数据集格式转换
如果标注格式为 VOC,需要转换为 YOLO 格式。转换代码如下:
import xml.etree.ElementTree as ET
import os, cv2
import numpy as np
from os import listdir
from os.path import join
classes = []
def convert(size, box):
dw = 1. / (size[0])
dh = 1. / (size[1])
x = (box[0] + box[1]) / 2.0 - 1
y = (box[2] + box[3]) / -
w = box[] - box[]
h = box[] - box[]
x = x * dw
w = w * dw
y = y * dh
h = h * dh
(x, y, w, h)
():
(xmlpath, , encoding=) in_file:
txtname = xmlname[:-] +
txtfile = os.path.join(txtpath, txtname)
tree = ET.parse(in_file)
root = tree.getroot()
filename = root.find()
img = cv2.imdecode(np.fromfile(.(imgpath, xmlname[:-], postfix), np.uint8), cv2.IMREAD_COLOR)
h, w = img.shape[:]
res = []
obj root.():
cls = obj.find().text
cls classes:
classes.append(cls)
cls_id = classes.index(cls)
xmlbox = obj.find()
b = ((xmlbox.find().text), (xmlbox.find().text), (xmlbox.find().text), (xmlbox.find().text))
bb = convert((w, h), b)
res.append((cls_id) + + .join([(a) a bb]))
(res) != :
(txtfile, ) f:
f.write(.join(res))
__name__ == :
postfix =
imgpath =
xmlpath =
txtpath =
os.path.exists(txtpath):
os.makedirs(txtpath, exist_ok=)
list_dir = os.listdir(xmlpath)
error_file_list = []
i (, (list_dir)):
:
path = os.path.join(xmlpath, list_dir[i])
( path) ( path):
convert_annotation(path, list_dir[i])
()
:
()
Exception e:
()
()
error_file_list.append(list_dir[i])
()
()


