Formula
Dice = 2 · |A ∩ B| / (|A| + |B|)Dice = 2 · TP / (2 · TP + FP + FN)Dice = 2 · IoU / (1 + IoU)Worked example
A model predicts 80 pixels of a lesion whose true mask has 100 pixels, and 60 of them overlap. Dice = 2 · 60 / (80 + 100) = 120 / 180 ≈ 0.67. The union is 80 + 100 − 60 = 120 pixels, so IoU = 60 / 120 = 0.5, and 2 · 0.5 / 1.5 gives the same 0.67.
Dice and IoU rank models the same way
Because one is a fixed function of the other, a model with higher Dice also has higher IoU on the same mask. Dice is never smaller than IoU, so a Dice of 0.8 is not better than an IoU of 0.7 from another paper; convert before comparing. Medical imaging tends to report Dice, while general segmentation benchmarks prefer IoU.
Dice as a loss
Soft Dice computes the same ratio on predicted probabilities instead of hard masks, and 1 − soft Dice serves as a training loss. It is popular when the foreground covers a tiny share of the image, since pixel-wise cross-entropy is then dominated by background; see class imbalance.
Edge cases
- Both masks empty: the formula becomes 0 / 0. Decide whether that image scores 1 or is skipped, and keep the choice fixed.
- Averaging per image or pooling all pixels first gives different numbers; small objects weigh more in the per-image mean.
Reading it from a Supervisely report
The semantic segmentation report on the model evaluation page shows pixel accuracy, IoU and boundary IoU; the third formula above turns its IoU into Dice. Models that produce such masks include UNet and MMSegmentation.