# dice_loss¶

paddle.fluid.layers.dice_loss(input, label, epsilon=1e-05, name=None)[source]

Dice loss for comparing the similarity between the input predictions and the label. This implementation is for binary classification, where the input is sigmoid predictions of each pixel, usually used for segmentation task. The dice loss can be defined as the following equation:

$\begin{split}dice\_loss &= 1 - \frac{2 * intersection\_area}{total\_area} \\ &= \frac{(total\_area - intersection\_area) - intersection\_area}{total\_area} \\ &= \frac{(union\_area - intersection\_area)}{total\_area}\end{split}$
Parameters
• input (Variable) – Tensor, rank>=2, shape is $$[N_1, N_2, ..., N_D]$$, where $$N_1$$ is the batch_size, $$N_D$$ is 1. It is usually the output predictions of sigmoid activation. The data type can be float32 or float64.

• label (Variable) – Tensor, the groud truth with the same rank as input, shape is $$[N_1, N_2, ..., N_D]$$. where $$N_1$$ is the batch_size, $$N_D$$ is 1. The data type can be float32 or float64.

• epsilon (float) – The epsilon will be added to the numerator and denominator. If both input and label are empty, it makes sure dice is 1. Default: 0.00001

• name (str, optional) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to Name

Returns

The dice loss with shape [1], data type is the same as input .

Return Type:

Varaible

Example

import paddle.fluid as fluid
x = fluid.data(name='data', shape = [3, 224, 224, 1], dtype='float32')
label = fluid.data(name='label', shape=[3, 224, 224, 1], dtype='float32')
predictions = fluid.layers.sigmoid(x)
loss = fluid.layers.dice_loss(input=predictions, label=label)