如何在Keras中计算指标? [英] How are metrics computed in Keras?

查看:185
本文介绍了如何在Keras中计算指标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道Keras如何计算指标(是否自定义指标).

I am wondering how does Keras compute a metric (a custom one or not).

例如,假设我有以下度量标准,该度量标准会在预测值和基本事实之间产生最大误差:

For example, suppose I have the following metric which yields the maximal error between the prediction and the ground truth:

def max_error(y_true, y_pred):

    import keras.backend as K

    return K.max(K.abs(y_true-y_pred))

是在所有迷你批次上计算出输出标量度量,然后将其求平均值,还是在整个数据集上直接计算出度量(训练或验证)?

Is the output scalar metric computed on all mini-batches and then averaged or is the metric directly computed on the whole dataset (training or validation)?

推荐答案

关于VALIDATION集合的指标还有其他需要了解的地方:

与另一个答案中所建议的相反,我只看到验证集上的度量是分批计算的,然后取平均值(当然,在纪元末尾的训练模型是与针对训练集计算指标得分的方式相反.

Contrary to what is suggested in another answer, I just saw that the metric on the validation set is calculated in batches, and then averaged (of course the trained model at the end of the epoch is used, in contrast to how the metric score is calculated for the training set).

如果要一次对整个验证数据进行计算,则必须使用已接受的答案中所述的回调.

If you want to compute it on the whole validation data at once, you have to use a callback as described in the accepted answer.

当然,对于通常的度量标准,无论是先进行批量计算并求平均值,还是全部进行一次大批量计算,都不会有任何区别.但是自定义指标很可能是:我有一种情况,指标会根据数据调整参数.

Sure, for the usual metrics, there will not be any difference whether you calculate first in batches and average, or do it all in one big batch. BUT for custom metrics, there very well can be: I just had a case where the metric would tune a parameter, based on the data.

这篇关于如何在Keras中计算指标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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