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...