Convolution layers¶
-
class
dynn.layers.convolution_layers.
Conv1D
(pc, input_dim, num_kernels, kernel_width, activation=<function identity>, dropout_rate=0.0, nobias=False, zero_padded=True, stride=1, K=None, b=None)¶ Bases:
dynn.layers.base_layers.ParametrizedLayer
1D convolution along the first dimension
Parameters: - pc (
dynet.ParameterCollection
) – Parameter collection to hold the parameters - input_dim (int) – Input dimension
- num_kernels (int) – Number of kernels (essentially the output dimension)
- kernel_width (int) – Width of the kernels
- activation (function, optional) – activation function
(default:
identity
) - dropout (float, optional) – Dropout rate (default 0)
- nobias (bool, optional) – Omit the bias (default
False
) - zero_padded (bool, optional) – Default padding behaviour. Pad
the input with zeros so that the output has the same length
(default
True
) - stride (list, optional) – Default stride along the length
(defaults to
1
).
-
__call__
(x, stride=None, zero_padded=None)¶ Forward pass
Parameters: - x (
dynet.Expression
) – Input expression with the shape (length, input_dim) - stride (int, optional) – Stride along the temporal dimension
- zero_padded (bool, optional) – Pad the image with zeros so that the
output has the same length (default
True
)
Returns: Convolved sequence.
Return type: - x (
-
__init__
(pc, input_dim, num_kernels, kernel_width, activation=<function identity>, dropout_rate=0.0, nobias=False, zero_padded=True, stride=1, K=None, b=None)¶ Creates a subcollection for this layer with a custom name
- pc (
-
class
dynn.layers.convolution_layers.
Conv2D
(pc, num_channels, num_kernels, kernel_size, activation=<function identity>, dropout_rate=0.0, nobias=False, zero_padded=True, strides=None, K=None, b=None)¶ Bases:
dynn.layers.base_layers.ParametrizedLayer
2D convolution
Parameters: - pc (
dynet.ParameterCollection
) – Parameter collection to hold the parameters - num_channels (int) – Number of channels in the input image
- num_kernels (int) – Number of kernels (essentially the output dimension)
- kernel_size (list, optional) – Default kernel size. This is a list of two elements, one per dimension.
- activation (function, optional) – activation function
(default:
identity
) - dropout (float, optional) – Dropout rate (default 0)
- nobias (bool, optional) – Omit the bias (default
False
) - zero_padded (bool, optional) – Default padding behaviour. Pad
the image with zeros so that the output has the same width/height
(default
True
) - strides (list, optional) – Default stride along each dimension
(list of size 2, defaults to
[1, 1]
).
-
__call__
(x, strides=None, zero_padded=None)¶ Forward pass
Parameters: - x (
dynet.Expression
) – Input image (3-d tensor) or matrix. - zero_padded (bool, optional) – Pad the image with zeros so that the output has the same width/height. If this is not specified, the default specified in the constructor is used.
- strides (list, optional) – Stride along width/height. If this is not specified, the default specified in the constructor is used.
Returns: Convolved image.
Return type: - x (
-
__init__
(pc, num_channels, num_kernels, kernel_size, activation=<function identity>, dropout_rate=0.0, nobias=False, zero_padded=True, strides=None, K=None, b=None)¶ Creates a subcollection for this layer with a custom name
- pc (