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 = K.reshape(K.constant(anchors), [1, 1, 1, num_anchors, 2])