def dice_hard_coe(output, target, epsilon=1e-10):
 output = tf.cast((output > 0.5), dtype=tf.float32)
 target = tf.cast((target > 0.5), dtype=tf.float32)
 inse = tf.reduce_sum((output * target))
 l = tf.reduce_sum((output * output))
 r = tf.reduce_sum((target * target))
 dice = ((2 * inse) / (l + r))
 if (epsilon == 0):
  return dice
 else:
  return tf.clip_by_value(dice, 0, (1.0 - epsilon))

def dice_hard_coe ( output , target , epsilon = 1e-10 ) : output = tf . cast ( ( output > 0.5 ) , dtype = tf . float32 ) target = tf . cast ( ( target > 0.5 ) , dtype = tf . float32 ) inse = tf . reduce_sum ( ( output * target ) ) l = tf . reduce_sum ( ( output * output ) ) r = tf . reduce_sum ( ( target * target ) ) dice = ( ( 2 * inse ) / ( l + r ) ) if ( epsilon == 0 ) : return dice else : return tf . clip_by_value ( dice , 0 , ( 1.0 - epsilon ) )
non-differentiable sørensen–dice coefficient for comparing the similarity of two distributions .