Keras Locally-connected Layers

LocallyConnected1D

The locally connected layer works for 1D inputs, which works same as that of the Conv1D layer, just the fact that weights aren't shared rather it applies a set of distinct filters at different input patches.

Example

Arguments

  • filters: It refers to an integer that depicts the output space dimensionality or the number of output filters present in the convolution.
  • kernel_size: It refers to an integer or tuple/list of an individual integer that specifies the length of a 1D convolution window.
  • strides: It can be defined as an integer or tuple/list of an individual integer that specifies the stride length of the convolution. Determining any stride value != 1 is incompatible with specifying any dilation_rate value != 1.
  • padding: As of now, it supports "valid", which is case-sensitive, but in the future, it may also support the "same".
  • data_format: It refers to a string one of channels_last, channels_first.
  • activation: It is an activation function to be used. When nothing is specified, then by defaults, it is a linear activation a(x)= x, or we can say no activation function is applied.
  • use_bias: It represents a Boolean that shows whether the layer utilizes a bias vector.
  • kernel_initializer: It can be defined as an initializer for the kernel weights matrix.
  • bias_initializer: It refers to an initializer for bias vector.
  • kernel_regularizer: It describes a regularizer function, which is implemented on the kernel weights matrix.
  • bias_regularizer: It can be defined as the regularizer function, which is applied to the bias vector.
  • activity_regularizer: It refers to the regularizer function that is applied to the activation (i.e., the output of the layer).
  • kernel_constraint: It indicates a constraint function that is implemented on the kernel matrix.
  • bias_constraint: It describes a constraint function, which is applied to the bias vector.

Input shape

It is a 3D tensor of shape (batch, steps, input_dim).

Output shape

The output shape is a 3D tensor of shape (batch, new_steps, filters) steps. The values might differ due to strides and padding.

LocallyConnected2D

It is a locally connected layer for 2D inputs, which works same as that of the Conv1D layer, just the fact that weights aren't shared rather it applies a set of distinct filters at different input patches.

Example

Arguments

  • filter: Filter describes an integer that signifies the output space dimensionality or a total number of output filters present in a convolution.
  • kernel_size: It can either be an integer or tuple/list of 2 integers to represent the height and width of a 2D convolution window. It can also exist as a single integer that signifies the same value for rest all of the spatial domain.
  • strides: It is either an integer or a tuple/list of 2 integers that represents the convolution strides along with height and width. It may exist as a single integer that specifies the same value for the spatial dimension.
  • padding: As of now, it supports "valid", which is case-sensitive, but in the future, it may also support the "same".
  • data_format: It is a string of "channels_last" or "channels_first", which represent the order of input dimensions. Here the "channels_last" relates to the input shape (batch, height, width, channels), and the "channels_first" relates to the input shape (batch, channels, height, width). It defaults to the image_data_format value that is found in Keras config at ~/.keras/keras.json. If you cannot find it in that folder, then it is residing at "channels_last".
  • activation: It is an activation function to be used. When nothing is specified, then by default, it is a linear activation a(x)= x, or we can say no activation function is applied.
  • use_bias: It represents a Boolean that shows whether the layer utilizes a bias vector.
  • kernel_initializer: It can be defined as an initializer for the kernel weights matrix.
  • bias_initializer: It refers to an initializer for bias vector.
  • kernel_regularizer: It describes a regularizer function, which is implemented on the kernel weights matrix.
  • bias_regularizer: It can be defined as the regularizer function, which is applied to the bias vector.
  • activity_regularizer: It refers to the regularizer function that is applied to the activation (i.e., the output of the layer).
  • kernel_constraint: It indicates a constraint function that is implemented on the kernel matrix.
  • bias_constraint: It describes a constraint function, which is applied to the bias vector.

Input shape

If the data_format is "channels_first", then the input shape of a 4D tensor is (samples, channels, rows, cols), else if data_format is "channels_last," the input shape of a 4D tensor is (samples, rows, cols, channels).

Output shape

If the data_format is "channels_first", the output shape of a 4D tensor will be (samples, filters, new_rows, new_cols), else if the data_format is "channels_last" the output will be (samples, new_rows, new_cols, filters). The values of rows and cols might change due to the effect of padding.






Latest Courses