2024字节阿里面试题深度解析YoloV3的主干网络和Loss,2024Python开发社招面试总结

return loss

从上面的代码中我们可以看出,YoloV3的Loss有4部分组成。

  1. 中心点 x、y 的调整参数 ——二分类的交叉熵(keras :binary_cross_entropy,pytorch:BCELoss

  2. anchor的宽高w、h的调整参数 —— 均方损失函数:MSELoss

  3. 置信度Conf —— BCELoss

  4. 类别预测Cls —— BCELoss

计算loss,实际上是y_pre和y_true之间的对比:

y_pre就是一幅图像经过网络之后的3个输出,y_true就是一个真实图像中,将它的真实框的位置以及框内物体的种类,转化成yolo3网络输出后的格式的值,所以y_pre和y_true内容的shape都是

(batch_size,13,13,3,85),(batch_size,26,26,3,85),(batch_size,52,52,3,85)。

y_pre在上面的网络中已经做了说明,下面说一说如何生成y_true,在yolo3中,其使用了一个专门的函数用于处理读取进来的图片的框的真实情况。

def preprocess_true_boxes(true_boxes, input_shape, anchors, num_classes):

‘’'Preprocess true boxes to training input format

Parameters


true_boxes: array, shape=(m, T, 5)

Absolute x_min, y_min, x_max, y_max, class_id relative to input_shape.

input_shape: array-like, hw, multiples of 32

anchors: array, shape=(N, 2), wh

num_classes: integer

Returns


y_true: list of array, shape like yolo_outputs, xywh are reletive value

‘’’

assert (true_boxes[…, 4]<num_classes).all(), ‘class id must be less than num_classes’

num_layers = len(anchors)//3 # default setting

anchor_mask = [[6,7,8], [3,4,5], [0,1,2]] if num_layers==3 else [[3,4,5], [1,2,3]]

true_boxes = np.array(true_boxes, dtype=‘float32’)

input_shape = np.array(input_shape, dtype=‘int32’)<

  • 4
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值