eegproc.deep_learning.unsupervised.Convolutions.CNN1D module

class eegproc.deep_learning.unsupervised.Convolutions.CNN1D.CNN1DDecoder(timesteps, n_features, t_down, conv_filters, kernel_sizes, pool_after_layers, pool_sizes, emb_dim, dropout=0.1, activation='relu', use_batch_norm=True, name='decoder_mirror', **kwargs)[source]

Bases: Model

Mirror decoder for CNN1DEncoder.

This decoder expects a latent sequence of shape (batch, ceil(timesteps / t_down), emb_dim) and reconstructs a sequence of shape (batch, timesteps, n_features).

The decoder mirrors the encoder by reversing the convolutional filter schedule and replacing temporal pooling with temporal upsampling.

Parameters:
  • timesteps (int)

  • n_features (int)

  • t_down (int)

  • conv_filters (tuple[int, ...])

  • kernel_sizes (int | tuple[int, ...])

  • pool_after_layers (tuple[int, ...])

  • pool_sizes (int | tuple[int, ...])

  • emb_dim (int)

  • dropout (float, default: 0.1)

  • activation (str, default: 'relu')

  • use_batch_norm (bool, default: True)

  • name (str, default: 'decoder_mirror')

call(inputs, training=False)[source]
Parameters:

training (bool, default: False)

compute_output_shape(input_shape)[source]

Return the decoder output shape.

fix_length(x)[source]

Trim or pad sequence to exactly timesteps.

Parameters:

x (Tensor)

Return type:

Tensor

classmethod from_encoder(encoder, name='decoder_mirror')[source]

Create a mirror decoder from a configured CNN1DEncoder.

Parameters:

name (str, default: 'decoder_mirror')

get_config()[source]

Return serializable configuration for the decoder.

Return type:

dict

property n_features: int

Flattened number of reconstructed channel-band features.

class eegproc.deep_learning.unsupervised.Convolutions.CNN1D.CNN1DEncoder(timesteps, n_features, t_down, conv_filters=(64, 128, 256), kernel_sizes=(7, 5, 3), pool_after_layers=None, pool_sizes=None, emb_dim=128, dropout=0.1, activation='relu', use_batch_norm=True, name='encoder_1dcnn', **kwargs)[source]

Bases: BaseEncoder

Configurable-depth 1D convolutional encoder for EEG sequence data.

This encoder treats each timestep’s feature vector as a flat representation and learns temporal patterns using a designer-defined stack of Conv1D layers.

The number of convolutional layers is determined by len(conv_filters). Temporal downsampling is controlled by pool_after_layers and pool_sizes. The product of the pooling sizes must equal t_down.

Parameters:
  • timesteps (int) – Number of timesteps in each input sequence.

  • n_features (int) – Number of features per timestep.

  • t_down (int) – Temporal downsampling factor.

  • conv_filters (tuple[int, ...], default: (64, 128, 256)) – Number of filters for each Conv1D layer. The length of this tuple defines the number of convolutional layers.

  • kernel_sizes (int | tuple[int, ...], default: (7, 5, 3)) – Kernel size for each Conv1D layer. If an int is given, the same kernel size is used for every layer.

  • pool_after_layers (tuple[int, ...] | None, default: None) – Zero-indexed convolutional layer indices after which MaxPool1D is applied. When both pooling arguments are omitted, one pooling operation with size t_down is placed after the first convolution.

  • pool_sizes (int | tuple[int, ...] | None, default: None) – Pool size for each pooling operation. If an int is given, the same pool size is used after every layer listed in pool_after_layers.

  • emb_dim (int, default: 128) – Dimensionality of the latent embedding at each output timestep.

  • dropout (float, default: 0.1) – Dropout rate applied after each convolutional block.

  • activation (str, default: 'relu') – Activation function used by convolutional layers.

  • use_batch_norm (bool, default: True) – Whether to apply batch normalization after each convolution.

  • name (str, default: 'encoder_1dcnn') – Name of the Keras model.

  • **kwargs – Additional keyword arguments passed to tf.keras.Model.

Notes

Inputs have shape (batch, timesteps, n_features); outputs have shape (batch, ceil(timesteps / t_down), emb_dim).

call(inputs, training=False)[source]

Run the configurable-depth 1D CNN encoder forward pass.

Parameters:

training (bool, default: False)

get_config()[source]

Return serializable configuration for the encoder.

Return type:

dict

property n_features: int

Number of input features per timestep.