Parent class: Pool3D

Derived classes: -

This module implements the operation of three-dimensional max pooling. For a detailed theoretical description, please see Pool3D.

For an input tensor of shape (N, C, D_{in}, H_{in}, W_{in}) and the output one of shape (N, C, D_{out}, H_{out}, W_{out}) the operation is performed as follows (we consider the i-th element of the batch and the j-th map of the output tensor):

out(N_i, C_j, d, h, w) = \max\limits_{t=0..k_d-1}\max\limits_{m=0..k_h-1}\max\limits_{n=0..k_w-1}(input(N_i, C_j, stride_d \times d + t, stride_h \times h + m, stride_w \times w + n))


N - size of the batch;
C - number of maps in the tensor;
H - tensor map height;
W - tensor map width;
stride_d, stride_h, stride_w - pooling stride along the depth, height and width of the maps, respectively;
k_d, k_h, k_w - size of the pooling kernel in depth, height and width, respectively.


def __init__(self, size=2, stride=2, pad=0, name=None):


Parameter Allowed types Description Default
size Union[int, tuple] Kernel size 2
stride Union[int, tuple] Pooling stride 2
pad Union[int, tuple] Input maps padding 0
name str Layer name None


size - possible to specify either a single size of the pooling kernel, in which case it will be cubic, or a tuple (size_d, size_h, size_w), where size_d is the depth of the pooling kernel, size_h is the height of the pooling kernel, and size_w is its width;

stride - possible to specify either a single value of the pooling stride along all the axes of the map, or a tuple (stride_d, stride_h, stride_w), where stride_d is the value of the pooling stride along the depth of the map, stride_h is the value of the pooling stride along the map height, and stride_w is along the width;

pad - possible to specify either a single padding value for all sides of the maps, or a tuple (pad_d, pad_h, pad_w), where pad_d is the padding value on each side along the depth of the map, pad_h is along the height of the map, and pad_w is along the width.


If you set any of the size, stride or pad parameters different for the map axes, then the values of these parameters must be explicitly specified in a three-element tuple, otherwise an error will occur.


Necessary imports.

import numpy as np
from PuzzleLib.Backend import gpuarray
from PuzzleLib.Modules import MaxPool3D


gpuarray is required to properly place the tensor in the GPU

For this module, the examples are given in a simplified version. For a more visual presentation, you can take a look at the examples in MaxPool2D.

batchsize, maps, d, h, w = 1, 1, 6, 6, 6
data = gpuarray.to_gpu(np.random.randn(batchsize, maps, d, h, w).astype(np.float32))
Let us initialize a module with standard parameters (size=2, stride=2, pad=0):

pool = MaxPool3D()
Let us leave all parameters the same size:

pool = MaxPool3D(size=4)
The size parameter can be set different for each axis of the map:
pool = MaxPool3D(size=(2, 4, 2))
The stride and pad parameters can also be set different for each axis of the map:
pool = MaxPool3D(size=4, stride=(1, 4, 4), pad=(0, 1, 1))

As mentioned earlier, if the parameter has different values for different axes, then all these values must be passed explicitly. The following example will throw an error:

pool = MaxPool3D(stride=(1, 3))