0

In a custom loss with tensorflow I am trying to select only the value of the true tensor and predict, between 0.2 and 0.8 and put equal to 1 other wise equal to 0. Then I calculate the mse between predict and true.

def customLoss(yTrue, yPred):
    yTrue_low=tf.where(yTrue > 0.2, tf.constant(1.), tf.constant(0.))
    yTrue_high=tf.where(yTrue < 0.8, tf.constant(1.), tf.constant(0.))
    trTrue=tf.multiply(yTrue_low, yTrue_high)

    yPred_low=tf.where(yPred > 0.2, tf.constant(1.), tf.constant(0.))
    yPred_high=tf.where(yPred < 0.8), tf.constant(1.), tf.constant(0.))
    trPred=tf.multiply(yPred_low, yPred_high)

    return tf.math.reduce_mean(tf.math.square(trTrue-trPred))

I got an error: ValueError: No gradients provided for any variable

Radhook
  • 9
  • 2

0 Answers0