braindecode.models.CTNet#

class braindecode.models.CTNet(n_outputs=None, n_chans=None, sfreq=None, chs_info=None, n_times=None, input_window_seconds=None, activation_patch=<class 'torch.nn.modules.activation.ELU'>, activation_transformer=<class 'torch.nn.modules.activation.GELU'>, drop_prob_cnn=0.3, drop_prob_posi=0.1, drop_prob_final=0.5, heads=4, emb_size=40, depth=6, n_filters_time=None, kernel_size=64, depth_multiplier=2, pool_size_1=8, pool_size_2=8)[source]#

CTNet from Zhao, W et al (2024) [ctnet].

A Convolutional Transformer Network for EEG-Based Motor Imagery Classification

CTNet Architecture

CTNet is an end-to-end neural network architecture designed for classifying motor imagery (MI) tasks from EEG signals. The model combines convolutional neural networks (CNNs) with a Transformer encoder to capture both local and global temporal dependencies in the EEG data.

The architecture consists of three main components:

  1. Convolutional Module:
    • Apply EEGNet to perform some feature extraction, denoted here as

    _PatchEmbeddingEEGNet module.

  2. Transformer Encoder Module:
    • Utilizes multi-head self-attention mechanisms as EEGConformer but

    with residual blocks.

  3. Classifier Module:
    • Combines features from both the convolutional module

    and the Transformer encoder. - Flattens the combined features and applies dropout for regularization. - Uses a fully connected layer to produce the final classification output.

Parameters:
  • n_outputs (int) – Number of outputs of the model. This is the number of classes in the case of classification.

  • n_chans (int) – Number of EEG channels.

  • sfreq (float) – Sampling frequency of the EEG recordings.

  • chs_info (list of dict) – Information about each individual EEG channel. This should be filled with info["chs"]. Refer to mne.Info for more details.

  • n_times (int) – Number of time samples of the input window.

  • input_window_seconds (float) – Length of the input window in seconds.

  • activation_patch (Module) – The description is missing.

  • activation_transformer (Module) – The description is missing.

  • drop_prob_cnn (float, default=0.3) – Dropout probability after convolutional layers.

  • drop_prob_posi (float, default=0.1) – Dropout probability for the positional encoding in the Transformer.

  • drop_prob_final (float, default=0.5) – Dropout probability before the final classification layer.

  • heads (int, default=4) – Number of attention heads in the Transformer encoder.

  • emb_size (int or None, default=None) – Embedding size (dimensionality) for the Transformer encoder.

  • depth (int, default=6) – Number of encoder layers in the Transformer.

  • n_filters_time (int, default=20) – Number of temporal filters in the first convolutional layer.

  • kernel_size (int, default=64) – Kernel size for the temporal convolutional layer.

  • depth_multiplier (int, default=2) – Multiplier for the number of depth-wise convolutional filters.

  • pool_size_1 (int, default=8) – Pooling size for the first average pooling layer.

  • pool_size_2 (int, default=8) – Pooling size for the second average pooling layer.

Raises:

ValueError – If some input signal-related parameters are not specified: and can not be inferred.

Notes

This implementation is adapted from the original CTNet source code [ctnetcode] to comply with Braindecode’s model standards.

References

[ctnet]

Zhao, W., Jiang, X., Zhang, B., Xiao, S., & Weng, S. (2024). CTNet: a convolutional transformer network for EEG-based motor imagery classification. Scientific Reports, 14(1), 20237.

[ctnetcode]

Zhao, W., Jiang, X., Zhang, B., Xiao, S., & Weng, S. (2024). CTNet source code: snailpt/CTNet

Methods

forward(x)[source]#

Forward pass of the CTNet model.

Parameters:

x (Tensor) – Input tensor of shape (batch_size, n_channels, n_times).

Returns:

Output with shape (batch_size, n_outputs).

Return type:

Tensor