code: def generalised_wasserstein_dice_loss(
      prediction, ground_truth, weight_map=None
  ):
      """
      Function to calculate the Generalised Wasserstein Dice Loss defined in
  
          Fidon, L. et. al. (2017) Generalised Wasserstein Dice Score
          for Imbalanced Multi-class Segmentation using Holistic
          Convolutional Networks.MICCAI 2017 (BrainLes)
  
      :param prediction: the logits
      :param ground_truth: the segmentation ground_truth
      :param weight_map:
      :return: the loss
      """
      if weight_map is not None:
          # raise NotImplementedError
          tf.logging.warning("Weight map specified but not used.")
  
      prediction = tf.cast(prediction, tf.float32)
      num_classes = prediction.shape[1].value
      one_hot = labels_to_one_hot(
          ground_truth, tf.shape(prediction)[-1]
      )
  
      one_hot = tf.sparse_tensor_to_dense(one_hot)
      # M = tf.cast(M, dtype=tf.float64)
      # compute disagreement map (delta)
      M = M_tree
      delta = wasserstein_disagreement_map(prediction, one_hot, M=M)
      # compute generalisation of all error for multi-class seg
      all_error = tf.reduce_sum(delta)
      # compute generalisation of true positives for multi-class seg
      one_hot = tf.cast(one_hot, dtype=tf.float64)
      true_pos = tf.reduce_sum(
          tf.multiply(
              tf.constant(M[0, :num_classes], dtype=tf.float64), one_hot
          ),
          axis=1,
      )
      true_pos = tf.reduce_sum(
          tf.multiply(true_pos, 1.0 - delta), axis=0
      )
      WGDL = 1.0 - (2.0 * true_pos) / (2.0 * true_pos + all_error)
      return tf.cast(WGDL, dtype=tf.float32)
  
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 11 for calling a global function with example usage: generalised_wasserstein_dice_loss(prediction, ground_truth, weight_map) and returns: tf