code: def huber_loss(prediction, ground_truth, delta=1.0, weight_map=None):
      """
      The Huber loss is a smooth piecewise loss function
      that is quadratic for ``|x| <= delta``, and linear for ``|x|> delta``
      See https://en.wikipedia.org/wiki/Huber_loss .
  
      :param prediction: the current prediction of the ground truth.
      :param ground_truth: the measurement you are approximating with regression.
      :param delta: the point at which quadratic->linear transition happens.
      :return:
      """
      absolute_residuals = tf.abs(tf.subtract(prediction, ground_truth))
      residual_is_outside_delta = tf.less(delta, absolute_residuals)
      quadratic_residual = 0.5 * absolute_residuals**2
      linear_residual = delta * (absolute_residuals - delta / 2)
  
      voxelwise_loss = tf.where(
          residual_is_outside_delta, linear_residual, quadratic_residual
      )
      if weight_map is not None:
          voxelwise_loss = tf.multiply(voxelwise_loss, weight_map)
          sum_weights = tf.reduce_sum(weight_map)
      else:
          sum_weights = tf.to_float(tf.size(absolute_residuals))
      sum_loss = tf.reduce_sum(voxelwise_loss)
      return tf.truediv(sum_loss, sum_weights)
  
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 5 for calling a global function with example usage: huber_loss(prediction, ground_truth, delta, weight_map) and returns: tf