YOLOv3庖丁解牛(三):YOLOv3损失函数

本文深入探讨YOLOv3损失函数,包括xy坐标、宽高(wh)、置信度和类别的损失计算,以及它们在目标检测中的作用。通过解释关键代码段,解释了损失函数如何平衡不同部分的权重,确保模型的有效训练。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、首先我们看一下他的输入参数

model_loss = Lambda(yolo_loss, output_shape=(1,), name='yolo_loss',
                        arguments={'anchors': anchors, 'num_classes': num_classes, 'ignore_thresh': 0.5})(
        [*model_body.output, *y_true])

def yolo_loss(args, anchors, num_classes, ignore_thresh=.5, print_loss=False)

(1)args包括两部分,第一部分是*model_body.output,就是三组 (batchsize, grid, grid, 75)的darknet输出;第二部分是*y_true,就是上一篇文章咱们说到的 三组(batchsize, grid, grid, 3, 25)的Y真实值

(2)anchors就是[[10,13],  [16,30],  [33,23],  [30,61],  [62,45],  [59,119],  [116,90],  [156,198],  [373,326]]9组anchors

(3)num_classes=20(COCO数据集为80)

(4)ignore_thresh指的是iou的最小达标值

 

2、在函数体内,经过了一个核心函数(yolo_head),这个函数的主要功能就是把darknet输出的值跟我们的y_true对应上。

grid, raw_pred, pred_xy, pred_wh = yolo_head(yolo_outputs[l],
                                                     anchors[anchor_mask[l]], num_classes, input_shape, calc_loss=True)

函数体如下:

def yolo_head(feats, anchors, num_classes, input_shape, calc_loss=False):
    """Convert final layer features to bounding box parameters.
    [Nxgridxgridx75], [[116, 90], [156, 198], [373,326]], 20, [416, 416]
    yolo_outputs[l],anchors[anchor_mask[l]], num_classes, input_shape, calc_loss=True

    [Nxgridxgridx75]
    [[116, 90], [156, 198], [373,326]], 20, [416, 416]
    20
    416x416
    True

    [Nxgridxgridx75], [[116,90],[156,198],[373,326]], 20, (416, 416)

    """
    # 3
    num_anchors = len(anchors)
    # Reshape to batch, height, width, num_anchors, box_params.
    # [1x1x1x3x2]
    anchors_tensor
评论 26
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值