code: def mae_loss(prediction, ground_truth, weight_map=None):
      """
      :param prediction: the current prediction of the ground truth.
      :param ground_truth: the measurement you are approximating with regression.
      :param weight_map: a weight map for the cost function. .
      :return: mean(abs(ground_truth-prediction))
      """
      if weight_map is not None:
          residuals = tf.subtract(prediction, ground_truth)
          residuals = tf.abs(residuals)
          residuals = tf.multiply(residuals, weight_map)
          return tf.reduce_mean(residuals) / tf.reduce_mean(weight_map)
      else:
          return tf.reduce_mean(
              tf.abs(tf.subtract(prediction, ground_truth))
          )
  
file_path: NiftyNet/niftynet/layer/loss_regression.py
imports: from __future__ import absolute_import, print_function, division
  import tensorflow
  from niftynet.engine.application_factory import LossRegressionFactory
  from niftynet.layer.base_layer import Layer
label_desc: Use image node_id 4 for calling a global function with example usage: mae_loss(prediction, ground_truth, weight_map) and returns: unknown, tf