Yolo V1单级单盒训练

发布于 2025-02-12 08:06:39 字数 1458 浏览 1 评论 0原文

我是 cnns 和对象检测模型的新手。 因此,我试图基于 yolo yolo v1 v1 v1 from

我的想法是让s = 7个单元格一个仅B = 1个单元格。 此外,我只对检测一个课程感兴趣。然后,每个单元格包含一个预测,例如[p,x,y,w,h],y_train具有尺寸[7x7x5]。

我正在 colaBoRagoratoration 带有 keras 。完整的代码可以在我的github存储库中找到:“ https://github.com/frapasti/human hands.git”

我已经深入研究了论文。

我的问题是,损失在训练的早期就出现了,模型仅输出NAN。

这是我使用过的自定义损失:

import keras.backend as K

def custom_loss(y_true, y_pred):
  yes_obj = y_true[..., 0]

  lxy = K.sum((K.square(y_pred[..., 1] - y_true[..., 1]) + K.square(y_pred[..., 2] - y_true[..., 2]))*yes_obj)
  lwh = K.sum((K.square(K.sqrt(y_pred[..., 3]) - K.sqrt(y_true[..., 3])) + K.square(K.sqrt(y_pred[..., 4]) - K.sqrt(y_true[..., 4])))*yes_obj)
  lp = K.sum(K.square(y_true[..., 0] - y_pred[..., 0])*yes_obj)

  return lxy + lwh + lp

yolo.compile(loss=custom_loss, optimizer='adam', metrics=['accuracy'])
yolo.fit(X_train, Y_train, batch_size=25, epochs=5, verbose=1)

我真的不明白为什么... 我已经跳过了卷积层的预训练,而我认为这不是引起问题的原因。

I'm rather new to CNNs and object detection models.
For this reason I'm trying to implement an object detection model based on YOLO v1 from scratch.

My idea is to have S = 7 cells an just B = 1 box per cell.
Furthermore, I'm only interested in detecting one class. Each cell then contains a prediction like [P, x, y, w, h] and y_train has dimensions [7x7x5].

I'm implementing the model on Colaboratory with Keras. The full code can be found in my GitHub repository: "https://github.com/frapasti/Human-Hands.git"

I've deeply studied the paper.

My problem is that the loss diverges early in the training and the model outputs only NaN.

Here's the custom loss that I've used:

import keras.backend as K

def custom_loss(y_true, y_pred):
  yes_obj = y_true[..., 0]

  lxy = K.sum((K.square(y_pred[..., 1] - y_true[..., 1]) + K.square(y_pred[..., 2] - y_true[..., 2]))*yes_obj)
  lwh = K.sum((K.square(K.sqrt(y_pred[..., 3]) - K.sqrt(y_true[..., 3])) + K.square(K.sqrt(y_pred[..., 4]) - K.sqrt(y_true[..., 4])))*yes_obj)
  lp = K.sum(K.square(y_true[..., 0] - y_pred[..., 0])*yes_obj)

  return lxy + lwh + lp

yolo.compile(loss=custom_loss, optimizer='adam', metrics=['accuracy'])
yolo.fit(X_train, Y_train, batch_size=25, epochs=5, verbose=1)

I really don't understand why...
I've skipped the pre-training of the convolutional layer on just classification, but I don't think that's what causes the problem.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凡间太子 2025-02-19 08:06:39

似乎这是一个梯度分歧问题。您是否从Yolo V1纸中实现了自定义损失?我正在尝试做同样的事情。但是,该模型的结果不太好。

培训结果:

“

It seems as if it is a gradient divergence problem. Did you implement the custom loss from the YOLO v1 paper? I'm trying to do the same. However, I am getting not-so-good results with the model.

Training results:

1

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文