Conversation
There was a problem hiding this comment.
In addition, we should put this op in layers/nn.py or https://github.com/PaddlePaddle/Paddle/blob/develop/python/paddle/fluid/nets.py ?
python/paddle/fluid/layers/nn.py
Outdated
| """ | ||
| **Dice loss Layer** | ||
| Dice loss for comparing the similarity of two batch of data, | ||
| usually be used for binary image segmentation i.e. labels are binary. |
python/paddle/fluid/layers/nn.py
Outdated
| **Dice loss Layer** | ||
| Dice loss for comparing the similarity of two batch of data, | ||
| usually be used for binary image segmentation i.e. labels are binary. | ||
| The value between 0 to 1, 1 means totally match. |
There was a problem hiding this comment.
The value between 0 to 1
是什么值呢? 语法也不对。
There was a problem hiding this comment.
loss值为0,才代表完全match, 公式化表达是 dice-loss = 1 - 2 * intersection_area / total_area = (total_area - intersection_area) - intersection_area = (union_area - intersection_area) / total_area
There was a problem hiding this comment.
补充增加第三个等式的分母 dice-loss = 1 - 2 * intersection_area / total_area =( (total_area - intersection_area) - intersection_area) / total_area = (union_area - intersection_area) / total_area
python/paddle/fluid/layers/nn.py
Outdated
| The value between 0 to 1, 1 means totally match. | ||
|
|
||
| Args: | ||
| input (Variable): The predictions with shape [batch_size, ... , num_classes]. |
There was a problem hiding this comment.
The shape [batch_size, ... , num_classes] is not clear. Is the rank large than 2 (>=2D)? The first dimension is batch size, the last dimension is class number?
python/paddle/fluid/layers/nn.py
Outdated
|
|
||
| Args: | ||
| input (Variable): The predictions with shape [batch_size, ... , num_classes]. | ||
| label (Variable): The groud truth with shape [batch_szie, ... , 1]. |
There was a problem hiding this comment.
The rank of label is the same with input?
python/paddle/fluid/layers/nn.py
Outdated
| Args: | ||
| input (Variable): The predictions with shape [batch_size, ... , num_classes]. | ||
| label (Variable): The groud truth with shape [batch_szie, ... , 1]. | ||
| num_classes (integer): The number of target classes. |
There was a problem hiding this comment.
It seems the num_classes can be got from input.
python/paddle/fluid/layers/nn.py
Outdated
| input (Variable): The predictions with shape [batch_size, ... , num_classes]. | ||
| label (Variable): The groud truth with shape [batch_szie, ... , 1]. | ||
| num_classes (integer): The number of target classes. | ||
| reduce_dim (list<int>): The dimensions to be reduced. It should be set to input.shape[1:]. |
There was a problem hiding this comment.
It should be set to input.shape[1:].
If so, the reduce_dim can be set Inside this function? there is no need to be an argument?
python/paddle/fluid/layers/nn.py
Outdated
| Default: 0.00001 | ||
|
|
||
| Returns: | ||
| dice_loss (Variable): The dice loss. |
There was a problem hiding this comment.
Give the shape for the returned value.
| input, dim=reduce_dim) + reduce_sum( | ||
| label, dim=reduce_dim) | ||
| dice_score = (inse * 2 + epsilon) / (dice_denominator + epsilon) | ||
| return reduce_mean(dice_score) |
There was a problem hiding this comment.
It seems the returned loss should be 1 - dice_score from pytorch/pytorch#1249 .
There was a problem hiding this comment.
It may not be necessary to add epsilon to the numerator
There was a problem hiding this comment.
It may not be necessary to add epsilon to the numerator
Should be necessary since prediction [0,0,0,0] and target [0,0,0,0] expect a perfect score.
No description provided.