braindecode.models.EEGNeX#

class braindecode.models.EEGNeX(n_chans=None, n_outputs=None, n_times=None, chs_info=None, input_window_seconds=None, sfreq=None, activation: ~torch.nn.modules.module.Module = <class 'torch.nn.modules.activation.ELU'>, depth_multiplier: int = 2, filter_1: int = 8, filter_2: int = 32, drop_rate: float = 0.5, kernel_block_4: tuple[int, int] = (1, 16), dilation_block_4: tuple[int, int] = (1, 2), avg_pool_block4: tuple[int, int] = (1, 4), kernel_block_5: tuple[int, int] = (1, 16), dilation_block_5: tuple[int, int] = (1, 4), avg_pool_block5: tuple[int, int] = (1, 8))[source]#

EEGNeX model from Chen et al. (2024) [eegnex].

Parameters:
  • n_chans (int) – Number of EEG channels.

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

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

  • 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.

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

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

  • activation (nn.Module, optional) – Activation function to use. Default is nn.ELU.

  • depth_multiplier (int, optional) – Depth multiplier for the depthwise convolution. Default is 2.

  • filter_1 (int, optional) – Number of filters in the first convolutional layer. Default is 8.

  • filter_2 (int, optional) – Number of filters in the second convolutional layer. Default is 32.

  • drop_rate (float, optional) – Dropout rate. Default is 0.5.

  • kernel_block_4 (tuple[int, int], optional) – Kernel size for block 4. Default is (1, 16).

  • dilation_block_4 (tuple[int, int], optional) – Dilation rate for block 4. Default is (1, 2).

  • avg_pool_block4 (tuple[int, int], optional) – Pooling size for block 4. Default is (1, 4).

  • kernel_block_5 (tuple[int, int], optional) – Kernel size for block 5. Default is (1, 16).

  • dilation_block_5 (tuple[int, int], optional) – Dilation rate for block 5. Default is (1, 4).

  • avg_pool_block5 (tuple[int, int], optional) – Pooling size for block 5. Default is (1, 8).

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

  • FutureWarning – If add_log_softmax is True, since LogSoftmax final layer: will be removed in the future.

Notes

This implementation is not guaranteed to be correct, has not been checked by original authors, only reimplemented from the paper description and source code in tensorflow [EEGNexCode].

References

[eegnex]

Chen, X., Teng, X., Chen, H., Pan, Y., & Geyer, P. (2024). Toward reliable signals decoding for electroencephalogram: A benchmark study to EEGNeX. Biomedical Signal Processing and Control, 87, 105475.

[EEGNexCode]

Chen, X., Teng, X., Chen, H., Pan, Y., & Geyer, P. (2024). Toward reliable signals decoding for electroencephalogram: A benchmark study to EEGNeX. chenxiachan/EEGNeX

Methods

static calc_padding(kernel_size: tuple[int, int], dilation: tuple[int, int]) tuple[int, int][source]#

Calculate padding size for ‘same’ convolution with dilation.

Parameters:
  • kernel_size (tuple) – Tuple containing the kernel size (height, width).

  • dilation (tuple) – Tuple containing the dilation rate (height, width).

Returns:

Padding sizes (padding_height, padding_width).

Return type:

tuple

forward(x: Tensor) Tensor[source]#

Forward pass of the EEGNeX model.

Parameters:

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

Returns:

Output tensor of shape (batch_size, n_outputs).

Return type:

torch.Tensor