Pooling Layers#

Classes#

class AdaptivePool(shape, shapes, *, channels=True, mode='average', **kwargs)[source]#

Bases: BaseSingleLayer

Uses pooling to downscale the input to the desired shape.

Attributes:
groupint

Layer group, if 0 it will always be used, else it will only be used if its group matches the Networks

descriptionstr

Description of the layer

layersSequential

Layers to loop through in the forward pass

Parameters:
shapeint | list[int]

Output shape of the layer

shapeslist[list[int]]

Shape of the outputs from each layer

channelsbool, Optional

If the input includes a channels dimension, default = True

mode{‘average’, ‘max’}

Whether to use ‘max’ or ‘average’ pooling

**kwargs

Leftover parameters to pass to base layer for checking

extra_repr()[source]#

Displays layer parameters when printing the network

Returns:
str

Layer parameters

class Pool(shapes, *, kernel=2, stride=2, padding=0, mode='max', pool_kwargs=None, **kwargs)[source]#

Bases: BaseSingleLayer

Constructs a max or average pooling layer.

Supports 1D, 2D, and 3D pooling.

Attributes:
groupint

Layer group, if 0 it will always be used, else it will only be used if its group matches the Networks

descriptionstr

Description of the layer

layersSequential

Layers to loop through in the forward pass

Parameters:
shapeslist[list[int]]

Shape of the outputs from each layer

kernelint | list[int], Optional

Size of the kernel, default = 2

strideint | list[int], Optional

Stride of the kernel, default = 2

paddingint | {‘same’} | list[int], Optional

Input padding, can an int or ‘same’ where ‘same’ preserves the input shape, default = 0

mode{‘max’, ‘average’}

Whether to use ‘max’ or ‘average’ pooling

pool_kwargsdict[str, Any] | NoneType, Optional

Additional keyword arguments to pass to the pooling layer

**kwargs

Leftover parameters to pass to base layer for checking

forward(x, *args, **kwargs)[source]#

Forward pass of the pool layer.

Parameters:
xTensor

Input tensor of shape (N,…) and type float, where N is the batch size

*args

Optional arguments to pass to the parent forward method

**kwargs

Optional keyword arguments to pass to the parent forward method

Returns:
Tensor

Output tensor of shape (N,…) and type float

class PoolDownscale(scale, shapes, *, mode='max', **kwargs)[source]#

Bases: Pool

Downscales the input using pooling.

Supports 1D, 2D, and 3D pooling.

Attributes:
groupint

Layer group, if 0 it will always be used, else it will only be used if its group matches the Networks

descriptionstr

Description of the layer

layersSequential

Layers to loop through in the forward pass

Parameters:
scaleint

Stride and size of the kernel, which acts as the downscaling factor

shapeslist[list[int]]

Shape of the outputs from each layer

mode{‘max’, ‘average’}

Whether to use ‘max’ or ‘average’ pooling

**kwargs

Leftover parameters to pass to base layer for checking