From 9f642ed88124a20565678d8dc33cabad2abd633c Mon Sep 17 00:00:00 2001 From: lijianshe02 <48898730+lijianshe02@users.noreply.github.com> Date: Mon, 23 Nov 2020 20:39:14 +0800 Subject: [PATCH] =?UTF-8?q?fix=20English=20doc=20for=20dice=5Floss,=20log?= =?UTF-8?q?=5Floss,=20unfold=20and=20NLLLoss=20API=20test=3D=E2=80=A6=20(#?= =?UTF-8?q?28739)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix English doc for dice_loss, log_loss, unfold and NLLLoss API test=document_fix --- python/paddle/fluid/layers/nn.py | 25 ++++++++----------------- python/paddle/nn/functional/loss.py | 4 +--- python/paddle/nn/layer/loss.py | 8 ++------ 3 files changed, 11 insertions(+), 26 deletions(-) diff --git a/python/paddle/fluid/layers/nn.py b/python/paddle/fluid/layers/nn.py index 755356ac4c..fa9a1c75b3 100755 --- a/python/paddle/fluid/layers/nn.py +++ b/python/paddle/fluid/layers/nn.py @@ -7068,9 +7068,6 @@ def roi_align(input, def dice_loss(input, label, epsilon=0.00001, name=None): """ - :alias_main: paddle.nn.functional.dice_loss - :alias: paddle.nn.functional.dice_loss,paddle.nn.functional.loss.dice_loss - :old_api: paddle.fluid.layers.dice_loss Dice loss for comparing the similarity between the input predictions and the label. This implementation is for binary classification, where the input is sigmoid @@ -7106,7 +7103,6 @@ def dice_loss(input, label, epsilon=0.00001, name=None): 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) @@ -13039,9 +13035,6 @@ def grid_sampler(x, grid, name=None): def log_loss(input, label, epsilon=1e-4, name=None): """ - :alias_main: paddle.nn.functional.log_loss - :alias: paddle.nn.functional.log_loss,paddle.nn.functional.loss.log_loss - :old_api: paddle.fluid.layers.log_loss **Negative Log Loss Layer** @@ -13073,7 +13066,6 @@ def log_loss(input, label, epsilon=1e-4, name=None): 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) @@ -14462,9 +14454,6 @@ def deformable_conv(input, def unfold(x, kernel_sizes, strides=1, paddings=0, dilations=1, name=None): """ - :alias_main: paddle.nn.functional.unfold - :alias: paddle.nn.functional.unfold,paddle.nn.functional.common.unfold - :old_api: paddle.fluid.layers.unfold This op returns a col buffer of sliding local blocks of input x, also known as im2col for batched 2D image tensors. For each block under the convolution filter, @@ -14490,7 +14479,7 @@ def unfold(x, kernel_sizes, strides=1, paddings=0, dilations=1, name=None): Parameters: - x(Varaible): 4-D Tensor, input tensor of format [N, C, H, W], + x(Tensor): 4-D Tensor, input tensor of format [N, C, H, W], data type can be float32 or float64 kernel_sizes(int|list): The size of convolution kernel, should be [k_h, k_w] or an integer k treated as [k, k]. @@ -14513,22 +14502,24 @@ def unfold(x, kernel_sizes, strides=1, paddings=0, dilations=1, name=None): Returns: - The tensor variable corresponding to the sliding local blocks. + The tensor corresponding to the sliding local blocks. The output shape is [N, Cout, Lout] as decriabled above. Cout is the total number of values within each block, and Lout is the total number of such blocks. The data type of output is the same as the input :math:`x` Return Type: - Variable + Tensor Examples: .. code-block:: python - import paddle.fluid as fluid - x = fluid.data(name = 'data', shape = [100, 3, 224, 224], dtype = 'float32') - y = fluid.layers.unfold(x, [3, 3], 1, 1, 1) + import paddle + import paddle.nn.functional as F + + x = paddle.randn((100,3,224,224)) + y = F.unfold(x, [3, 3], 1, 1, 1) """ helper = LayerHelper("unfold", **locals()) diff --git a/python/paddle/nn/functional/loss.py b/python/paddle/nn/functional/loss.py index 4539ceb6c7..1b19c4c163 100644 --- a/python/paddle/nn/functional/loss.py +++ b/python/paddle/nn/functional/loss.py @@ -780,13 +780,11 @@ def nll_loss(input, [0.05689114, 0.0862954 , 0.6325046 ]]).astype(np.float32) label_np = np.array([0, 2, 1, 1, 0]).astype(np.int64) - place = paddle.CPUPlace() - paddle.disable_static(place) input = paddle.to_tensor(input_np) log_out = log_softmax(input) label = paddle.to_tensor(label_np) result = nll_loss(log_out, label) - print(result.numpy()) # [1.0720209] + print(result) # [1.0720209] """ if reduction not in ['sum', 'mean', 'none']: raise ValueError( diff --git a/python/paddle/nn/layer/loss.py b/python/paddle/nn/layer/loss.py index b16dcae7b6..a0186cc0e8 100644 --- a/python/paddle/nn/layer/loss.py +++ b/python/paddle/nn/layer/loss.py @@ -625,8 +625,6 @@ class BCELoss(fluid.dygraph.Layer): class NLLLoss(fluid.dygraph.Layer): """ - :alias_main: paddle.nn.NLLLoss - :alias: paddle.nn.NLLLoss,paddle.nn.layer.NLLLoss,paddle.nn.layer.loss.NLLLoss This class accepts input and target label and returns negative log likelihood cross error. It is useful to train a classification problem with C classes. @@ -693,7 +691,7 @@ class NLLLoss(fluid.dygraph.Layer): import paddle import numpy as np - nll_loss = paddle.nn.layer.NLLLoss() + nll_loss = paddle.nn.NLLLoss() log_softmax = paddle.nn.LogSoftmax(axis=1) input_np = np.array([[0.88103855, 0.9908683 , 0.6226845 ], @@ -703,13 +701,11 @@ class NLLLoss(fluid.dygraph.Layer): [0.05689114, 0.0862954 , 0.6325046 ]]).astype(np.float32) label_np = np.array([0, 2, 1, 1, 0]).astype(np.int64) - place = paddle.CPUPlace() - paddle.disable_static(place) input = paddle.to_tensor(input_np) log_out = log_softmax(input) label = paddle.to_tensor(label_np) result = nll_loss(log_out, label) - print(result.numpy()) # [1.0720209] + print(result) # [1.0720209] """ -- GitLab