Keras - Loss and Metric calculated differently?

孤街浪徒 提交于 2019-12-01 02:10:32

问题


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?

As a metric:

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

For the model:

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

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


回答1:


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.



来源:https://stackoverflow.com/questions/48719540/keras-loss-and-metric-calculated-differently

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!