Giter Club home page Giter Club logo

dice-coefficient-scale-sensitivity-pitfall's Introduction

Dice Coefficient and Its Sensitivity to Scale

In computer vision, we often use the Dice score to quantify the quality of a generated segmentation to its ground truth:

$$Dice = 2\frac{|Y\cap \hat{Y}|}{|Y| + |\hat{Y}|}$$

Where:

  • $Y$ is the ground truth
  • $\hat{Y}$ the estimate or prediction.

Let's name $r$ as the number of pixels removed by the estimate, that is the number of false negatives FN:

$$|Y\cap \hat{Y}| = |Y| - r, \quad r\in[0, |Y|]$$

Same thing for the number of pixels added $a$ by the estimate, that is the number of false positives FP:

$$|Y\cup \hat{Y}| = |Y| + a, \quad a\in[0, |\hat{Y}|]$$

We thus have:

$$\begin{equation} \begin{split} Dice & = 2\frac{|Y\cap \hat{Y}|}{|Y| + |\hat{Y}|} \\ & = 2\frac{|Y\cap \hat{Y}|}{|Y\cap \hat{Y}| + |Y\cup \hat{Y}|} \\ & =2\frac{|Y| - r}{2|Y|-r+a} \\ & =\frac{2|Y| - 2r}{2|Y|-r+a}\\ &=\frac{2|Y|-r+a -r -a}{2|Y|-r+a}\\ &=1-\frac{r+a }{2|Y|-r+a}\\ &=1-f(r,a)\\ \end{split} \end{equation}$$

The penalty factor $f(r,a)$ is null when $a=r=0$. We thus have $Dice=1$ as expected.

We can see that $f(r,a)\geq 0$.

Also, $\frac{\partial f}{\partial r}\gt 0$ and $\frac{\partial f}{\partial a}\geq 0$ show that small positive variations of $a$ or $r$ increase $f(r,a)$, and thus decrease the Dice coefficient, as expected.

However, the interesting thing is that $f(r,a)$ also depends on the size of the ground truth $|Y|$.

$f(r,a)$ decreases when the size $|Y|$ increases, which means that for two ground truth segmentations where $|Y_1|<|Y_2|$, and with the same number of pixel-wise errors $r+a$, we will have $Dice(Y_1, \hat{Y_1}) \lt Dice(Y_2, \hat{Y_2})$.

In other terms, it means that Dice overpenalises small objects, and is too tolerant with big objects.

Using a Dice loss or a Dice metric on a dataset with many different sizes of objects will cause your model to be biased.

A solution is to use the Generalized Dice Loss.

dice-coefficient-scale-sensitivity-pitfall's People

Contributors

jonas1312 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.