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

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

二、数据集准备
1. 数据集标注软件
数据集使用标注软件标注好,推荐 labelimg 或 labelme,可以在 python 环境使用 pip install labelimg 或 pip install labelme 进行安装。
安装完成在终端输入命令启动标注软件。
下面是软件界面。
设置自动保存标注生成的标注文件。
2. VOC 数据集格式转换
标注格式如果选择 VOC 格式,后面需要代码转换格式,如果选择 YOLO 格式就不用转换。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[]) / -
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=)
listdir = os.listdir(xmlpath)
error_file_list = []
i (, (listdir)):
:
path = os.path.join(xmlpath, listdir[i])
( path) ( path):
convert_annotation(path, listdir[i])
()
:
()
Exception e:
()
()
error_file_list.append(listdir[i])
()
()






