code: def loss_confusion_matrix(
      ground_truth, pred_multi, num_classes=2, nrater=6
  ):
      """
      Creates a loss over the two multi rater confusion matrices between the rater
      :param ground_truth: multi rater classification
      :param pred_multi: multi rater prediction (1 pred per class for each
      rater and each observation - A softmax is performed during the loss
      calculation
      :param nrater: number of raters
      :return: integration over the absolute differences between the confusion
      matrices divided by number of raters
      """
  
      one_hot_gt, output_shape = labels_to_one_hot(
          ground_truth, num_classes
      )
      dense_one_hot = tf.reshape(
          tf.sparse_tensor_to_dense(one_hot_gt), output_shape
      )
      dense_one_hot = tf.reshape(dense_one_hot, tf.shape(pred_multi))
      nclasses = tf.shape(pred_multi)[-1]
      nn_pred = tf.nn.softmax(pred_multi, -1)
      error_fin = tf.zeros([nclasses, nclasses])
      error_fin = tf.Print(
          tf.cast(error_fin, tf.float32),
          [nn_pred, tf.shape(pred_multi)],
          message="error",
      )
      nn_pred = tf.Print(
          tf.cast(nn_pred, tf.float32),
          [
              tf.shape(dense_one_hot),
              nclasses,
              tf.shape(ground_truth),
              tf.shape(nn_pred),
          ],
          message="check_conf",
      )
      for i in range(0, nrater):
          for j in range(i + 1, nrater):
              confusion_pred = tf.matmul(
                  tf.transpose(nn_pred[:, i, :]), nn_pred[:, j, :]
              )
              confusion_gt = tf.matmul(
                  tf.transpose(dense_one_hot[:, i, :]),
                  dense_one_hot[:, j, :],
              )
              error = tf.divide(
                  tf.abs(confusion_gt - confusion_pred),
                  tf.cast(tf.shape(ground_truth)[0], tf.float32),
              )
              error_fin += error
              error_fin = tf.Print(
                  tf.cast(error, tf.float32),
                  [tf.reduce_sum(error_fin), tf.reduce_max(error_fin)],
                  message="build_error",
              )
      return tf.reduce_sum(error_fin) / tf.cast(nrater, tf.float32)
  
file_path: NiftyNet/niftynet/layer/loss_classification_multi.py
imports: from __future__ import absolute_import, print_function, division
  import numpy
  import tensorflow
  from niftynet.engine.application_factory import LossClassificationMultiFactory
  from niftynet.layer.base_layer import Layer
label_desc: Use image node_id 2 for calling a global function with example usage: loss_confusion_matrix(ground_truth, pred_multi, num_classes, nrater) and returns: unknown