I'm working with a non-standard dataset, where my y_true is (batch x 5 x 1), and y_pred is (batch x 5 x 1). A batch sample i is "true" if any value of y_true[i] > 0., and it is predicted "true" if an y_pred[i] >= b where b is a threshold between 0 and 1.
I've defined this custom keras metric to calculate the number of true positives in a batch:
def TP(threshold=0.0):
def TP_(Y_true, Y_pred):
Y_true = tf.where(Y_true > 0., tf.ones(tf.shape(Y_true)), tf.zeros(tf.shape(Y_true)))
Y_pred_true = tf.where(Y_pred >= threshold, tf.ones(tf.shape(Y_pred)), tf.zeros(tf.shape(Y_pred)))
Y_true = K.sum(Y_true, axis=1)
Y_pred_true = K.sum(Y_pred_true, axis=1)
Y_true = tf.where(Y_true > 0., tf.ones(tf.shape(Y_true)), tf.zeros(tf.shape(Y_true)))
Y_pred_true = tf.where(Y_pred_true > 0., tf.ones(tf.shape(Y_pred_true)), tf.zeros(tf.shape(Y_pred_true)))
Y = tf.math.add(Y_true, Y_pred_true)
tp = tf.where(Y == 2, tf.ones(tf.shape(Y)), tf.zeros(tf.shape(Y)))
tp = K.sum(tp)
return tp
return TP_
When training, I sometimes get non-integer values. Is this because keras is averaging the values from all batches?
I have similar custom metrics for true negatives, false positives, and false negatives. Should the sum of all four of these values during training be an integer?