Pooling layers

class lasagne.layers.MaxPool1DLayer(incoming, pool_size, stride=None, pad=0, ignore_border=True, **kwargs)[source]

1D max-pooling layer

Performs 1D max-pooling over the trailing axis of a 3D input tensor.

Parameters:

incoming : a Layer instance or tuple

The layer feeding into this layer, or the expected input shape.

pool_size : integer or iterable

The length of the pooling region. If an iterable, it should have a single element.

stride : integer, iterable or None

The stride between sucessive pooling regions. If None then stride == pool_size.

pad : integer or iterable

The number of elements to be added to the input on each side. Must be less than stride.

ignore_border : bool

If True, partial pooling regions will be ignored. Must be True if pad != 0.

**kwargs

Any additional keyword arguments are passed to the Layer superclass.

Notes

The value used to pad the input is chosen to be less than the minimum of the input, so that the output of each pooling region always corresponds to some element in the unpadded input region.

Using ignore_border=False prevents Theano from using cuDNN for the operation, so it will fall back to a slower implementation.

class lasagne.layers.MaxPool2DLayer(incoming, pool_size, stride=None, pad=(0, 0), ignore_border=True, **kwargs)[source]

2D max-pooling layer

Performs 2D max-pooling over the two trailing axes of a 4D input tensor.

Parameters:

incoming : a Layer instance or tuple

The layer feeding into this layer, or the expected input shape.

pool_size : integer or iterable

The length of the pooling region in each dimension. If an integer, it is promoted to a square pooling region. If an iterable, it should have two elements.

stride : integer, iterable or None

The strides between sucessive pooling regions in each dimension. If None then stride = pool_size.

pad : integer or iterable

Number of elements to be added on each side of the input in each dimension. Each value must be less than the corresponding stride.

ignore_border : bool

If True, partial pooling regions will be ignored. Must be True if pad != (0, 0).

**kwargs

Any additional keyword arguments are passed to the Layer superclass.

Notes

The value used to pad the input is chosen to be less than the minimum of the input, so that the output of each pooling region always corresponds to some element in the unpadded input region.

Using ignore_border=False prevents Theano from using cuDNN for the operation, so it will fall back to a slower implementation.

class lasagne.layers.MaxPool3DLayer(incoming, pool_size, stride=None, pad=(0, 0, 0), ignore_border=True, **kwargs)[source]

3D max-pooling layer

Performs 3D max-pooling over the three trailing axes of a 5D input tensor.

Parameters:

incoming : a Layer instance or tuple

The layer feeding into this layer, or the expected input shape.

pool_size : integer or iterable

The length of the pooling region in each dimension. If an integer, it is promoted to a cubic pooling region. If an iterable, it should have three elements.

stride : integer, iterable or None

The strides between sucessive pooling regions in each dimension. If None then stride = pool_size.

pad : integer or iterable

Number of elements to be added on each side of the input in each dimension. Each value must be less than the corresponding stride.

ignore_border : bool

If True, partial pooling regions will be ignored. Must be True if pad != (0, 0, 0).

**kwargs

Any additional keyword arguments are passed to the Layer superclass.

Notes

The value used to pad the input is chosen to be less than the minimum of the input, so that the output of each pooling region always corresponds to some element in the unpadded input region.

Using ignore_border=False prevents Theano from using cuDNN for the operation, so it will fall back to a slower implementation.

class lasagne.layers.Pool1DLayer(incoming, pool_size, stride=None, pad=0, ignore_border=True, mode='max', **kwargs)[source]

1D pooling layer

Performs 1D mean or max-pooling over the trailing axis of a 3D input tensor.

Parameters:

incoming : a Layer instance or tuple

The layer feeding into this layer, or the expected input shape.

pool_size : integer or iterable

The length of the pooling region. If an iterable, it should have a single element.

stride : integer, iterable or None

The stride between sucessive pooling regions. If None then stride == pool_size.

pad : integer or iterable

The number of elements to be added to the input on each side. Must be less than stride.

ignore_border : bool

If True, partial pooling regions will be ignored. Must be True if pad != 0.

mode : {‘max’, ‘average_inc_pad’, ‘average_exc_pad’}

Pooling mode: max-pooling or mean-pooling including/excluding zeros from partially padded pooling regions. Default is ‘max’.

**kwargs

Any additional keyword arguments are passed to the Layer superclass.

See also

MaxPool1DLayer
Shortcut for max pooling layer.

Notes

The value used to pad the input is chosen to be less than the minimum of the input, so that the output of each pooling region always corresponds to some element in the unpadded input region.

Using ignore_border=False prevents Theano from using cuDNN for the operation, so it will fall back to a slower implementation.

