I am trying to use tf.boolean_mask to get a masked mean difference for image segmentation:
def custom_loss(image):
def loss(predicted_y, target_y):
pred_mask = tf.math.greater(predicted_y,0.5)
target_mask = tf.math.greater(target_y,0.5)
mean_diff = (tf.reduce_mean(tf.boolean_mask(image,pred_mask)) - tf.reduce_mean(tf.boolean_mask(image,target_mask))) ** 2
return mean_diff
return loss
Unfortunately, I am getting a ValueError: No gradients provided for any variable, which would logically be caused by the tf.boolean_mask. Any way to do this on Tensorflow 2.0?
Thanks a lot!