Skip to content
AI360Xpert
Beta

Tversky Loss for Segmentation

Tversky loss generalizes Dice with separate knobs for false positives and false negatives, so missing a lesion can cost more than overcalling one.

Tversky loss charges different prices for missed lesion pixels versus extra guessed pixels, steering the model toward recall.
Tversky loss charges different prices for missed lesion pixels versus extra guessed pixels, steering the model toward recall.

Why Does This Exist?

Dice punishes a missed lesion pixel exactly as much as an extra guessed pixel, but clinicians do not: a missed tumour is worse than a slightly wide outline. Tversky loss (Salehi et al., 2017) splits the denominator with weights α\alpha for false positives and β\beta for false negatives. Setting β=0.7\beta = 0.7, α=0.3\alpha = 0.3 tells training that recall matters more than precision.

Think of It Like This

Airport security versus a dinner guest list

Missing a banned item at security is catastrophic; pulling a clean bag aside costs minutes. Missing a dinner guest's name on the list is a shrug; seating a stranger causes an evening of awkwardness. Tversky is the dial that says which room you are guarding. Lesion screening is airport security: β\beta high.

Where it stops: cranking recall forever fills the mask with false alarms, and radiologists stop trusting it.

How It Actually Works

With predictions pip_i and truth gig_i:

TI=∑ipigi+ϵ∑ipigi+α∑ipi(1−gi)+β∑i(1−pi)gi+ϵL=1−TITI = \frac{\sum_i p_i g_i + \epsilon}{\sum_i p_i g_i + \alpha \sum_i p_i (1 - g_i) + \beta \sum_i (1 - p_i) g_i + \epsilon} \qquad \mathcal{L} = 1 - TI

α=β=0.5\alpha = \beta = 0.5 recovers Dice. The focal-Tversky variant raises (1−TI)γ(1 - TI)^\gamma to concentrate on hard cases. Standard lesion setting: α=0.3\alpha = 0.3, β=0.7\beta = 0.7.

Worked example

P=[0.8,0.7,0.1,0.2]P = [0.8, 0.7, 0.1, 0.2], G=[1,1,0,0]G = [1, 1, 0, 0]. True-positive mass 1.51.5. False-positive mass 0.30.3. False-negative mass 0.50.5. With α=0.3\alpha = 0.3, β=0.7\beta = 0.7: TI=1.5/(1.5+0.09+0.35)=1.5/1.94≈0.7732TI = 1.5 / (1.5 + 0.09 + 0.35) = 1.5 / 1.94 \approx 0.7732, loss ≈0.2268\approx 0.2268. Dice on the same numbers gave 0.05660.0566: Tversky charges more because it prices the 0.50.5 of missed lesion mass at 0.70.7 each.

Code

# Tversky index on the worked example.p = [0.8, 0.7, 0.1, 0.2]g = [1.0, 1.0, 0.0, 0.0]tp = sum(pi * gi for pi, gi in zip(p, g))fp = sum(pi * (1 - gi) for pi, gi in zip(p, g))fn = sum((1 - pi) * gi for pi, gi in zip(p, g))ti = tp / (tp + 0.3 * fp + 0.7 * fn)print(round(1 - ti, 4))# -> 0.2268

Watch Out For

Recall dial stuck at maximum

β=0.9\beta = 0.9 inflates masks until precision collapses and reviewers reject every prediction. Symptom: great recall, useless precision. Fix: track both on validation and stop at the clinical operating point, typically β\beta between 0.60.6 and 0.750.75.

Tversky on balanced natural scenes

On Cityscapes-style data the asymmetry buys nothing and destabilizes calibration. Symptom: no gain over Dice plus worse confidence. Fix: reserve Tversky for high-recall medical and defect tasks; use Dice or cross-entropy elsewhere.

The Quick Version

  • Tversky generalizes Dice with α\alpha on false positives and β\beta on false negatives.
  • α=β=0.5\alpha = \beta = 0.5 is exactly Dice; β=0.7\beta = 0.7 is the common recall-leaning start.
  • Missing-lesion mass is priced higher, so tiny structures get found.
  • Focal-Tversky adds a gamma exponent to focus on hard volumes.
  • Over-cranking beta destroys precision and reviewer trust.