class lasagne.layers.Pool2DLayer(incoming, pool_size, stride=None, pad=(0, 0), ignore_border=True, mode='max', **kwargs)[source]

2D pooling layer

Performs 2D mean or max-pooling over the two trailing axes of a 4D input tensor.

Parameters:

incoming : a Layer instance or tuple

The layer feeding into this layer, or the expected input shape.

pool_size : integer or iterable

The length of the pooling region in each dimension. If an integer, it is promoted to a square pooling region. If an iterable, it should have two elements.

stride : integer, iterable or None

The strides between sucessive pooling regions in each dimension. If None then stride = pool_size.

pad : integer or iterable

Number of elements to be added on each side of the input in each dimension. Each value must be less than the corresponding stride.

ignore_border : bool

If True, partial pooling regions will be ignored. Must be True if pad != (0, 0).

mode : {‘max’, ‘average_inc_pad’, ‘average_exc_pad’}

Pooling mode: max-pooling or mean-pooling including/excluding zeros from partially padded pooling regions. Default is ‘max’.

**kwargs

Any additional keyword arguments are passed to the Layer superclass.

See also

MaxPool2DLayer
Shortcut for max pooling layer.

Notes

The value used to pad the input is chosen to be less than the minimum of the input, so that the output of each pooling region always corresponds to some element in the unpadded input region.

Using ignore_border=False prevents Theano from using cuDNN for the operation, so it will fall back to a slower implementation.

class lasagne.layers.Pool3DLayer(incoming, pool_size, stride=None, pad=(0, 0, 0), ignore_border=True, mode='max', **kwargs)[source]

3D pooling layer

Performs 3D mean or max-pooling over the three trailing axes of a 5D input tensor.

Parameters:

incoming : a Layer instance or tuple

The layer feeding into this layer, or the expected input shape.

pool_size : integer or iterable

The length of the pooling region in each dimension. If an integer, it is promoted to a cubic pooling region. If an iterable, it should have three elements.

stride : integer, iterable or None

The strides between sucessive pooling regions in each dimension. If None then stride = pool_size.

pad : integer or iterable

Number of elements to be added on each side of the input in each dimension. Each value must be less than the corresponding stride.

ignore_border : bool

If True, partial pooling regions will be ignored. Must be True if pad != (0, 0, 0).

mode : {‘max’, ‘average_inc_pad’, ‘average_exc_pad’}

Pooling mode: max-pooling or mean-pooling including/excluding zeros from partially padded pooling regions. Default is ‘max’.

**kwargs

Any additional keyword arguments are passed to the Layer superclass.

See also

MaxPool3DLayer
Shortcut for max pooling layer.

Notes

The value used to pad the input is chosen to be less than the minimum of the input, so that the output of each pooling region always corresponds to some element in the unpadded input region.

Using ignore_border=False prevents Theano from using cuDNN for the operation, so it will fall back to a slower implementation.

class lasagne.layers.Upscale1DLayer(incoming, scale_factor, mode='repeat', **kwargs)[source]

1D upscaling layer

Performs 1D upscaling over the trailing axis of a 3D input tensor.

Parameters:

incoming : a Layer instance or tuple

The layer feeding into this layer, or the expected input shape.

scale_factor : integer or iterable

The scale factor. If an iterable, it should have one element.

mode : {‘repeat’, ‘dilate’}

Upscaling mode: repeat element values or upscale leaving zeroes between upscaled elements. Default is ‘repeat’.

**kwargs

Any additional keyword arguments are passed to the Layer superclass.

class lasagne.layers.Upscale2DLayer(incoming, scale_factor, mode='repeat', **kwargs)[source]

2D upscaling layer

Performs 2D upscaling over the two trailing axes of a 4D input tensor.

Parameters:

incoming : a Layer instance or tuple

The layer feeding into this layer, or the expected input shape.

scale_factor : integer or iterable

The scale factor in each dimension. If an integer, it is promoted to a square scale factor region. If an iterable, it should have two elements.

mode : {‘repeat’, ‘dilate’}

Upscaling mode: repeat element values or upscale leaving zeroes between upscaled elements. Default is ‘repeat’.

**kwargs

Any additional keyword arguments are passed to the Layer superclass.

Notes

Using mode='dilate' followed by a convolution can be realized more efficiently with a transposed convolution, see lasagne.layers.TransposedConv2DLayer.

class lasagne.layers.Upscale3DLayer(incoming, scale_factor, mode='repeat', **kwargs)[source]

3D upscaling layer

Performs 3D upscaling over the three trailing axes of a 5D input tensor.

Parameters:

incoming : a Layer instance or tuple

The layer feeding into this layer, or the expected input shape.

