Tversky loss is a loss function built from the Tversky index, which measures the overlap between the predicted region and the true region, allowing separate weights for excess foreground (FP) and missed foreground (FN). It generalizes the Dice loss and was proposed by Salehi et al. in 2017 for segmenting multiple sclerosis lesions in 3D MRI images.
With the set of true foreground pixels and the set of predicted foreground pixels, the Tversky index is as follows.
- (TP): the number of pixels correctly predicted as foreground
- (FP): the number of background pixels predicted as foreground, weighted by
- (FN): the number of foreground pixels missed, weighted by
With , it equals the Dice coefficient and counts FP and FN with the same weight.
The motivation lies in two problems common in medical image segmentation.
- Extremely little foreground: In lesion detection, it is not unusual for non-lesion pixels to outnumber lesion pixels by 500 times or more. Training on such imbalanced data pulls predictions toward the background.
- Misses are worse: Training on imbalanced data tends to give predictions with high precision (the fraction of predicted foreground that is correct) but low recall (the fraction of true foreground that is found). In diagnostic support, missing a lesion (FN) is considered less acceptable than an extra detection (FP).
The Dice loss handles class imbalance without weight tuning, but it corresponds to the harmonic mean of precision and recall (the F1 score) and treats FP and FN equally. Tversky loss lets exceed to penalize misses more strongly, making the balance between precision and recall adjustable.
The figure at the top shows the loss as the predicted foreground size varies, with the true foreground size set to 1. With , compared with (Dice loss), the loss for missed foreground (left side) becomes larger and the loss for excess foreground (right side) becomes smaller.

