If I look into keras metric I see that the values of y_true
and y_predict
are "just" compared at the end of each epoch for categorical_accuracy
:
def categorical_accuracy(y_true, y_pred):
return K.cast(K.equal(K.argmax(y_true, axis=-1),
K.argmax(y_pred, axis=-1)),
K.floatx())
How are masked values handled? If I understood correctly, masking prohibits the masked values to influence the training, but it still produces predictions for the masked values. Thereby, it does, in my opinion, influence the metric.
More explanation on how it influences the metric:
In the padding/masking process, I set the padded/masked values in y_true
to an unused class e.g. class 0
.
If now argmax()
is looking for a max value in the one-hot encoded y_true
, it will just return 0 as the total (masked) row is the same.
I do not have a class 0, as it is my masking value/class, and thereby the y_pred
and y_true
certainly have different values creating a reduced accuracy.
Is this somehow already thought of in the Keras metric and I oversaw it?
Otherwise, I would have to create a custom metric or callback creating a similar metric to categorical_accuracy
with the addition that all masked values are eliminated in y_pred
and y_true
before comparison.