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.
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 and prediction , and . The exact link is , so Dice sits above IoU everywhere except and 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 pixels and prediction of pixels sharing : missed, falsely painted. The union is . IoU is . Dice is . Check the link: . 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 with truth and prediction gives and . Convert with before comparing across papers.
Watch Out For
Comparing Dice to IoU as if the scales match
Dice looks better than IoU 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 wrong pixels were misses plus 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 IoU and Dice.
- The link 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.