DeepConvNet

class selfeeg.models.zoo.DeepConvNet(nb_classes: int, Chans: int, Samples: int, kernLength: int = 10, F: int = 25, Pool: int = 3, stride: int = 3, max_norm: int = None, batch_momentum: float = 0.1, ELUalpha: int = 1, dropRate: float = 0.5, max_dense_norm: float = None, return_logits: bool = True, seed: int = None)[source]

Pytorch Implementation of the DeepConvNet model.

Official paper can be found here [deepconv] . A Keras implementation can be found here [deepconvgit] .

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 = 10

  • F (int, optional) –

    The number of filters in the first layer. Next layers will continue to double the previous output.

    Default = 25

  • Pool (int, optional) –

    The temporal pooling kernel size.

    Default = 3

  • stride (int, optional) –

    The stride to apply to the convolutional layers.

    Default = 3

  • max_norm (int, optional) –

    A max norm constraint to apply to each filter of the convolutional layer. See ConstrainedConv2d for more info.

    Default = None

  • batch_momentum (float, optional) –

    The batch normalization momentum.

    Default = 0.9

  • ELUalpha (float, optional) –

    The alpha value of the ELU activation function.

    Default = 1

  • dropRate (float, optional) –

    The dropout percentage in range [0,1].

    Default = 0.5

  • max_dense_norm (int, optional) –

    A max norm constraint to apply to the DenseLayer. See ConstrainedDense for more info.

    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 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 original implementation of DeepConvNet. So, no max norm constraints were applied on the network layers.

References

[deepconv]

Schirrmeister, Robin Tibor, et al. “Deep learning with convolutional neural networks for EEG decoding and visualization.” Human brain mapping 38.11 (2017): 5391-5420. https://onlinelibrary.wiley.com/doi/pdfdirect/10.1002/hbm.23730

Example

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