EEGSym
- class selfeeg.models.zoo.EEGSym(nb_classes: int, Chans: int, Samples: int, Fs: int, scales_time: tuple = (500, 250, 125), lateral_chans: int = 3, first_left: bool = True, F: int = 8, pool: int = 2, dropRate: float = 0.5, ELUalpha: float = 1.0, bias: bool = True, residual: bool = True, return_logits: bool = True, seed: int = None)[source]
Pytorch implementation of the EEGSym model.
EEGSym paper can be found here [eegsym] . Keras implementation can be found here [eegsymgit] .
The expected input is a 3D tensor with size (Batch x Channels x Samples). However Channel order is expected to be symmetrical along lateral channels to perform the reshaping operation correctly. For instance, if the first channel index refers to the FP1 channel, then the last must refer to the other hemisphere counterpart, i.e. FP2.
- 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 number of EEG Samples.
Fs (float) – The sampling frequency.
scales_time (tuple of 3 float, optional) –
The portion of EEG (in milliseconds) the short, medium and long temporal convolutional layers must cover. kernel size will be automatically calculated based on the sampling rate given.
Default = (500,250,125)
lateral_chans (int, optional) –
The amount of lateral channels. It will be used to reshape the 3D tensor in a 5D tensor with size ( batch x filters x hemisphere x channel x samples ). See the original paper for more info.
Default = 3
first_left (bool, optional) –
Whether the first half of the channels are of the left hemisphere or not.
Default = True
F (int, optional) –
The output filters of each branch of the first inception block. Must be a multiple of 8. Other outputs will be automatically calculated.
Default = 8
pool (int, optional) –
The size of the pooling kernel.
Default = 2
dropRate (float, optional) –
The dropout percentage in range [0,1].
Default = 0.5
bias (bool, optional) –
If True, adds a learnable bias to the convolutional layers.
Default = True
residual (bool, optional) –
Whether to add a residual block after the inception block. Currently not implemented, will be added in future releases.
Default = True
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
References
Example
>>> import selfeeg.models >>> import torch >>> x = torch.randn(4,8,1024) >>> mdl = models.EEGSym(4,8,1024,64) >>> out = mdl(x) >>> print(out.shape) # shoud return torch.Size([4, 4]) >>> print(torch.isnan(out).sum()) # shoud return 0