Keras-损失和指标的计算方式有所不同? [英] Keras - Loss and Metric calculated differently?

查看:279
本文介绍了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

这就是您的差异出处.

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

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