Tensorflow loss functions

It is possible to use any default tensorflow loss, dice coefficient<https://analysiscenter.github.io/dataset/api/dataset.models.tf.losses.html>` loss has alias dice_loss.

radio.models.tf.losses.tversky_loss(labels, predictions, alpha=0.3, beta=0.7, smooth=1e-10)[source]

Tversky loss function.

Parameters:
  • labels (tf.Tensor) – tensor containing target mask.
  • predictions (tf.Tensor) – tensor containing predicted mask.
  • alpha (float) – real value, weight of ‘0’ class.
  • beta (float) – real value, weight of ‘1’ class.
  • smooth (float) – small real value used for avoiding division by zero error.
Returns:

tensor containing tversky loss.

Return type:

tf.Tensor

radio.models.tf.losses.jaccard_coef_logloss(labels, predictions, smooth=1e-10)[source]

Loss function based on jaccard coefficient.

Parameters:
  • labels (tf.Tensor) – tensor containing target mask.
  • predictions (tf.Tensor) – tensor containing predicted mask.
  • smooth (float) – small real value used for avoiding division by zero error.
Returns:

tensor containing negative logarithm of jaccard coefficient.

Return type:

tf.Tensor

radio.models.tf.losses.reg_l2_loss(labels, predictions, lambda_coords=0.75)[source]

L2 loss for prediction of cancer tumor’s centers, sizes joined with binary classification task.

Parameters:
  • labels (tf.Tensor) – tensor containing true values for sizes of nodules, their centers and classes of crop(1 if cancerous 0 otherwise).
  • predictions (tf.Tensor) – tensor containing predicted values for sizes of nodules, their centers and probability of cancer in given crop.
Returns:

l2 loss for regression of cancer tumor center’s coordinates, sizes joined with binary classification task.

Return type:

tf.Tensor

Notes

labels and predictions tensors must have [None, 7] shapes; labels[:, :3] and predictions[:, :3] correspond to normalized (from [0, 1] interval) zyx coordinates of cancer tumor, while labels[:, 3:6] and predictions[:, 3:6] correspond to sizes of cancer tumor along zyx axes(also normalized), finally, labels[:, 6] and predictions[:, 6] represent whether cancer tumor presents or not in the current crop.

radio.models.tf.losses.iou_3d(labels, predictions, epsilon=1e-06)[source]

Compute intersection over union in 3D case for input tensors.

Parameters:
  • labels (tf.Tensor) – tensor containg true values for sizes of nodules and their centers.
  • predictions (tf.Tensor) – tensor containing predicted values for sizes of nodules and their centers.
  • epsilon (float) – small real value used for avoiding division by zero error.
Returns:

tensor containing intersection over union computed on input tensors.

Return type:

tf.Tensor