code: def dice_nosquare(prediction, ground_truth, weight_map=None):
      """
      Function to calculate the classical dice loss
  
      :param prediction: the logits
      :param ground_truth: the segmentation ground_truth
      :param weight_map:
      :return: the loss
      """
      prediction = tf.cast(prediction, tf.float32)
      if len(ground_truth.shape) == len(prediction.shape):
          ground_truth = ground_truth[..., -1]
      one_hot = labels_to_one_hot(
          ground_truth, tf.shape(prediction)[-1]
      )
  
      # dice
      if weight_map is not None:
          num_classes = prediction.shape[1].value
          weight_map_nclasses = tf.tile(
              tf.expand_dims(tf.reshape(weight_map, [-1]), 1),
              [1, num_classes],
          )
          dice_numerator = 2.0 * tf.sparse_reduce_sum(
              weight_map_nclasses * one_hot * prediction,
              reduction_axes=[0],
          )
          dice_denominator = tf.reduce_sum(
              prediction * weight_map_nclasses, reduction_indices=[0]
          ) + tf.sparse_reduce_sum(
              weight_map_nclasses * one_hot, reduction_axes=[0]
          )
      else:
          dice_numerator = 2.0 * tf.sparse_reduce_sum(
              one_hot * prediction, reduction_axes=[0]
          )
          dice_denominator = tf.reduce_sum(
              prediction, reduction_indices=[0]
          ) + tf.sparse_reduce_sum(one_hot, reduction_axes=[0])
      epsilon = 0.00001
  
      dice_score = (dice_numerator + epsilon) / (
          dice_denominator + epsilon
      )
      # dice_score.set_shape([num_classes])
      # minimising (1 - dice_coefficients)
      return 1.0 - tf.reduce_mean(dice_score)
  
imports: from __future__ import absolute_import, print_function, division
  import numpy
  import tensorflow
  from niftynet.engine.application_factory import LossSegmentationFactory
  from niftynet.layer.base_layer import Layer
label_desc: Use image node_id 13 for calling a global function with example usage: dice_nosquare(prediction, ground_truth, weight_map) and returns: unknown