scale_factor : integer or iterable

The scale factor in each dimension. If an integer, it is promoted to a cubic scale factor region. If an iterable, it should have three elements.

mode : {‘repeat’, ‘dilate’}

Upscaling mode: repeat element values or upscale leaving zeroes between upscaled elements. Default is ‘repeat’.

**kwargs

Any additional keyword arguments are passed to the Layer superclass.

class lasagne.layers.GlobalPoolLayer(incoming, pool_function=theano.tensor.mean, **kwargs)[source]

Global pooling layer

This layer pools globally across all trailing dimensions beyond the 2nd.

Parameters:

incoming : a Layer instance or tuple

The layer feeding into this layer, or the expected input shape.

pool_function : callable

the pooling function to use. This defaults to theano.tensor.mean (i.e. mean-pooling) and can be replaced by any other aggregation function.

**kwargs

Any additional keyword arguments are passed to the Layer superclass.

class lasagne.layers.FeaturePoolLayer(incoming, pool_size, axis=1, pool_function=theano.tensor.max, **kwargs)[source]

Feature pooling layer

This layer pools across a given axis of the input. By default this is axis 1, which corresponds to the feature axis for DenseLayer, Conv1DLayer and Conv2DLayer. The layer can be used to implement maxout.

Parameters:

incoming : a Layer instance or tuple

The layer feeding into this layer, or the expected input shape.

pool_size : integer

the size of the pooling regions, i.e. the number of features / feature maps to be pooled together.

axis : integer

the axis along which to pool. The default value of 1 works for DenseLayer, Conv1DLayer and Conv2DLayer.

pool_function : callable

the pooling function to use. This defaults to theano.tensor.max (i.e. max-pooling) and can be replaced by any other aggregation function.

**kwargs

Any additional keyword arguments are passed to the Layer superclass.

Notes

This layer requires that the size of the axis along which it pools is a multiple of the pool size.

class lasagne.layers.FeatureWTALayer(incoming, pool_size, axis=1, **kwargs)[source]

‘Winner Take All’ layer

This layer performs ‘Winner Take All’ (WTA) across feature maps: zero out all but the maximal activation value within a region.

Parameters:

incoming : a Layer instance or tuple

The layer feeding into this layer, or the expected input shape.

pool_size : integer

the number of feature maps per region.

axis : integer

the axis along which the regions are formed.

**kwargs

Any additional keyword arguments are passed to the Layer superclass.

Notes

This layer requires that the size of the axis along which it groups units is a multiple of the pool size.

class lasagne.layers.SpatialPyramidPoolingLayer(incoming, pool_dims=[4, 2, 1], mode='max', implementation='fast', **kwargs)[source]

Spatial Pyramid Pooling Layer

Performs spatial pyramid pooling (SPP) over the input. It will turn a 2D input of arbitrary size into an output of fixed dimension. Hence, the convolutional part of a DNN can be connected to a dense part with a fixed number of nodes even if the dimensions of the input image are unknown.

The pooling is performed over \(l\) pooling levels. Each pooling level \(i\) will create \(M_i\) output features. \(M_i\) is given by \(n_i * n_i\), with \(n_i\) as the number of pooling operation per dimension in level \(i\), and we use a list of the \(n_i\)‘s as a parameter for SPP-Layer. The length of this list is the level of the spatial pyramid.

Parameters:

incoming : a Layer instance or tuple

The layer feeding into this layer, or the expected input shape.

pool_dims : list of integers

The list of \(n_i\)‘s that define the output dimension of each pooling level \(i\). The length of pool_dims is the level of the spatial pyramid.

mode : string

Pooling mode, one of ‘max’, ‘average_inc_pad’, ‘average_exc_pad’ Defaults to ‘max’.

implementation : string

Either ‘fast’ or ‘kaiming’. The ‘fast’ version uses theano’s pool_2d operation, which is fast but does not work for all input sizes. The ‘kaiming’ mode is slower but implements the pooling as described in [1], and works with any input size.

**kwargs

Any additional keyword arguments are passed to the Layer superclass.

Notes

This layer should be inserted between the convolutional part of a DNN and its dense part. Convolutions can be used for arbitrary input dimensions, but the size of their output will depend on their input dimensions. Connecting the output of the convolutional to the dense part then usually demands us to fix the dimensions of the network’s InputLayer. The spatial pyramid pooling layer, however, allows us to leave the network input dimensions arbitrary. The advantage over a global pooling layer is the added robustness against object deformations due to the pooling on different scales.

References

[R42]He, Kaiming et al (2015): Spatial Pyramid Pooling in Deep Convolutional Networks for Visual Recognition. http://arxiv.org/pdf/1406.4729.pdf.