How are metrics computed in Keras?

后端 未结 3 1728
醉酒成梦
醉酒成梦 2021-02-15 16:57

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 predict

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-15 17:54

    Something additional to know with respect to the metric for the VALIDATION set:

    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 of guangshengzuo (see https://keras.io/guides/writing_your_own_callbacks/ for more details).

    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.

    Edit: added link on callbacks, in response to comment

提交回复
热议问题