ultralytics-YOLOv11的目标检测解析

1. Python的调用

from ultralytics import YOLO
import os
def detect_predict():
    model = YOLO('../weights/yolo11n.pt')
    print(model)
    results = model('../ultralytics/assets/bus.jpg')
    if not os.path.exists(results[0].save_dir):
        os.makedirs(results[0].save_dir)
    for result in results:
        filename = result.path.split("\\")[-1]
        filedir = result.save_dir + "\\" + filename
        result.save(filedir)

运行结果:

模型训练,基于coco8数据:

from ultralytics import YOLO
def detect_train():
    model = YOLO("yolo11l.pt")  # Load a model
    train_results = model.train(   # Train the model
        data="coco8.yaml",  # path to dataset YAML
        epochs=100,  # number of training epochs
        imgsz=640,  # training image size
        device="0",  # device to run on, i.e. device=0 or device=0,1,2,3 or device=cpu
    )
    metrics = model.val()  # Evaluate model performance on the validation set
    results = model("../ultralytics/assets/bus.jpg")  # Perform object detection on an image
    results[0].show()
    # Export the model to ONNX format
    path = model.export(format="onnx")  # return path to exported model

2. 网络结构图

图2-1 yolo11-detection网络结构图

其中depth参数控制C3k2,即C3k2_X中,X*depth.

3. 损失函数

3.1 损失函数的定位

ultralytics中损失函数定位:ultralytics.engine.train()-->ultralytics.engine.trainer.train()--> ultralytics.engine.trainer._do_train(),其中以下为调用损失位置:

即模型的前向推理过程触发损失函数计算。同debug到该处,获取模型名称如下:

DetectionModel类中的函数如下:

其中DetectionModel函数继承自BaseModel,损失调用如下

经debug调用self.loss函数,其中ultralytics.utls.loss.v8DetectionLoss函数是具体损失计算位置

self.criterion(preds, batch)形式调用,即v8DetectionLoss类中的__call__函数,具体如下

3.2 损失函数具体分析

(1) 前向推理与anchor构造

前向处理分成三个尺度: ,其中B表示batch_size,

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值