neupy.layers.pooling module

class neupy.layers.pooling.MaxPooling[source]

Maximum pooling layer.

Parameters:

size : tuple with 2 integers

Factor by which to downscale (vertical, horizontal). (2, 2) will halve the image in each dimension.

stride : tuple or int.

Stride size, which is the number of shifts over rows/cols to get the next pool region. If stride is None, it is considered equal to ds (no overlap on pooling regions).

padding : tuple or int

(pad_h, pad_w), pad zeros to extend beyond four borders of the images, pad_h is the size of the top and bottom margins, and pad_w is the size of the left and right margins.

ignore_border : bool

When True, (5, 5) input with size (2, 2) will generate a (2, 2) output. (3, 3) otherwise. Defaults to True.

name : str or None

Layer’s identifier. If name is equal to None than name will be generated automatically. Defaults to None.

Examples

2D pooling

>>> from neupy import layers
>>>
>>> network = layers.join(
...     layers.Input((3, 10, 10)),
...     layers.MaxPooling((2, 2)),
... )
>>> network.output_shape
(3, 5, 5)

1D pooling

>>> from neupy import layers
>>>
>>> network = layers.join(
...     layers.Input((10, 30)),
...     layers.Reshape((10, 30, 1)),
...     layers.MaxPooling((2, 1)),
... )
>>> network.output_shape
(10, 15, 1)

Attributes

input_shape (tuple) Layer’s input shape.
output_shape (tuple) Layer’s output shape.
training_state (bool) Defines whether layer in training state or not.
parameters (dict) Trainable parameters.
graph (LayerGraph instance) Graphs that stores all relations between layers.

Methods

disable_training_state() Swith off trainig state.
initialize() Set up important configurations related to the layer.
options = {'name': Option(class_name='BaseLayer', value=Property(name="name")), 'padding': Option(class_name='BasePooling', value=PaddingProperty(name="padding")), 'stride': Option(class_name='BasePooling', value=StrideProperty(name="stride")), 'ignore_border': Option(class_name='BasePooling', value=Property(name="ignore_border")), 'size': Option(class_name='BasePooling', value=TypedListProperty(name="size"))}[source]
output(input_value)[source]

Return output base on the input value.

Parameters:input_value
class neupy.layers.pooling.AveragePooling[source]

Average pooling layer.

Parameters:

mode : {include_padding, exclude_padding}

Give a choice to include or exclude padding. Defaults to include_padding.

size : tuple with 2 integers

Factor by which to downscale (vertical, horizontal). (2, 2) will halve the image in each dimension.

stride : tuple or int.

Stride size, which is the number of shifts over rows/cols to get the next pool region. If stride is None, it is considered equal to ds (no overlap on pooling regions).

padding : tuple or int

(pad_h, pad_w), pad zeros to extend beyond four borders of the images, pad_h is the size of the top and bottom margins, and pad_w is the size of the left and right margins.

ignore_border : bool

When True, (5, 5) input with size (2, 2) will generate a (2, 2) output. (3, 3) otherwise. Defaults to True.

name : str or None

Layer’s identifier. If name is equal to None than name will be generated automatically. Defaults to None.

Examples

2D pooling

>>> from neupy import layers
>>>
>>> network = layers.join(
...     layers.Input((3, 10, 10)),
...     layers.AveragePooling((2, 2)),
... )
>>> network.output_shape
(3, 5, 5)

1D pooling

>>> from neupy import layers
>>>
>>> network = layers.join(
...     layers.Input((10, 30)),
...     layers.Reshape((10, 30, 1)),
...     layers.AveragePooling((2, 1)),
... )
>>> network.output_shape
(10, 15, 1)

Attributes

input_shape (tuple) Layer’s input shape.
output_shape (tuple) Layer’s output shape.
training_state (bool) Defines whether layer in training state or not.
parameters (dict) Trainable parameters.
graph (LayerGraph instance) Graphs that stores all relations between layers.

Methods

disable_training_state() Swith off trainig state.
initialize() Set up important configurations related to the layer.
mode = None[source]
options = {'name': Option(class_name='BaseLayer', value=Property(name="name")), 'padding': Option(class_name='BasePooling', value=PaddingProperty(name="padding")), 'stride': Option(class_name='BasePooling', value=StrideProperty(name="stride")), 'mode': Option(class_name='AveragePooling', value=ChoiceProperty(name="mode")), 'ignore_border': Option(class_name='BasePooling', value=Property(name="ignore_border")), 'size': Option(class_name='BasePooling', value=TypedListProperty(name="size"))}[source]
output(input_value)[source]

Return output base on the input value.

Parameters:input_value
class neupy.layers.pooling.Upscale[source]

Upscales input over two axis (height and width).

Parameters:

scale : int or tuple with two int

Scaling factor for the input value. In the tuple first parameter identifies scale of the height and the second one of the width.

name : str or None

Layer’s identifier. If name is equal to None than name will be generated automatically. Defaults to None.

Examples

>>> from neupy import layers
>>>
>>> network = layers.join(
...     layers.Input((3, 10, 10)),
...     layers.Upscale((2, 2)),
... )
>>> network.output_shape
(3, 20, 20)

Attributes

input_shape (tuple) Layer’s input shape.
output_shape (tuple) Layer’s output shape.
training_state (bool) Defines whether layer in training state or not.
parameters (dict) Trainable parameters.
graph (LayerGraph instance) Graphs that stores all relations between layers.

Methods

disable_training_state() Swith off trainig state.
initialize() Set up important configurations related to the layer.
options = {'scale': Option(class_name='Upscale', value=ScaleFactorProperty(name="scale")), 'name': Option(class_name='BaseLayer', value=Property(name="name"))}[source]
output(input_value)[source]

Return output base on the input value.

Parameters:input_value
output_shape[source]
scale = None[source]
validate(input_shape)[source]

Validate input shape value before assigning it.

Parameters:input_shape : tuple with int
class neupy.layers.pooling.GlobalPooling[source]

Global pooling layer.

Parameters:

function : callable

Function that aggregates over dimensions. Defaults to theano.tensor.mean.

def agg_func(x, axis=None):
    pass

name : str or None

Layer’s identifier. If name is equal to None than name will be generated automatically. Defaults to None.

Examples

>>> from neupy import layers
>>>
>>> network = layers.join(
...     layers.Input((16, 4, 4)),
...     layers.GlobalPooling(),
... )
>>> network.output_shape
(16,)

Attributes

input_shape (tuple) Layer’s input shape.
output_shape (tuple) Layer’s output shape.
training_state (bool) Defines whether layer in training state or not.
parameters (dict) Trainable parameters.
graph (LayerGraph instance) Graphs that stores all relations between layers.

Methods

disable_training_state() Swith off trainig state.
initialize() Set up important configurations related to the layer.
function = None[source]
options = {'function': Option(class_name='GlobalPooling', value=Property(name="function")), 'name': Option(class_name='BaseLayer', value=Property(name="name"))}[source]
output(input_value)[source]

Return output base on the input value.

Parameters:input_value
output_shape[source]