CNNEmbedding

CNNEmbedding#

class CNNEmbedding(input_shape, in_channels=1, out_channels_per_layer=None, num_conv_layers=2, num_linear_layers=2, num_linear_units=50, output_dim=20, kernel_size=5, pool_kernel_size=2)[source]#

Bases: Module

Convolutional embedding network with channel-first 1D or 2D inputs.

Parameters:
  • input_shape (Tuple)

  • in_channels (int)

  • out_channels_per_layer (List | None)

  • num_conv_layers (int)

  • num_linear_layers (int)

  • num_linear_units (int)

  • output_dim (int)

  • kernel_size (int)

  • pool_kernel_size (int)

forward(x)[source]#

Embed a batch of inputs.

Parameters:

x (Tensor) – Inputs of shape (batch_dim, in_channels, *input_shape). A flat (batch_dim, in_channels * prod(input_shape)) is also accepted, as is (batch_dim, *input_shape) when in_channels is 1.

Returns:

Embeddings of shape (batch_dim, output_dim).

Raises:

ValueError – If the trailing shape of x is none of the above.

Return type:

Tensor