In binary image segmentation, for given a set of images, it's true mask and predicted mask. How to compute dice score?, should I compute dice score for each image separately and then find mean across all images. or compute dice score for all images at once by flattening tensor? which is the correct way?

  • $\begingroup$ did you find a solution for this problem? $\endgroup$ Oct 22, 2022 at 18:04

1 Answer 1


Usually - Compute dice score for each image separately and then calculate mean across all images.


The above suggestion assumes that images may have truth masks of different size - and that they are equally important.

Example: Suppose 80% of your data have truth masks of size 1000px, while 20% have truth masks of size 10px. Now lets assume that all large masks are segmented perfectly, while the small ones are totally off (predicted with correct size, but no overlap).

Compute per image => dice = 0.8 * 1.0 + 0.2 * 0.0 = 0.8

Compute globally => dice = (0.8 * N) * 1000 / ((0.8 * N) * 1000 + (0.2 * N) * 10) = 0.9975 The small masks have negligible effect on the total dice score (although 80% of your images failed).

At some cases, it might make sense to measure a global dice score. You can look at it this way - what corresponds to an independent "test case"? an image or a pixel?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.