Keras - 损失和度量的计算方式不同? [英] Keras - Loss and Metric calculated differently?

查看:21
本文介绍了Keras - 损失和度量的计算方式不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Keras 中有一个模型,我正在优化均方误差.但是,如果我在指标中使用与 Keras 的 losses.py 相同的代码,我会得到不同的结果.这是为什么?

I have a model in Keras which I'm optimizing the mean squared error. However, if I use the same code as in losses.py from Keras in the metric, I get a different result. Why is this?

作为一个指标:

def MSE_metric(y_true, y_pred):
    return K.mean(K.square(y_pred, y_true))

对于模型:

model.compile(optimizer=SGD(lr=0.01, momntum=0.9), loss='MSE', metrics=[MSE_metric])

这导致损失为 6.07,但 MSE_metric 为 0.47

This results in a loss of 6.07 but an MSE_metric of 0.47

推荐答案

请记住 - 如果您使用任何类型的正则化 - 它会影响您的 loss.您的实际损失等于:

Remember - that if you use any kind of regularization - it affects your loss. Your actual loss is equal to:

loss = mse + regularization

这就是您的差异的来源.

and this is where your discrepancy comes from.

这篇关于Keras - 损失和度量的计算方式不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