EEGNet

class selfeeg.models.zoo.EEGNet(nb_classes: int, Chans: int, Samples: int, kernLength: int = 64, dropRate: float = 0.5, F1: int = 8, D: int = 2, F2: int = 16, norm_rate: int = 0.25, dropType: str = 'Dropout', ELUalpha: int = 1, pool1: int = 4, pool2: int = 8, separable_kernel: int = 16, depthwise_max_norm: float = 1.0, return_logits: bool = True, seed: int = None)[source]

Pytorch implementation of the EEGNet model.

For more information see the following paper [EEGnet] . Keras implementation of the full EEGnet (updated version), more info can be found here [eegnetgit] .

The expected input is a 3D tensor with size (Batch x Channels x Samples).

Parameters:
  • nb_classes (int) – The number of classes. If less than 2, a binary classification problem is considered (output dimensions will be [batch, 1] in this case).

  • Chans (int) – The number of EEG channels.

  • Samples (int) – The sample length. It will be used to calculate the embedding size (for head initialization).

  • kernlength (int, optional) –

    The length of the temporal convolutional layer.

    Default = 64

  • dropRate (float, optional) –

    The dropout percentage in range [0,1].

    Default = 0.5

  • F1 (int, optional) –

    The number of filters in the first layer.

    Default = 8

  • D (int, optional) –

    The depth of the depthwise convolutional layer.

    Default = 16

  • dropType (str, optional) –

    The type of dropout. It can be either ‘Dropout’ or ‘SpatialDropout2D’.

    Default = ‘Dropout’

  • ELUalpha (float, optional) –

    The alpha value of the ELU activation function.

    Default = 1

  • pool1 (int, optional) –

    The first temporal average pooling kernel size.

    Default = 4

  • pool2 (int, optional) –

    The second temporal average pooling kernel size.

    Default = 8

  • separable_kernel (int, optional) –

    The temporal separable conv layer kernel size.

    Default = 16

  • depthwise_max_norm (float, optional) –

    The maximum norm each filter can have in the depthwise block. If None no constraint will be included.

    Default = None

  • return_logits (bool, optional) –

    Whether to return the output as logit or probability. It is suggested to not use False as the pytorch crossentropy loss function applies the softmax internally.

    Default = True

  • seed (int, optional) –

    A custom seed for model initialization. It must be a nonnegative number. If None is passed, no custom seed will be set

    Default = None

Note

This implementation refers to the latest version of EEGNet which can be found in the official repository (see references).

References

[EEGnet]

Lawhern et al., EEGNet: a compact convolutional neural network for EEG-based brain–computer interfaces. Journal of Neural Engineering. 2018

Example

>>> import selfeeg.models
>>> import torch
>>> x = torch.randn(4,8,64)
>>> mdl = models.EEGNet(4,8,64)
>>> out = mdl(x)
>>> print(out.shape) # shoud return torch.Size([4, 4])
>>> print(torch.isnan(out).sum()) # shoud return 0