neupy.layers.convolutions module

class neupy.layers.convolutions.Convolution[source]

Convolutional layer.

Parameters:

size : tuple of int

Filter shape. In should be defined as a tuple with three integers (filter rows, filter columns, output channels).

padding : {same, valid}, int, tuple

Zero padding for the input tensor.

  • valid - Padding won’t be added to the tensor. Result will be the same as for padding=0
  • same - Padding will depend on the number of rows and columns in the filter. This padding makes sure that image with the stride=1 won’t change its width and height. It’s the same as padding=(filter rows // 2, filter columns // 2).
  • Custom value for the padding can be specified as an integer, like padding=1 or it can be specified as a tuple when different dimensions have different padding values, for example padding=(2, 3).

Defaults to valid.

stride : tuple with ints, int.

Stride size. Defaults to (1, 1)

dilation : int, tuple

Rate for the fiter upsampling. When dilation > 1 layer will become diated convolution (or atrous convolution). Defaults to 1.

weight : array-like, Tensorfow variable, scalar or Initializer

Defines layer’s weights. Shape of the weight will be equal to (filter rows, filter columns, input channels, output channels). Default initialization methods you can find here. Defaults to HeNormal(gain=2).

bias : 1D array-like, Tensorfow variable, scalar, Initializer or None

Defines layer’s bias. Default initialization methods you can find here. Defaults to Constant(0). The None value excludes bias from the calculations and do not add it into parameters list.

name : str or None

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

Examples

2D Convolution

>>> from neupy import layers
>>>
>>> layers.join(
...     layers.Input((28, 28, 3)),
...     layers.Convolution((3, 3, 16)),
... )

1D Convolution

>>> from neupy import layers
>>>
>>> layers.join(
...     layers.Input((30, 10)),
...     layers.Reshape((30, 1, 10)),
...     layers.Convolution((3, 1, 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.
bias_shape[source]
dilation = None[source]
find_output_from_input_shape(input_shape)[source]
options = {'name': Option(class_name='BaseLayer', value=Property(name="name")), 'size': Option(class_name='Convolution', value=TypedListProperty(name="size")), 'weight': Option(class_name='Convolution', value=ParameterProperty(name="weight")), 'bias': Option(class_name='ParameterBasedLayer', value=ParameterProperty(name="bias")), 'padding': Option(class_name='Convolution', value=PaddingProperty(name="padding")), 'stride': Option(class_name='Convolution', value=Spatial2DProperty(name="stride")), 'dilation': Option(class_name='Convolution', value=Spatial2DProperty(name="dilation"))}[source]
output(input_value)[source]

Return output base on the input value.

Parameters:input_value
output_shape[source]
output_shape_per_dim(*args, **kwargs)[source]
padding = None[source]
size = None[source]
stride = None[source]
validate(input_shape)[source]

Validate input shape value before assigning it.

Parameters:input_shape : tuple with int
weight = None[source]
weight_shape[source]
class neupy.layers.convolutions.Deconvolution[source]

Deconvolution layer. It’s commonly called like this in the literature, but it’s just gradient of the convolution and not actual deconvolution.

Parameters:

size : tuple of int

Filter shape. In should be defined as a tuple with three integers (filter rows, filter columns, output channels).

padding : {same, valid}, int, tuple

Zero padding for the input tensor.

  • valid - Padding won’t be added to the tensor. Result will be the same as for padding=0
  • same - Padding will depend on the number of rows and columns in the filter. This padding makes sure that image with the stride=1 won’t change its width and height. It’s the same as padding=(filter rows // 2, filter columns // 2).
  • Custom value for the padding can be specified as an integer, like padding=1 or it can be specified as a tuple when different dimensions have different padding values, for example padding=(2, 3).

Defaults to valid.

stride : tuple with ints, int.

Stride size. Defaults to (1, 1)

weight : array-like, Tensorfow variable, scalar or Initializer

Defines layer’s weights. Shape of the weight will be equal to (filter rows, filter columns, output channels, input channels). Default initialization methods you can find here. Defaults to HeNormal(gain=2).

bias : 1D array-like, Tensorfow variable, scalar, Initializer or None

Defines layer’s bias. Default initialization methods you can find here. Defaults to Constant(0). The None value excludes bias from the calculations and do not add it into parameters list.

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
>>>
>>> layers.join(
...     layers.Input((28, 28, 3)),
...     layers.Convolution((3, 3, 16)),
...     layers.Deconvolution((3, 3, 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.
dilation = None[source]
options = {'name': Option(class_name='BaseLayer', value=Property(name="name")), 'size': Option(class_name='Convolution', value=TypedListProperty(name="size")), 'weight': Option(class_name='Convolution', value=ParameterProperty(name="weight")), 'bias': Option(class_name='ParameterBasedLayer', value=ParameterProperty(name="bias")), 'padding': Option(class_name='Convolution', value=PaddingProperty(name="padding")), 'stride': Option(class_name='Convolution', value=Spatial2DProperty(name="stride"))}[source]
output(input_value)[source]

Return output base on the input value.

Parameters:input_value
output_shape_per_dim(*args, **kwargs)[source]
weight_shape[source]