code: def sensitivity_specificity_loss(
      prediction, ground_truth, weight_map=None, r=0.05
  ):
      """
      Function to calculate a multiple-ground_truth version of
      the sensitivity-specificity loss defined in "Deep Convolutional
      Encoder Networks for Multiple Sclerosis Lesion Segmentation",
      Brosch et al, MICCAI 2015,
      https://link.springer.com/chapter/10.1007/978-3-319-24574-4_1
  
      error is the sum of r(specificity part) and (1-r)(sensitivity part)
  
      :param prediction: the logits
      :param ground_truth: segmentation ground_truth.
      :param r: the 'sensitivity ratio'
          (authors suggest values from 0.01-0.10 will have similar effects)
      :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)
      one_hot = labels_to_one_hot(
          ground_truth, tf.shape(prediction)[-1]
      )
  
      one_hot = tf.sparse_tensor_to_dense(one_hot)
      # value of unity everywhere except for the previous 'hot' locations
      one_cold = 1 - one_hot
  
      # chosen region may contain no voxels of a given label. Prevents nans.
      epsilon = 1e-5
  
      squared_error = tf.square(one_hot - prediction)
      specificity_part = tf.reduce_sum(squared_error * one_hot, 0) / (
          tf.reduce_sum(one_hot, 0) + epsilon
      )
      sensitivity_part = tf.reduce_sum(
          tf.multiply(squared_error, one_cold), 0
      ) / (tf.reduce_sum(one_cold, 0) + epsilon)
  
      return tf.reduce_sum(
          r * specificity_part + (1 - r) * sensitivity_part
      )
  
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 7 for calling a global function with example usage: sensitivity_specificity_loss(prediction, ground_truth, weight_map, r) and returns: tf