I have written the following custom AUC metric for a two class classification problem. The output of the network is a softmax with 2 units.
class my_auc(tf.keras.metrics.Metric):
# USAGE: metrics=[my_auc()]
def __init__(self, name='auc', **kwargs):
super(Metric, self).__init__(name=name, **kwargs)
self.m0 = tf.keras.metrics.AUC()
self.m1 = tf.keras.metrics.AUC()
def update_state(self, y_true, y_pred, sample_weight=None):
print("y_true.shape = ", y_true.shape)
print("y_pred.shape", y_pred.shape)
self.m0.update_state(y_true[:, 1], y_pred[:, 1]) # HERE THE MENTIONED ERROR OCCURS
self.m1.update_state(y_true[:, 0], y_pred[:, 0])
def result(self):
return (self.m0.result() + self.m1.result())/2
def reset_state(self):
# The state of the metric will be reset at the start of each epoch.
self.m0.reset_state()
self.m1.reset_state()
The problem is that it issues the following error:
ValueError: Shapes (200,) and () are incompatible
I am sure that my model outputs 2 value for each input. And, the labels are converted to one-hot encoding.