class neupy.layers.Convolution[source]

Convolutional layer.

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.


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)),
... )
input_shape : tuple

Returns layer’s input shape in the form of a tuple. Shape will not include batch size dimension.

output_shape : tuple

Returns layer’s output shape in the form of a tuple. Shape will not include batch size dimension.

training_state : bool

Defines whether layer in training state or not. Training state will enable some operations inside of the layers that won’t work otherwise.

parameters : dict

Parameters that networks uses during propagation. It might include trainable and non-trainable parameters.

graph : LayerGraph instance

Graphs that stores all relations between layers.


disable_training_state() Context manager that switches off trainig state.
initialize() Set up important configurations related to the layer.
dilation = None[source]
options = {'bias': Option(class_name='ParameterBasedLayer', value=ParameterProperty(name="bias")), 'dilation': Option(class_name='Convolution', value=Spatial2DProperty(name="dilation")), 'name': Option(class_name='BaseLayer', value=Property(name="name")), 'padding': Option(class_name='Convolution', value=PaddingProperty(name="padding")), 'size': Option(class_name='Convolution', value=TypedListProperty(name="size")), 'stride': Option(class_name='Convolution', value=Spatial2DProperty(name="stride")), 'weight': Option(class_name='Convolution', value=ParameterProperty(name="weight"))}[source]

Return output base on the input value.

output_shape_per_dim(*args, **kwargs)[source]
padding = None[source]
size = None[source]
stride = None[source]

Validate input shape value before assigning it.

input_shape : tuple with int
weight = None[source]