Search code examples
kerascallbackmetrics

Which class do the log scores belong to in the parameter of on_epoch_end of keras.callbacks.Callback


I am trying to get scores from my Keras model after each epoch so I'm using the below custom callback:

class EpochScoreHistory(keras.callbacks.Callback):
    def __init__(self, keys):
        self.custom_keys = keys

    def on_train_begin(self, logs={}):
        self.custom_avg_scores = dict()
        for key in self.custom_keys:
            self.custom_avg_scores[key]=[]

    def on_epoch_end(self, epoch, logs={}):
        for key in self.custom_keys:
            self.custom_avg_scores[key].append(logs.get(key))

After each epoch, inside the logs parameter of on_epoch_end function, i have scores like acc, for instance 0.567, etc. but i wonder which class do these scores belong to since my problem has two classes to classify into.

In short, when we get logs as the parameter of on_epoch_end function of a customized Keras callback, which classification class do the scores in those logs belong to? I was expecting to get a list of accuracies for instance but instead I have single values for each score I'm after. I wonder if this is a bug in Keras. Many thanks.


Solution

  • Keras gives you an accuracy of the model i.e. how good it is at classifying the classes. It does not give you a value for every class. You might need to create a confusion matrix for that.