Chapter 8 – Algorithm-Level Deep Learning Techniques
- This has been left as an exercise for you.
- This has been left as an exercise for you.
- Tversky loss is based on the Tversky index, which is defined by the following formula:
TverskyIndex = TruePositive _______________________________________ TruePositive+ α * FalsePositive + (1 − α) * FalseNegative
A smoothing factor is added to both the numerator and denominator to avoid division by zero.
alpha
is a hyperparameter that can be tuned:import torch import torch.nn.functional as F def Tversky(y_true, y_pred, smooth=1, alpha=0.8): y_true_pos = y_true.view(-1) y_pred_pos = y_pred.view(-1) true_pos = torch.sum(y_true_pos * y_pred_pos) false_neg = torch.sum(y_true_pos * (1 - y_pred_pos)) false_pos = torch.sum((1 - y_true_pos) * y_pred_pos...