Dice coefficient

The Dice coefficient measures the overlap of two masks as twice their intersection divided by the total size of both, from 0 for no overlap to 1 for a perfect match; for a binary mask it equals the F1 score computed over pixels.

MetricsAlso called Dice score, Dice similarity coefficient, Sørensen–Dice index, F1 over pixels

Formula

Dice = 2 · |A ∩ B| / (|A| + |B|)Dice = 2 · TP / (2 · TP + FP + FN)Dice = 2 · IoU / (1 + IoU)
A is the predicted mask and B the ground-truth mask, measured in pixels (or voxels in 3D). TP, FP and FN count pixels predicted correctly, predicted wrongly as foreground, and missed.

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.

Frequently asked questions.

What is a good Dice score?

It depends on the task, but in many segmentation problems scores above 0.8 count as good and above 0.9 as excellent; thin or small structures usually score lower. Compare models on the same validation set rather than against a fixed number.

What is Dice loss?

One minus the Dice coefficient, used as a training loss for segmentation. It works well when the foreground is small, because it measures overlap rather than counting every background pixel.