gpt4 book ai didi

python - 关于 yolov2 损失函数的问题?

转载 作者:行者123 更新时间:2023-11-30 09:44:57 28 4
gpt4 key购买 nike

我阅读了yolov2的实现。我对它的损失有一些疑问。下面是损失函数的伪代码,我希望我答对了。

costs = np.zeros(output.shape)
for pred_box in all prediction box:
if (max iou pred_box has with all truth box < threshold):
costs[pred_box][obj] = (sigmoid(obj)-0)^2 * 1
else:
costs[pred_box][obj] = 0
costs[pred_box][x] = (sigmoid(x)-0.5)^2 * 0.01
costs[pred_box][y] = (sigmoid(y)-0.5)^2 * 0.01
costs[pred_box][w] = (w-0)^2 * 0.01
costs[pred_box][h] = (h-0)^2 * 0.01
for truth_box all ground truth box:
pred_box = the one prediction box that is supposed to predict for truth_box
costs[pred_box][obj] = (1-sigmoid(obj))^2 * 5
costs[pred_box][x] = (sigmoid(x)-truex)^2 * (2- truew*trueh/imagew*imageh)
costs[pred_box][y] = (sigmoid(y)-truey)^2 * (2- truew*trueh/imagew*imageh)
costs[pred_box][w] = (w-log(truew/anchorw))^2 * (2- truew*trueh/imagew*imageh)
costs[pred_box][h] = (h-log(trueh/anchorh))^2 * (2- truew*trueh/imagew*imageh)
costs[pred_box][classes] = softmax_euclidean
total loss = sum(costs)

我对此有一些疑问:

1.代码每10批随机调整训练图像的尺寸到320到608之间,但是 anchor 框没有相应地调整大小。为什么不也调整 anchor 的大小。我的意思是你选择了一组最常见的 anchor 在 13*13 的特征图中,这些 anchor 在 19*19 的特征图中并不常见,所以为什么不根据图像大小调整 anchor 的大小。

2.正在对未分配真实值的框的 x,y,w,h 预测应用成本,默认情况下,这会插入 w,h 完全适合 anchor ,并将 x,y 推到单元格的中心,有帮助为什么不将位置预测成本仅应用于分配了真相的位置并忽略未分配的位置预测成本。

3.为什么不简单地应用(obj-0)^2作为所有没有分配真值的框的obj预测的成本。在yolov2中,没有分配真值的框的obj预测并不全部应用成本,只有那些没有分配真值的框分配的真理与所有真理并没有太多重叠,并且被应用成本。这是为什么呢,很复杂。

最佳答案

1

在YOLOv2的实现中,使用随机裁剪来增强训练数据。随机裁剪裁剪图像的一部分并将其扩展,使其与原始图像具有相同的大小。

这种训练数据的增强使得经过训练的网络对于训练数据中未见过的不同大小的对象具有鲁棒性。所以 anchor 框不应该通过这个过程改变。

请记住, anchor 框是对训练和预测之前输入的对象形状的假设。但是,如果网络提出这样的假设,那么对于形状与假设大不相同的对象,它就会变得不稳健。数据增强解决了这个问题。

2

这是因为我们不知道中心坐标和盒子形状的真相。当我们训练 YOLO 时,我们使用Responsible Boxes这个概念。它们是要通过培训过程进行更新的盒子。

请参阅“my Medium post 的“负责任”边界框。

3这是因为 YOLO 的输出来自卷积层的目录,而不是来自全连接的激活。因此输出不限于 0 和 1 之间。因此我们应用 sigmoid 函数,使其代表概率。

关于python - 关于 yolov2 损失函数的问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53650457/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com