public struct Conv1D<Scalar> : Layer where Scalar : TensorFlowFloatingPoint

A 1-D convolution layer (e.g. temporal convolution over a time-series).

This layer creates a convolution filter that is convolved with the layer input to produce a tensor of outputs.

  • The 3-D convolution kernel [width, inputChannels, outputChannels].

    Declaration

    public var filter: Tensor<Scalar>
  • The bias vector [outputChannels].

    Declaration

    public var bias: Tensor<Scalar>
  • An activation function.

    Declaration

    public typealias Activation = (Tensor<Scalar>) -> Tensor<Scalar>
  • The element-wise activation function.

    Declaration

    public let activation: Activation
  • The stride of the sliding window for temporal dimension.

    Declaration

    public let stride: Int
  • The padding algorithm for convolution.

    Declaration

    public let padding: Padding
  • Creates a Conv1D layer with the specified filter, bias, activation function, stride, and padding.

    Declaration

    public init(
        filter: Tensor<Scalar>,
        bias: Tensor<Scalar>,
        activation: @escaping Activation,
        stride: Int,
        padding: Padding
    )

    Parameters

    filter

    The 3-D convolution kernel [width, inputChannels, outputChannels].

    bias

    The bias vector [outputChannels].

    activation

    The element-wise activation function.

    stride

    The stride of the sliding window for temporal dimension.

    padding

    The padding algorithm for convolution.

  • Returns the output obtained from applying the layer to the given input.

    Declaration

    public func call(_ input: Tensor<Scalar>) -> Tensor<Scalar>

    Parameters

    input

    The input to the layer [batchCount, width, inputChannels].

    Return Value

    The output [batchCount, newWidth, outputChannels].

  • Creates a Conv1D layer with the specified filter shape, stride, padding, and element-wise activation function. The filter tensor is initialized using Glorot uniform initialization with the specified generator. The bias vector is initialized with zeros.

    Note

    Use init(filterShape:stride:padding:activation:seed:) for faster random initialization.

    Declaration

    init<G: RandomNumberGenerator>(
        filterShape: (Int, Int, Int),
        stride: Int = 1,
        padding: Padding = .valid,
        activation: @escaping Activation = identity,
        generator: inout G
    )

    Parameters

    filterShape

    The 3-D shape of the filter, representing [width, inputChannels, outputChannels].

    stride

    The stride of the sliding window for temporal dimension.

    padding

    The padding algorithm for convolution.

    activation

    The element-wise activation function.

    generator

    The random number generator for initialization.

  • Creates a Conv1D layer with the specified filter shape, strides, padding, and element-wise activation function. The filter tensor is initialized using Glorot uniform initialization with the specified seed. The bias vector is initialized with zeros.

    Declaration

    init(
        filterShape: (Int, Int, Int),
        stride: Int = 1,
        padding: Padding = .valid,
        activation: @escaping Activation = identity,
        seed: (Int64, Int64) = (Int64.random(in: Int64.min..<Int64.max),
                                Int64.random(in: Int64.min..<Int64.max))
    )

    Parameters

    filterShape

    The 3-D shape of the filter, representing [width, inputChannels, outputChannels].

    stride

    The stride of the sliding window for temporal dimension.

    padding

    The padding algorithm for convolution.

    activation

    The element-wise activation function.

    seed

    The random seed for initialization. The default value is random.