code: def l1_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.
      :return: mean of the l1 loss across all voxels.
      """
      absolute_residuals = tf.abs(tf.subtract(prediction, ground_truth))
      if weight_map is not None:
          absolute_residuals = tf.multiply(
              absolute_residuals, weight_map
          )
          sum_residuals = tf.reduce_sum(absolute_residuals)
          sum_weights = tf.reduce_sum(weight_map)
      else:
          sum_residuals = tf.reduce_sum(absolute_residuals)
          sum_weights = tf.size(absolute_residuals)
      return tf.truediv(
          tf.cast(sum_residuals, dtype=tf.float32),
          tf.cast(sum_weights, dtype=tf.float32),
      )
  
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 1 for calling a global function with example usage: l1_loss(prediction, ground_truth, weight_map) and returns: tf