目录
一 ultralytics公司的最新作品YOLOV11
1 yolov11的创新
2 安装YOLOv11
3 PYTHON Guide
二 训练
三 验证
四 推理
五 导出模型
六 使用
文档:https://docs.ultralytics.com/models/yolo11/
代码链接:https://github.com/ultralytics/ultralytics
Performance Metrics
关键特性
◆增强的特征提取能力:YOLO11采用了改进的主干和颈部架构,增强了特征提取能力,能够实现更精确的目标检测和复杂任务的执行。
◆优化的效率和速度:YOLO11引入了精细化的架构设计和优化的训练流程,提供更快的处理速度,并在准确性和性能之间保持最佳平衡。
◆参数更少、精度更高:通过模型设计的改进,YOLO11m在COCO数据集上实现了更高的平均精度(mAP),同时使用的参数比YOLOv8m少22%,使其在计算上更加高效,而不牺牲准确性。
◆跨环境的适应性:YOLO11可以无缝部署在各种环境中,包括边缘设备、云平台和支持NVIDIA GPU的系统,确保最大的灵活性。
◆支持广泛任务:无论是目标检测、实例分割、图像分类、姿态估计还是定向目标检测(OBB),YOLO11都旨在应对一系列计算机视觉挑战。
支持的任务和模式
YOLO11建立在YOLOv8中引入的多功能模型范围之上,为各种计算机视觉任务提供增强的支持:
该表提供了YOLO11模型变体的概述,展示了它们在特定任务中的适用性以及与Inference、Validation、Training和Export等操作模式的兼容性。从实时检测到复杂的分割任务 ,这种灵活性使YOLO11适用于计算机视觉的广泛应用。
一 ultralytics公司的最新作品YOLOV11
1 yolov11的创新
■ yolov8 VS yolov11
YOLOv5,YOLOv8和YOLOv11均是ultralytics公司的作品,ultralytics出品必属精品。
具体创新点:
① 深度(depth)和宽度 (width)
YOLOv8和YOLOv11是基本上完全不同。
② C3k2机制
C3k2有参数为c3k,其中在网络的浅层c3k设置为False。C3k2就相当于YOLOv8中的C2f。
③ C2PSA机制
下图为C2PSA机制的原理图。
④ 解耦头
解耦头中的分类检测头增加了两个DWConv。
▲Conv
def autopad(k, p=None, d=1): # kernel, padding, dilation"""Pad to 'same' shape outputs."""if d > 1:k = d * (k - 1) + 1 if isinstance(k, int) else [d * (x - 1) + 1 for x in k] # actual kernel-sizeif p is None:p = k // 2 if isinstance(k, int) else [x // 2 for x in k] # auto-padreturn pclass Conv(nn.Module):"""Standard convolution with args(ch_in, ch_out, kernel, stride, padding, groups, dilation, activation)."""default_act = nn.SiLU() # default activationdef __init__(self, c1, c2, k=1, s=1, p=None, g=1, d=1, act=True):"""Initialize Conv layer with given arguments including activation."""super().__init__()self.conv = nn.Conv2d(c1, c2, k, s, autopad(k, p, d), groups=g, dilation=d, bias=False)self.bn = nn.BatchNorm2d(c2)self.act = self.default_act if act is True else act if isinstance(act, nn.Module) else nn.Identity()def forward(self, x):"""Apply convolution, batch normalization and activation to input tensor."""return self.act(self.bn(self.conv(x)))def forward_fuse(self, x):"""Perform transposed convolution of 2D data."""return self.act(self.conv(x))
▲Conv2d
torch.nn.Conv2d(in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True, padding_mode='zeros')
▲DWConv
DWConv 代表 Depthwise Convolution(深度卷积),是一种在卷积神经网络中常用的高效卷积操作。它主要用于减少计算复杂度和参数量。
class DWConv(Conv):"""Depth-wise convolution."""def __init__(self, c1, c2, k=1, s=1, d=1, act=True): # ch_in, ch_out, kernel, stride, dilation, activation"""Initialize Depth-wise convolution with given parameters."""super().__init__(c1, c2, k, s, g=math.gcd(c1, c2), d=d, act=act)
2 安装YOLOv11
# Clone the ultralytics repository
git clone https://github.com/ultralytics/ultralytics# 创建conda环境yolov11
conda create -n yolov11 python=3.9
conda activate yolov11
# Navigate to the cloned directory
cd ultralytics
# Install the package in editable mode for development
pip install -e . -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install onnx -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install onnxslim -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install onnxruntime -i https://pypi.tuna.tsinghua.edu.cn/simple
# opencv
pip install opencv-python -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install opencv-contrib-python -i https://pypi.tuna.tsinghua.edu.cn/simple
3 PYTHON Guide
from ultralytics import YOLO# Create a new YOLO model from scratchmodel = YOLO("yolo11n.yaml")# Load a pretrained YOLO model (recommended for training)model = YOLO("yolo11n.pt")# Train the model using the 'coco8.yaml' dataset for 3 epochsresults = model.train(data="coco8.yaml", epochs=3)# Evaluate the model's performance on the validation setresults = model.val()# Perform object detection on an image using the modelresults = model("https://ultralytics.com/images/bus.jpg")# Export the model to ONNX formatsuccess = model.export(format="onnx")
CLI AND PYTHON 示例:https://docs.ultralytics.com/tasks/detect/#models
二 训练
# Build a new model from YAML and start training from scratchyolo detect train data=coco8.yaml model=yolo11n.yaml epochs=100 imgsz=640# Start training from a pretrained *.pt modelyolo detect train data=coco8.yaml model=yolo11n.pt epochs=100 imgsz=640# Build a new model from YAML, transfer pretrained weights to it and start trainingyolo detect train data=coco8.yaml model=yolo11n.yaml pretrained=yolo11n.pt epochs=100 imgsz=640
示例:
# Load a COCO-pretrained YOLO11n model and train it on the COCO8 example dataset for 100 epochsyolo train model=yolo11n.pt data=coco8.yaml epochs=100 imgsz=640
训练产物:
三 验证
yolo detect val model=yolo11n.pt # val official model# 使用自己的模型yolo detect val model=path/to/best.pt # val custom model
示例:
yolo detect val model=yolo11n.pt
效果图:
四 推理
yolo detect predict model=yolo11n.pt source='https://ultralytics.com/images/bus.jpg' # predict with official model# 使用自己的模型yolo detect predict model=path/to/best.pt source='https://ultralytics.com/images/bus.jpg' # predict with custom model
示例:
yolo detect predict model=yolo11n.pt source='ultralytics/assets/bus.jpg'
效果图:
五 导出模型
yolo export model=yolo11n.pt format=onnx # export official modelyolo export model=path/to/best.pt format=onnx # export custom trained model
示例:
yolo export model=yolo11n.pt format=onnx
六 使用
代码如下:
from ultralytics import YOLO
# Load a model
model = YOLO("yolo11n.onnx") # load a custom model
# Predict with the model
results = model("ultralytics/assets/zidane.jpg")
# Process results list
for result in results:# boxes = result.boxes # Boxes object for bounding box outputs# masks = result.masks # Masks object for segmentation masks outputs# keypoints = result.keypoints # Keypoints object for pose outputs# probs = result.probs # Probs object for classification outputs# obb = result.obb # Oriented boxes object for OBB outputsresult.show() # display to screenresult.save(filename="result.jpg") # save to disk
pass
效果图:
至此,本文分享的内容就结束啦。