niftynet.layer.loss_regression module

Loss functions for regression

class LossFunction(loss_type='L2Loss', loss_func_params=None, name='loss_function')[source]

Bases: niftynet.layer.base_layer.Layer

layer_op(prediction, ground_truth=None, weight_map=None)[source]

Compute loss from prediction and ground truth, the computed loss map are weighted by weight_map.

if prediction is list of tensors, each element of the list will be compared against ground_truth` and the weighted by ``weight_map.

Parameters:
  • prediction – input will be reshaped into (batch_size, N_voxels, num_classes)
  • ground_truth – input will be reshaped into (batch_size, N_voxels)
  • weight_map – input will be reshaped into (batch_size, N_voxels)
Returns:

l1_loss(prediction, ground_truth, weight_map=None)[source]
Parameters:
  • prediction – the current prediction of the ground truth.
  • ground_truth – the measurement you are approximating with regression.
Returns:

mean of the l1 loss across all voxels.

l2_loss(prediction, ground_truth, weight_map=None)[source]
Parameters:
  • prediction – the current prediction of the ground truth.
  • ground_truth – the measurement you are approximating with regression.
Returns:

sum(differences squared) / 2 - Note, no square root

rmse_loss(prediction, ground_truth, weight_map=None)[source]
Parameters:
  • prediction – the current prediction of the ground truth.
  • ground_truth – the measurement you are approximating with regression.
  • weight_map – a weight map for the cost function. .
Returns:

sqrt(mean(differences squared))

mae_loss(prediction, ground_truth, weight_map=None)[source]
Parameters:
  • prediction – the current prediction of the ground truth.
  • ground_truth – the measurement you are approximating with regression.
  • weight_map – a weight map for the cost function. .
Returns:

mean(abs(ground_truth-prediction))

huber_loss(prediction, ground_truth, delta=1.0, weight_map=None)[source]

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 .

Parameters:
  • prediction – the current prediction of the ground truth.
  • ground_truth – the measurement you are approximating with regression.
  • delta – the point at which quadratic->linear transition happens.
Returns: