AdaptiveMaxPool3d_cn.rst 3.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
.. _cn_api_nn_AdaptiveMaxPool3d:


AdaptiveMaxPool3d
-------------------------------

.. py:function:: paddle.nn.AdaptiveMaxPool3d(output_size, return_indices=False, name=None)

该算子根据输入 `x` , `output_size` 等参数对一个输入Tensor计算3D的自适应平均池化。输入和输出都是5-D Tensor,
默认是以 `NCDHW` 格式表示的,其中 `N` 是 batch size, `C` 是通道数, `D` , `H` , `W` 分别是输入特征的深度,高度,宽度.

计算公式如下:

..  math::

    dstart &= floor(i * D_{in} / D_{out})
    
    dend &= ceil((i + 1) * D_{in} / D_{out})
    
    hstart &= floor(j * H_{in} / H_{out})
    
    hend &= ceil((j + 1) * H_{in} / H_{out})
    
    wstart &= floor(k * W_{in} / W_{out})
    
    wend &= ceil((k + 1) * W_{in} / W_{out})
    
    Output(i ,j, k) &= max(Input[dstart:dend, hstart:hend, wstart:wend])

参数
:::::::::
    - **output_size** (int|list|tuple): 算子输出特征图的高宽长大小,其数据类型为int,list或tuple。
    - **return_indices** (bool): 如果设置为True,则会与输出一起返回最大值的索引,默认为False。
    - **name** (str,可选): 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。

形状
:::::::::
    - **x** (Tensor): 默认形状为(批大小,通道数,输出特征长度),即NCDHW格式的5-D Tensor。 其数据类型为float32或者float64。
    - **output** (Tensor): 默认形状为(批大小,通道数,输出特征长度),即NCDHW格式的5-D Tensor。 其数据类型与输入x相同。

返回
:::::::::
计算AdaptiveMaxPool3d的可调用对象

抛出异常
:::::::::
    - ``ValueError`` - ``output_size`` 应是一个整数或长度为3的list,tuple

代码示例
:::::::::

.. code-block:: python

        # adaptive max pool3d
        # suppose input data in shape of [N, C, D, H, W], `output_size` is [l, m, n],
        # output shape is [N, C, l, m, n], adaptive pool divide D, H and W dimensions
        # of input data into l * m * n grids averagely and performs poolings in each
        # grid to get output.
        # adaptive max pool performs calculations as follow:
        #
        #     for i in range(l):
        #         for j in range(m):
        #             for k in range(n):
        #                 dstart = floor(i * D / l)
        #                 dend = ceil((i + 1) * D / l)
        #                 hstart = floor(j * H / m)
        #                 hend = ceil((j + 1) * H / m)
        #                 wstart = floor(k * W / n)
        #                 wend = ceil((k + 1) * W / n)
        #                 output[:, :, i, j, k] =
        #                     max(input[:, :, dstart:dend, hstart: hend, wstart: wend])
        import paddle
        import numpy as np
        paddle.disable_static()
        input_data = np.random.rand(2, 3, 8, 32, 32)
        x = paddle.to_tensor(input_data)
        pool = paddle.nn.AdaptiveMaxPool3d(output_size=4)
        out = pool(x)
        # out shape: [2, 3, 4, 4, 4]
S
shippingwang 已提交
80 81
        pool = paddle.nn.AdaptiveMaxPool3d(output_size=3, return_indices=True)
        out, indices = pool(x)
82
        # out shape: [2, 3, 4, 4, 4], indices shape: [2, 3, 4, 4, 4]