niftynet.layer.loss_segmentation module

class niftynet.layer.loss_segmentation.LossFunction(n_class, loss_type='Dice', loss_func_params={}, name='loss_function')

Bases: niftynet.layer.base_layer.Layer

layer_op(prediction, ground_truth=None, weight_map=None, var_scope=None)
make_callable_loss_func(type_str)
niftynet.layer.loss_segmentation.cross_entropy(prediction, ground_truth, weight_map=None)

Function to calculate the cross-entropy loss function :param prediction: the logits (before softmax) :param ground_truth: the segmentation ground truth :param weight_map: :return: the cross-entropy loss

niftynet.layer.loss_segmentation.dice(prediction, ground_truth, weight_map=None)
Function to calculate the dice loss with the definition given in Milletari,
F., Navab, N., & Ahmadi, S. A. (2016) V-net: Fully convolutional neural networks for volumetric medical image segmentation. 3DV 2016 using a square in the denominator
Parameters:
  • prediction – the logits (before softmax)
  • ground_truth – the segmentation ground_truth
  • weight_map
Returns:

the loss

niftynet.layer.loss_segmentation.dice_nosquare(prediction, ground_truth, weight_map=None)

Function to calculate the classical dice loss :param prediction: the logits (before softmax) :param ground_truth: the segmentation ground_truth :param weight_map: :return: the loss

niftynet.layer.loss_segmentation.generalised_dice_loss(prediction, ground_truth, weight_map, type_weight='Square')
Function to calculate the Generalised Dice Loss defined in Sudre, C. et. al.
  1. Generalised Dice overlap as a deep learning loss function for highly
unbalanced segmentations. DLMIA 2017
Parameters:
  • prediction – the logits (before softmax)
  • ground_truth – the segmentation ground truth
  • weight_map
  • type_weight – type of weighting allowed between labels (choice

between Square (square of inverse of volume), Simple (inverse of volume) and Uniform (no weighting)) :return: the loss

niftynet.layer.loss_segmentation.generalised_wasserstein_dice_loss(prediction, ground_truth, weight_map=None)

Function to calculate the Generalised Wasserstein Dice Loss defined in Fidon, L. et. al. (2017) Generalised Wasserstein Dice Score for Imbalanced Multi-class Segmentation using Holistic Convolutional Networks. MICCAI 2017 (BrainLes) :param prediction: the logits (before softmax) :param ground_truth: the segmentation ground_truth :param weight_map: :return: the loss

niftynet.layer.loss_segmentation.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: the loss

niftynet.layer.loss_segmentation.l1_loss(prediction, ground_truth, weight_map=None)
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.

niftynet.layer.loss_segmentation.l2_loss(prediction, ground_truth, weight_map=None)
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

niftynet.layer.loss_segmentation.l2_reg_loss(scope)
niftynet.layer.loss_segmentation.sensitivity_specificity_loss(prediction, ground_truth, weight_map=None, r=0.05)

Function to calculate a multiple-ground_truth version of the sensitivity-specificity loss defined in “Deep Convolutional Encoder Networks for Multiple Sclerosis Lesion Segmentation”, Brosch et al, MICCAI 2015, https://link.springer.com/chapter/10.1007/978-3-319-24574-4_1

error is the sum of r(specificity part) and (1-r)(sensitivity part)

Parameters:
  • pred – the logits (before softmax).
  • ground_truth – segmentation ground_truth.
  • r – the ‘sensitivity ratio’ (authors suggest values from 0.01-0.10 will have similar effects)
Returns:

the loss

niftynet.layer.loss_segmentation.wasserstein_disagreement_map(prediction, ground_truth, M)

Function to calculate the pixel-wise Wasserstein distance between the flattened pred_proba and the flattened labels (ground_truth) with respect to the distance matrix on the label space M.

Parameters:
  • prediction – the logits after softmax
  • ground_truth – segmentation ground_truth
  • M – distance matrix on the label space
Returns:

the pixelwise distance map (wass_dis_map)