NVIDIA Clara Train 3.1
3.1

ai4med.libs.losses package

ce_loss(logits, labels)

Compute CE loss for tf variable

Parameters
  • logits (Tensor) – logits outputs of the network

  • labels (Tensor) – target integer labels

Returns

cross entropy loss

Return type

ce

binary_classification_loss(predictions, labels, label_format_info: ai4med.common.label_format.LabelFormatInfo)

Compute binary classification loss for tf variable

Parameters
  • predictions (Tensor) – outputs of the network

  • labels (Tensor) – target integer labels

  • label_format_info – label format information.

Returns

cross entropy loss

multiclass_classification_loss(predictions, targets, label_format)

Compute multiclass classification loss for tf variable

Parameters
  • predictions (Tensor) – outputs of the network

  • targets (Tensor) – target integer labels

  • label_format – vector of every label’s parameters

Returns

vector of multiple cross entropy losses

weighted_multiclass_classification_loss(predictions, targets, class_weights, label_format)

Compute multiclass classification loss for tf variable

Parameters
  • predictions (Tensor) – outputs of the network

  • targets (Tensor) – target integer labels

  • class_weights (list) – weight for each class

  • label_format – vector of every label’s parameters

Returns

vector of multiple cross entropy losses

cross_entropy_loss(predictions, targets, data_format='channels_first', skip_background=False, smooth=1e-08, is_onehot_targets=False)

Compute average cross entropy loss between two tensors.

5D tensors (for 3D images) or 4D tensors (for 2D images).

Parameters
  • predictions (Tensor) – outputs of the network

  • labels (Tensor) – target integer labels

  • data_format (str) – channels_first (default) or channels_last

  • skip_background (bool) – skip dice computation on the first channel of the predicted output (skipping dice on background class) or not

  • smooth (float) – constant to avoid log zero (default 1e-8)

  • is_onehot_targets (bool) – labels with One-Hot format or not

Returns

float tensor of cross entropy loss

dice_loss(predictions, targets, data_format='channels_first', skip_background=False, squared_pred=False, jaccard=False, smooth=1e-05, top_smooth=0.0, is_onehot_targets=False)

Compute average Dice loss between two tensors.

5D tensors (for 3D images) or 4D tensors (for 2D images).

Parameters
  • predictions (Tensor) – Tensor of Predicted segmentation output (e.g NxCxHxWxD)

  • targets (Tensor) – Tensor of True segmentation values. Usually has 1 channel dimension (e.g. Nx1xHxWxD), where each element is an index indicating class label. Alternatively it can be a one-hot-encoded tensor of the shape NxCxHxWxD, where each channel is binary (or float in interval 0..1) indicating the probability of the corresponding class label

  • data_format (str) – channels_first (default) or channels_last

  • skip_background (bool) – skip dice computation on the first channel of the predicted output or not

  • squared_pred (bool) – use squared versions of targets and predictions in the denominator or not

  • jaccard (bool) – compute Jaccard Index (soft IoU) instead of dice or not

  • smooth (float) – denominator constant to avoid zero division (default 1e-5)

  • top_smooth (float) – experimental, nominator constant to avoid zero final loss when targets are all zeros

  • is_onehot_targets (bool) – the targets are already One-Hot-encoded or not

Returns

tensor of one minus average dice loss

focal_loss(predictions, targets, data_format='channels_first', skip_background=False, smooth=1e-08, is_onehot_targets=False, alpha=0.25, gamma=2, use_sigmoid=False, use_for_segmentation=True, use_for_classification=False)

Compute average Focal loss between two tensors.

5D tensors (for 3D images) or 4D tensors (for 2D images).

For more details, check the focal loss for segmentation: AnatomyNet: Deep Learning for Fast and Fully Automated Whole-volume Segmentation of Head and Neck Anatomy, Medical Physics, 2018.

Parameters
  • predictions (Tensor) – Tensor of Predicted segmentation output (e.g NxCxHxWxD)

  • targets (Tensor) – Tensor of True segmentation values. Usually has 1 channel dimension (e.g. Nx1xHxWxD), where each element is an index indicating class label. Alternatively it can be a one-hot-encoded tensor of the shape NxCxHxWxD, where each channel is binary (or float in interval 0..1) indicating the probability of the corresponding class label

  • data_format (str) – channels_first (default) or channels_last

  • skip_background (bool) – skip dice computation on the first channel of the predicted output or not

  • smooth (float) – denominator constant to avoid zero division(default 1e-5)

  • is_onehot_targets (bool) – targets are already One-Hot-encoded or not

  • alpha (float) – fl = -alpha * (1-p)^gamma * log(p)

  • gamma (float) – indicating the power of 1-p

  • use_sigmoid (bool) – add sigmoid layer on predictions or not

  • use_for_segmentation (bool) – use this Focal loss for segmentation task or not

  • use_for_classification (bool) – use this Focal loss for classification task or not

Returns

tensor of focal loss

© Copyright 2020, NVIDIA. Last updated on Feb 2, 2023.