fractional_max_pool3d¶
- paddle.nn.functional. fractional_max_pool3d ( x, output_size, kernel_size=None, random_u=None, return_mask=False, name=None ) [source]
-
This operation applies 3D fractional max pooling on input tensor, which is described in the paper:
[1] Ben Graham, Fractional Max-Pooling. 2015. http://arxiv.org/abs/1412.6071
The d, h and w dimensions of the output tensor are determined by the parameter output_size.
For each dimension, the fractional max pooling:
\[ \begin{align}\begin{aligned}\alpha &= size_{input} / size_{output}\\index_{start} &= ceil( \alpha * (i + u) - 1)\\index_{end} &= ceil( \alpha * (i + 1 + u) - 1)\\Output &= max(Input[index_{start}:index_{end}])\\where, u \in (0, 1), i = 0,1,2...size_{output}\end{aligned}\end{align} \]The
u
from the formula is the parameterrandom_u
, and subtract1
for the index starts from0
instead of1
whereceil
works.For instance, giving a sequence of length
7
is[2, 4, 3, 1, 5, 2, 3]
,output_size
is5
andrandom_u
is0.3
. Thealpha = 7/5 = 1.4
, the starts of index is[0, 1, 3, 4, 6]
, the ends of index is[1, 3, 4, 6, 7]
and makes the random sequence in the paper isindex_end - index_start = [1, 2, 1, 2, 1]
. The strides and kernel_sizes are both equal to the random sequence, giving the final pooling output is[2, 4, 1, 5, 3]
.- Parameters
-
x (Tensor) – The input tensor of fractional max pool3d operator, which is a 5-D tensor. The data type can be float16, bfloat16, float32, float64.
output_size (int|list|tuple) – The output size. If output size is a tuple or list, it must contain three element, (D, H, W). D, H and W can be either a int, or None which means the size will be the same as that of the input.
kernel_size (int|list|tuple) – The pool kernel size. If the kernel size is a tuple or list, it must contain three integers, (kernel_size_Depth, kernel_size_Height, kernel_size_Width). Otherwise, the pool kernel size will be the cube of an int. Default is None, means using the non-overlapping mode.
random_u (float) – A random float number in range (0, 1) for the fractional pooling. Default None, means randomly generated by framework which can be fixed by
paddle.seed
.return_mask (bool, optional) – If true, the index of max pooling point will be returned along with outputs. Default False.
name (str, optional) – For detailed information, please refer to Name. Usually name is no need to set and None by default.
- Returns
-
The output tensor of fractional max pool3d result which is a 5-D tensor.. The data type is same as input tensor.
- Return type
-
Tensor
Examples
>>> # fractional 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], fractional pool divide D, H and W dimensions >>> # of input data into l * m * n grids and performs poolings in each >>> # grid to get output. >>> import paddle >>> x = paddle.rand([2, 3, 8, 32, 32]) >>> # disjont: without `kernel_size` >>> pool_out = paddle.nn.functional.fractional_max_pool3d(x, output_size=3) >>> print(pool_out.shape) [2, 3, 3, 3, 3] >>> # overlapping: with `kernel_size` >>> pool_out = paddle.nn.functional.fractional_max_pool3d(x, kernel_size=2, output_size=3) >>> print(pool_out.shape) [2, 3, 3, 3, 3] >>> pool_out, indices = paddle.nn.functional.fractional_max_pool3d(x, output_size=[2, 3, 3], return_mask=True) >>> print(pool_out.shape) [2, 3, 2, 3, 3] >>> print(indices.shape) [2, 3, 2, 3, 3]