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 filter upsampling. When dilation > 1 layer will become dilated 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 name. Can be used as a reference to specific layer. Name Can be specified as:

  • String: Specified name will be used as a direct reference to the layer. For example, name=”fc”
  • Format string: Name pattern could be defined as a format string and specified field will be replaced with an index. For example, name=”fc{}” will be replaced with fc1, fc2 and so on. A bit more complex formatting methods are acceptable, for example, name=”fc-{:<03d}” will be converted to fc-001, fc-002, fc-003 and so on.
  • None: When value specified as None than name will be generated from the class name.

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.layers import *
>>> network = join(
...     Input((30, 10)),
...     Reshape((30, 1, 10)),  # convert 3D to 4D
...     Convolution((3, 1, 16)),
...     Reshape((-1, 16))  # convert 4D back to 3D
... )
>>> network
(?, 30, 10) -> [... 4 layers ...] -> (?, 28, 16)
variables : dict

Variable names and their values. Dictionary can be empty in case if variables hasn’t been created yet.


variable(value, name, shape=None, trainable=True) Initializes variable with specified values.
get_output_shape(input_shape) Computes expected output shape from the layer based on the specified input shape.
output(*inputs, **kwargs) Propagates input through the layer. The kwargs variable might contain additional information that propagates through the network.
bias = None[source]
dilation = None[source]
options = {'bias': Option(class_name='Convolution', 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]
output(input, **kwargs)[source]
output_shape_per_dim(*args, **kwargs)[source]
padding = None[source]
size = None[source]
stride = None[source]
weight = None[source]