I want to be able to know the rounded accuracy of my neural network when the prediction is above or below a certain threshold. For example, I want it to only calculate accuracy when the prediction is above 0.55 or below 0.45 in order to filter out near 50/50 cases.
I tried using the soft_acc function on stackoverflow and adding an if else to the beginning to filter out the near 50/50s.
def soft_acc(y_true, y_pred):
if y_pred > 0.55 or y_pred < 0.45:
return K.mean(K.equal(K.round(y_true), K.round(y_pred)))
I received the following error message.
TypeError: Using a tf.Tensor as a Python bool is not allowed. Use if t is not None: instead of if t: to test if a tensor is defined, and use TensorFlow ops such as tf.cond to execute subgraphs conditioned on the value of a tensor.