Python 约罗损失函数降低精度

Python 约罗损失函数降低精度,python,deep-learning,convolution,object-detection,yolo,Python,Deep Learning,Convolution,Object Detection,Yolo,我在实现YOLO loss函数时遇到一些问题。每次我训练我的模型,我的损失减少,但我的准确性也下降。这让我相信我的损失函数是不正确的。考虑到约洛的论文很模糊,我想知道是否有人能帮我解决这个问题 这是我目前正在使用的损失函数,试图遵循本文的函数。我试图找到一个类对象,因此我的y_true=[P,w,h,x,y]是该对象的一部分,没有其他边界框 def get_coord(X,Y,H,W): x2 = X + W y2 = Y + H return x2,y2 def loss_functio

我在实现YOLO loss函数时遇到一些问题。每次我训练我的模型,我的损失减少,但我的准确性也下降。这让我相信我的损失函数是不正确的。考虑到约洛的论文很模糊,我想知道是否有人能帮我解决这个问题

这是我目前正在使用的损失函数,试图遵循本文的函数。我试图找到一个类对象,因此我的y_true=[P,w,h,x,y]是该对象的一部分,没有其他边界框

def get_coord(X,Y,H,W):
x2 = X + W
y2 = Y + H

return x2,y2


def loss_function2(y_true,y_pred):
object_true = y_true[:,:,:,0]
object_pred = y_pred[:,:,:,0]

width_true = y_true[:,:,:,1]
width_pred = y_pred[:,:,:,1]

height_true = y_true[:,:,:,2]
height_pred =y_pred[:,:,:,2]

X_true = y_true[:,:,:,3]
X_pred =y_pred[:,:,:,3]

Y_true = y_true[:,:,:,4]
Y_pred = y_pred[:,:,:,4]

x2_true,y2_true = get_coord(X_true,Y_true,height_true,width_true)
x2_pred,y2_pred = get_coord(X_pred,Y_pred,height_pred,width_pred)

xi1 = tf.maximum(X_true,X_pred)
yi1 = tf.maximum(Y_true,X_true)
xi2 = tf.minimum(x2_true,x2_pred)
yi2 = tf.minimum(y2_true,y2_pred)


zeros = tf.zeros([10,19,19])

inter_area = tf.maximum(zeros,xi2-xi1)*tf.maximum(zeros,yi2-yi1)
box_area1 = (x2_true-X_true)*(y2_true-Y_true)
box_area2 = (x2_pred-X_pred)*(y2_pred-Y_pred)

union_area = box_area1 + box_area2 - inter_area
iou = inter_area/union_area

loss1 = tf.reduce_sum(tf.multiply(object_true,(tf.squared_difference(X_pred,X_true) + tf.squared_difference(Y_pred,Y_true))))
loss2 = tf.reduce_sum(tf.multiply(object_true,(tf.squared_difference(tf.sqrt(width_pred),tf.sqrt(width_true)) + tf.squared_difference(tf.sqrt(height_pred),tf.sqrt(height_true)))))
loss3 = tf.reduce_sum(tf.multiply(object_true,(tf.squared_difference(object_pred,iou))))
loss4 = tf.scalar_mul(0.5,(tf.reduce_sum(tf.multiply(((object_true*-1)+1),(tf.squared_difference(object_pred,object_true))))))

return loss1+loss2+loss3+loss4
我已经将我的图像网格分割了19x19,因此我的预测是以10x19x19x5张量为单位的

我已经看过了python中YOLO的其他实现的代码,大多数loss函数都让我感到困惑。它们要么太复杂,我无法遵循,要么实现了与原始文件概述完全不同的东西