@frozen
public struct Conv2D<Scalar> : Layer where Scalar : TensorFlowFloatingPoint
A 2-D convolution layer (e.g. spatial convolution over images).
This layer creates a convolution filter that is convolved with the layer input to produce a tensor of outputs.
-
The 4-D convolution filter.
Declaration
public var filter: Tensor<Scalar>
-
The bias vector.
Declaration
public var bias: Tensor<Scalar>
-
The element-wise activation function.
Declaration
@noDerivative public let activation: Activation
-
The strides of the sliding window for spatial dimensions.
Declaration
@noDerivative public let strides: (Int, Int)
-
The padding algorithm for convolution.
Declaration
@noDerivative public let padding: Padding
-
The dilation factor for spatial dimensions.
Declaration
@noDerivative public let dilations: (Int, Int)
-
Creates a
Conv2D
layer with the specified filter, bias, activation function, strides, dilations and padding.Declaration
public init( filter: Tensor<Scalar>, bias: Tensor<Scalar>? = nil, activation: @escaping Activation = identity, strides: (Int, Int) = (1, 1), padding: Padding = .valid, dilations: (Int, Int) = (1, 1) )
Parameters
filter
The 4-D convolution filter of shape [filter height, filter width, input channel count, output channel count].
bias
The bias vector of shape [output channel count].
activation
The element-wise activation function.
strides
The strides of the sliding window for spatial dimensions, i.e. (stride height, stride width).
padding
The padding algorithm for convolution.
dilations
The dilation factors for spatial dimensions, i.e. (dilation height, dilation width).
-
Returns the output obtained from applying the layer to the given input.
The output spatial dimensions are computed as:
output height = (input height + 2 * padding height - (dilation height * (filter height - 1) + 1)) / stride height + 1
output width = (input width + 2 * padding width - (dilation width * (filter width - 1) + 1)) / stride width + 1
and padding sizes are determined by the padding scheme.
Note
Padding size equals zero when using
.valid
.Parameters
input
The input to the layer of shape [batch size, input height, input width, input channel count].
Return Value
The output of shape [batch count, output height, output width, output channel count].
-
Creates a
Conv2D
layer with the specified filter shape, strides, padding, dilations and element-wise activation function.Declaration
public init( filterShape: (Int, Int, Int, Int), strides: (Int, Int) = (1, 1), padding: Padding = .valid, dilations: (Int, Int) = (1, 1), activation: @escaping Activation = identity, useBias: Bool = true, filterInitializer: ParameterInitializer<Scalar> = glorotUniform(), biasInitializer: ParameterInitializer<Scalar> = zeros() )
Parameters
filterShape
The shape of the 4-D convolution filter, representing (filter height, filter width, input channel count, output channel count).
strides
The strides of the sliding window for spatial dimensions, i.e. (stride height, stride width).
padding
The padding algorithm for convolution.
dilations
The dilation factors for spatial dimensions, i.e. (dilation height, dilation width).
activation
The element-wise activation function.
filterInitializer
Initializer to use for the filter parameters.
biasInitializer
Initializer to use for the bias parameters.