Skip to content
AI360Xpert
Beta

IoU and Dice Score the Same Mask Twice

IoU and Dice read the same pixel overlap through two linked ratios, with Dice always scoring higher, so reports must convert before comparing.

IoU and Dice read the same overlap differently, so one mask gives two linked scores with Dice always scoring higher
IoU and Dice read the same overlap differently, so one mask gives two linked scores with Dice always scoring higher

Why Does This Exist?

Pixel accuracy rewards background: labeling everything road on a road-heavy photo scores well while finding nothing. Overlap ratios fix that by scoring only claimed and true foreground. Intersection over Union is the box standard, Dice is the medical-mask standard, and segmentation reports need both without confusion.

This page gives both formulas, one recomputed mask, and the exact link between them. Box matching details live in IoU, and the per-object masks being scored live in semantic segmentation.

Think of It Like This

Shared pizza slices counted two ways

Two friends claim slices from one pizza. The shared slices are the overlap, all distinct slices touched are the union, and every slice touched with shared ones counted twice is the Dice denominator. Same pizza, two bills, and the Dice bill always looks kinder than the IoU one.

Where it stops: neither bill says who dropped the slices, since both ratios hide whether the error was misses or false paint, so error analysis still needs the raw counts.

How It Actually Works

For truth AA and prediction BB, IoU=∣A∩B∣/∣A∪B∣\text{IoU} = |A \cap B| / |A \cup B| and Dice=2∣A∩B∣/(∣A∣+∣B∣)\text{Dice} = 2|A \cap B| / (|A| + |B|). The exact link is Dice=2IoU/(1+IoU)\text{Dice} = 2\text{IoU} / (1 + \text{IoU}), so Dice sits above IoU everywhere except 00 and 11 where they meet. Use IoU for detection-style reporting and Dice as the loss-friendly overlap on small structures, where its smoother gradient on tiny masks trains better.

Worked example

Take truth of 100100 pixels and prediction of 9090 pixels sharing 8080: 2020 missed, 1010 falsely painted. The union is 100+90−80=110100 + 90 - 80 = 110. IoU is 80/110≈0.72780 / 110 \approx 0.727. Dice is 2×80/(100+90)=160/190≈0.8422 \times 80 / (100 + 90) = 160 / 190 \approx 0.842. Check the link: 2×0.727/(1+0.727)=1.454/1.727≈0.8422 \times 0.727 / (1 + 0.727) = 1.454 / 1.727 \approx 0.842. Same mask, two scores, one exact conversion.

Code

Both ratios from the same counts, using only the standard library.

def overlap_scores(shared: int, truth: int, pred: int) -> tuple[float, float]:    union = truth + pred - shared    iou = shared / union    dice = 2 * shared / (truth + pred)    return round(iou, 3), round(dice, 3)
print(overlap_scores(80, 100, 90))# -> (0.727, 0.842)

Shared 8080 with truth 100100 and prediction 9090 gives 0.7270.727 and 0.8420.842. Convert with Dice=2IoU/(1+IoU)\text{Dice} = 2\text{IoU} / (1 + \text{IoU}) before comparing across papers.

Watch Out For

Comparing Dice to IoU as if the scales match

Dice 0.8420.842 looks better than IoU 0.7270.727 on the identical mask, so cross-paper claims evaporate after conversion. The symptom is a method that wins only because it reports Dice against rivals reporting IoU. Fix it by converting both sides to one scale before ranking.

Reporting ratios without the raw counts

Both ratios hide whether the 3030 wrong pixels were 2020 misses plus 1010 false alarms or the reverse, yet the fix differs: misses need recall work, false paint needs precision work. The symptom is a tuned threshold that raises the score while the failure mode stays unknown. Fix it by logging shared, missed, and false pixels alongside every ratio.

The Quick Version

  • IoU is overlap over union; Dice is twice overlap over the total touched.
  • The fixture scores 80/110≈0.72780 / 110 \approx 0.727 IoU and 160/190≈0.842160 / 190 \approx 0.842 Dice.
  • The link Dice=2IoU/(1+IoU)\text{Dice} = 2\text{IoU} / (1 + \text{IoU}) holds exactly; Dice sits higher except at 0 and 1.
  • Use IoU for detection-style reports and Dice for small-structure overlap.
  • Convert before comparing, and log raw counts behind every ratio.