Skip to content

Commit

Permalink
update 2.0 API for dice_loss and log_loss (PaddlePaddle#2738)
Browse files Browse the repository at this point in the history
* update 2.0 API for dice_loss and log_loss
  • Loading branch information
lijianshe02 authored Nov 3, 2020
1 parent d7e03ae commit 8be309d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
20 changes: 10 additions & 10 deletions doc/paddle/api/paddle/fluid/layers/dice_loss_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,24 @@ dice_loss定义为:
&= \frac{union\_area−intersection\_area}{total\_area}
参数:
- **input** (Variable) - 分类的预测概率,秩大于等于2的多维Tensor,维度为 :math:`[N_1, N_2, ..., N_k, D]` 。第一个维度的大小是batch_size,最后一维的大小D是类别数目。数据类型是float32或者float64
- **label** (Variable)- 正确的标注数据(groud truth),与输入 ``input`` 的秩相同的Tensor,维度为 :math:`[N_1, N_2, ..., N_k, 1]` 。第一个维度的大小是batch_size,最后一个维度的大小是1。数据类型为int32或者int64
- **input** (Tensor) - 分类的预测概率,秩大于等于2的多维Tensor,维度为 :math:`[N_1, N_2, ..., N_k, D]` 。第一个维度的大小是batch_size,最后一维的大小D是类别数目。数据类型是float32或者float64
- **label** (Tensor)- 正确的标注数据(groud truth),与输入 ``input`` 的秩相同的Tensor,维度为 :math:`[N_1, N_2, ..., N_k, 1]` 。第一个维度的大小是batch_size,最后一个维度的大小是1。数据类型为int32或者int64
- **epsilon** (float,可选) - 将会加到分子和分母上的数,浮点型的数值。如果输入和标签都为空,则确保dice为1。默认值:0.00001

返回: 按上述公式计算出来的损失函数的结果所表示的Tensor,shape为[batch_size, 1],数据类型与 ``input`` 相同
返回: Tensor,shape为[batch_size, 1],数据类型与 ``input`` 相同

返回类型: Variable

**代码示例**

.. code-block:: python
import paddle.fluid as fluid
x = fluid.layers.data(name='data', shape = [3, 224, 224, 2], dtype='float32')
label = fluid.layers.data(name='label', shape=[3, 224, 224, 1], dtype='float32')
predictions = fluid.layers.softmax(x)
loss = fluid.layers.dice_loss(input=predictions, label=label)
import paddle
import paddle.nn.functional as F
paddle.disable_static()
x = paddle.randn((3,224,224,2))
label = paddle.randint(high=2, shape=(3,224,224,1))
predictions = F.softmax(x)
loss = F.dice_loss(input=predictions, label=label)
Expand Down
19 changes: 10 additions & 9 deletions doc/paddle/api/paddle/fluid/layers/log_loss_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,26 @@ log_loss
参数:
- **input** (Variable) – 形为 [N x 1] 的二维张量, 其中 N 为 batch 大小。该输入是由前驱算子计算得来的概率, 数据类型是 float32。
- **label** (Variable) – 形为 [N x 1] 的二维张量,真值标签, 其中 N 为 batch 大小,数据类型是 float32。
- **input** (Tensor) – 形为 [N x 1] 的二维张量, 其中 N 为 batch 大小。该输入是由前驱算子计算得来的概率, 数据类型是 float32。
- **label** (Tensor) – 形为 [N x 1] 的二维张量,真值标签, 其中 N 为 batch 大小,数据类型是 float32。
- **epsilon** (float) – epsilon
- **name** (str,可选) – 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。

返回: 形为[N x 1]的二维张量,计算出的负log_loss值,数据类型为 float32
返回: Tensor, 形状为[N x 1], 数据类型为 float32

返回类型: Variable


**代码示例**

.. code-block:: python
import paddle.fluid as fluid
label = fluid.data(name='label', shape=[None, 1], dtype='float32')
prob = fluid.data(name='prob', shape=[None, 1], dtype='float32')
cost = fluid.layers.log_loss(input=prob, label=label)
import paddle
import paddle.nn.functional as F
paddle.disable_static()
label = paddle.randn((10,1))
prob = paddle.randn((10,1))
cost = F.log_loss(input=prob, label=label)
Expand Down

0 comments on commit 8be309d

Please sign in to comment.