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 : {valid, same}

(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.

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((10, 10, 3)),
...     layers.MaxPooling((2, 2)),
... )
>>> network.output_shape
(3, 5, 5)

1D pooling

>>> from neupy import layers
>>>
>>> network = layers.join(
...     layers.Input((30, 10)),
...     layers.Reshape((10, 1, 30)),
...     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")), 'size': Option(class_name='BasePooling', value=TypedListProperty(name="size")), 'stride': Option(class_name='BasePooling', value=Spatial2DProperty(name="stride")), 'padding': Option(class_name='BasePooling', value=ChoiceProperty(name="padding"))}[source]
pooling_type = 'MAX'[source]
class neupy.layers.pooling.AveragePooling[source]

Average 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 : {valid, same}

(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.

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((10, 10, 3)),
...     layers.AveragePooling((2, 2)),
... )
>>> network.output_shape
(3, 5, 5)

1D pooling

>>> from neupy import layers
>>>
>>> network = layers.join(
...     layers.Input((30, 10)),
...     layers.Reshape((10, 1, 30)),
...     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.
options = {'name': Option(class_name='BaseLayer', value=Property(name="name")), 'size': Option(class_name='BasePooling', value=TypedListProperty(name="size")), 'stride': Option(class_name='BasePooling', value=Spatial2DProperty(name="stride")), 'padding': Option(class_name='BasePooling', value=ChoiceProperty(name="padding"))}[source]
pooling_type = 'AVG'[source]
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.layers import *
>>> network = Input((10, 10, 3)) > 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 = {'name': Option(class_name='BaseLayer', value=Property(name="name")), 'scale': Option(class_name='Upscale', value=ScaleFactorProperty(name="scale"))}[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 : {avg, max} or callable

Common functions has been predefined for the user. These options are available:

  • avg - For average global pooling. The same as tf.reduce_mean.
  • max - For average global pooling. The same as tf.reduce_max.

Parameters also excepts custom functions that have following format.

def agg_func(x, axis=None):
    pass

Defaults to avg.

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.layers import *
>>> network = Input((4, 4, 16)) > GlobalPooling('avg')
>>> 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 = {'name': Option(class_name='BaseLayer', value=Property(name="name")), 'function': Option(class_name='GlobalPooling', value=FunctionWithOptionsProperty(name="function"))}[source]
output(input_value)[source]

Return output base on the input value.

Parameters:input_value
output_shape[source]