# pool3d¶

paddle.fluid.layers.nn. pool3d ( input, pool_size=- 1, pool_type='max', pool_stride=1, pool_padding=0, global_pooling=False, use_cudnn=True, ceil_mode=False, name=None, exclusive=True, data_format='NCDHW' ) [source]

This operation calculates the output based on the input, pooling_type, pool_size, pool_stride, and pool_padding parameters. Input(X) and output(Out) are in NCDHW or NDHWC format, where N is batch size, C is the number of channels, and D, H and W are the depth, height and width of the feature, respectively. Parameters(pool_size, pool_stride, pool_padding) hold three integer elements. These three elements represent depth, height and width, respectively. The input(X) size and output(Out) size may be different.

Example: Input: X shape: $(N, C, D_{in}, H_{in}, W_{in})$ Output: Out shape: $(N, C, D_{out}, H_{out}, W_{out})$

For pool_padding = “SAME”: $$D_{out} = \frac{(D_{in} + strides[0] - 1)}{strides[0]}$$ $$H_{out} = \frac{(H_{in} + strides[1] - 1)}{strides[1]}$$ $$W_{out} = \frac{(W_{in} + strides[2] - 1)}{strides[2]}$$

For pool_padding = “VALID”: $$D_{out} = \frac{(D_{in} - ksize[0] + strides[0])}{strides[0]}$$ $$H_{out} = \frac{(H_{in} - ksize[1] + strides[1])}{strides[1]}$$ $$W_{out} = \frac{(W_{in} - ksize[2] + strides[2])}{strides[2]}$$

For ceil_mode = false: $$D_{out} = \frac{(D_{in} - ksize[0] + pad_depth_front + pad_depth_back)}{strides[0]} + 1$$ $$H_{out} = \frac{(H_{in} - ksize[1] + pad_height_top + pad_height_bottom)}{strides[1]} + 1$$ $$W_{out} = \frac{(W_{in} - ksize[2] + pad_width_left + pad_width_right)}{strides[2]} + 1$$ For ceil_mode = true: $$D_{out} = \frac{(D_{in} - ksize[0] + pad_depth_front + pad_depth_back + strides[0] -1)}{strides[0]} + 1$$ $$H_{out} = \frac{(H_{in} - ksize[1] + pad_height_top + pad_height_bottom + strides[1] -1)}{strides[1]} + 1$$ $$W_{out} = \frac{(W_{in} - ksize[2] + pad_width_left + pad_width_right + strides[2] -1)}{strides[2]} + 1$$

For exclusive = false: $$dstart = i * strides[0] - pad_depth_front$$ $$dend = dstart + ksize[0]$$ $$hstart = j * strides[1] - pad_height_top$$ $$hend = hstart + ksize[1]$$ $$wstart = k * strides[2] - pad_width_left$$ $$wend = wstart + ksize[2]$$ $$Output(i ,j, k) = \frac{sum(Input[dstart:dend, hstart:hend, wstart:wend])}{ksize[0] * ksize[1] * ksize[2]}$$

For exclusive = true: $$dstart = max(0, i * strides[0] - pad_depth_front)$$ $$dend = min(D, dstart + ksize[0])$$ $$hstart = max(0, j * strides[1] - pad_height_top)$$ $$hend = min(H, hstart + ksize[1])$$ $$wstart = max(0, k * strides[2] - pad_width_left)$$ $$wend = min(W, wstart + ksize[2])$$ $$Output(i ,j, k) = \frac{sum(Input[dstart:dend, hstart:hend, wstart:wend])}{(dend - dstart) * (hend - hstart) * (wend - wstart)}$$

Parameters
• input (Variable) – The input tensor of pooling operator, which is a 5-D tensor with shape [N, C, D, H, W]. The format of input tensor is “NCDHW” or “NDHWC”, where N is batch size, C is the number of channels, D is the depth of the feature, H is the height of the feature, and W is the width of the feature.

• pool_size (int|list|tuple) – The pool kernel size. If pool kernel size is a tuple or list, it must contain three integers, (pool_size_Depth, pool_size_Height, pool_size_Width). Otherwise, the pool kernel size will be the cube of an int.

• pool_type (string) – (string) Pooling type, can be “max” for max-pooling and “avg” for average-pooling

• pool_stride (string|int|list|tuple)) – The pool padding. If pool_padding is a string, either ‘VALID’ or ‘SAME’ which is the padding algorithm. If pool stride size is a tuple or list, it must contain three integers, [stride_Depth, stride_Height, stride_Width]. Otherwise, the pool stride size will be a cube of an int.

• global_pooling (bool) – (bool) Whether to use the global pooling. If global_pooling = true, kernel size and paddings will be ignored. Default False

• use_cudnn (bool) – (bool) Only used in cudnn kernel, need install cudnn. Default False

• ceil_mode (bool) – (bool) Whether to use the ceil function to calculate output height and width. False is the default. If it is set to False, the floor function will be used. Default False

• name (str, optional) – For detailed information, please refer to Name. Usually name is no need to set and None by default.

• exclusive (bool) – Whether to exclude padding points in average pooling mode, default is true.

• data_format (string) – The data format of the input and output data. An optional string from: “NCDHW”, “NDHWC”. The default is “NCDHW”. When it is “NCDHW”, the data is stored in the order of: [batch_size, input_channels, input_depth, input_height, input_width].

Returns

The output tensor of pooling result. The data type is same as input tensor.

Return type

Variable

Raises
• ValueError – If pool_type is not “max” nor “avg”.

• ValueError – If global_pooling is False and pool_size is -1.

• TypeError – If use_cudnn is not a bool value.

• ValueError – If data_format is not “NCDHW” or “NDHWC”.

• ValueError – If pool_padding is a string, but not “SAME” or “VALID”.

• ValueError – If pool_padding is “VALID”, but ceil_mode is True.

• ValueError – If pool_padding is a list or tuple, but the elements in the batch or channel dimensions are non-zero.

• ShapeError – If the input is not a 4-D or 5-D Tensor.

• ShapeError – If the dimension of input minus the size of pool_stride is not 2.

• ShapeError – If the size of pool_size and pool_stride is not equal.

• ShapeError – If the output’s shape calculated is not greater than 0.

Examples

import paddle.fluid as fluid

data = fluid.data(name='data', shape=[None, 3, 32, 32, 32], dtype='float32')

# max pool3d
pool3d = fluid.layers.pool3d(
input = data,
pool_size = 2,
pool_type = "max",
pool_stride = 1,
global_pooling=False)

# average pool3d
pool3d = fluid.layers.pool3d(
input = data,
pool_size = 2,
pool_type = "avg",
pool_stride = 1,
global_pooling=False)

# global average pool3d
pool3d = fluid.layers.pool3d(
input = data,
pool_size = 2,
pool_type = "avg",
pool_stride = 1,
global_pooling=True)

# example 1:
# Attr(pool_padding) is a list with 6 elements, Attr(data_format) is "NCDHW".
out_1 = fluid.layers.pool3d(
input = data,
pool_size = 2,
pool_type = "avg",
pool_stride = 1,
pool_padding = [1, 2, 1, 0, 1, 2],
global_pooling = False,
data_format = "NCDHW")

# example 2:
# Attr(pool_padding) is a string, Attr(data_format) is "NCDHW".
out_2 = fluid.layers.pool3d(
input = data,
pool_size = 3,
pool_type = "avg",
pool_stride = 1,