From 652e655fe0a7df956f6d76dc630a7e34aa30cd87 Mon Sep 17 00:00:00 2001 From: xiaoting <31891223+tink2123@users.noreply.github.com> Date: Fri, 17 Sep 2021 11:23:34 +0800 Subject: [PATCH] fix unpool doc, test=document_fix (#35806) * fix unpool doc, test=document_fix * fix typo for python example, test=document_fix --- python/paddle/nn/functional/pooling.py | 14 ++------------ python/paddle/nn/layer/pooling.py | 14 ++++---------- 2 files changed, 6 insertions(+), 22 deletions(-) diff --git a/python/paddle/nn/functional/pooling.py b/python/paddle/nn/functional/pooling.py index 4a96f884ca..27f4d4a7db 100755 --- a/python/paddle/nn/functional/pooling.py +++ b/python/paddle/nn/functional/pooling.py @@ -674,17 +674,8 @@ def max_unpool2d(x, name=None): """ This API implements max unpooling 2d opereation. + See more details in :ref:`api_nn_pooling_MaxUnPool2D` . - `max_unpool2d` is not fully invertible, since the non-maximal values are lost. - - `max_unpool2d` takes in as input the output of `max_unpool2d` - including the indices of the maximal values and computes a partial inverse - in which all non-maximal values are set to zero. - - `max_unpool2d` can map several input sizes to the same output - sizes. Hence, the inversion process can get ambiguous. - To accommodate this, you can provide the needed output size - as an additional argument `output_size` in the forward call. Args: x (Tensor): The input tensor of unpooling operator which is a 4-D tensor with @@ -735,9 +726,8 @@ def max_unpool2d(x, import paddle import paddle.nn.functional as F - import numpy as np - data = paddle.to_tensor(np.random.uniform(-1, 1, [1, 1, 6, 6]).astype(np.float32)) + data = paddle.rand(shape=[1,1,6,6]) pool_out, indices = F.max_pool2d(data, kernel_size=2, stride=2, padding=0, return_mask=True) # pool_out shape: [1, 1, 3, 3], indices shape: [1, 1, 3, 3] unpool_out = F.max_unpool2d(pool_out, indices, kernel_size=2, padding=0) diff --git a/python/paddle/nn/layer/pooling.py b/python/paddle/nn/layer/pooling.py index 8eb0da122e..b5d6d7834f 100755 --- a/python/paddle/nn/layer/pooling.py +++ b/python/paddle/nn/layer/pooling.py @@ -1134,16 +1134,10 @@ class MaxUnPool2D(Layer): """ This API implements max unpooling 2d opereation. - `max_unpool2d` is not fully invertible, since the non-maximal values are lost. - - `max_unpool2d` takes in as input the output of `max_unpool2d` - including the indices of the maximal values and computes a partial inverse - in which all non-maximal values are set to zero. + 'max_unpool2d' accepts the output of 'max_unpool2d' as input + Including the indices of the maximum value and calculating the partial inverse + All non-maximum values ​​are set to zero. - `max_unpool2d` can map several input sizes to the same output - sizes. Hence, the inversion process can get ambiguous. - To accommodate this, you can provide the needed output size - as an additional argument `output_size` in the forward call. Parameters: kernel_size (int|list|tuple): The unpool kernel size. If unpool kernel size is a tuple or list, @@ -1183,7 +1177,7 @@ class MaxUnPool2D(Layer): import paddle.nn.functional as F import numpy as np - data = paddle.to_tensor(np.random.uniform(-1, 1, [1, 1, 7, 7]).astype(np.float32)) + data = paddle.rand(shape=[1,1,7,7]) pool_out, indices = F.max_pool2d(data, kernel_size=2, stride=2, padding=0, return_mask=True) # pool_out shape: [1, 1, 3, 3], indices shape: [1, 1, 3, 3] Unpool2D = paddle.nn.MaxUnPool2D(kernel_size=2, padding=0) -- GitLab