简体   繁体   English

Keras自定义损失函数输出负值,不明白为什么?

[英]Keras custom loss function outputs negative values, dont understand why?

Dear StackOverflow Community, I have the following loss function in keras: 尊敬的StackOverflow社区,我在keras中具有以下损失功能:

return K.mean((y_true+K.epsilon()) * K.square(y_pred - y_true), axis=-1)

When I try to train my network (y normalized to 0 - 1) with it, the loss appears to get to an negative value, which I just can't understand. 当我尝试用它训练我的网络(y归一化为0-1)时,损失似乎达到负值,这是我无法理解的。 I calculated the same thing with numpy, and everything worked fine and as intended. 我用numpy计算了同样的东西,并且一切工作正常且符合预期。

I would be really delighted If someone knows the cause for this weird negative solutions, so thank you for your help. 如果有人知道导致这种奇怪的负面解决方案的原因,我将非常高兴,因此,感谢您的帮助。

If y_true is really normalized to 0-1 that only possible cause that I see is K.epsilon() . 如果y_true真正标准化为0-1,那我看到的唯一可能原因是K.epsilon() As this page suggest epsilon can be changed by user and this can cause a problem. 该页面所示,用户可以更改epsilon,这可能会引起问题。

Try to hardcode epsilon value or just throw it away. 尝试对epsilon值进行硬编码或将其丢弃。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM