import tensorflow as tf


def dice_loss(predictions, targets, weights=1., name='dice_loss'):
  with tf.name_scope(name):
    # predictions = tf.to_float(predictions)
    targets = tf.to_float(targets)
    intersection = 2 * tf.reduce_sum(predictions * targets) + weights
    union = weights + tf.reduce_sum(predictions) + tf.reduce_sum(targets)
    loss = -(intersection / (union))
  return loss

