TinySleepNet

class selfeeg.models.zoo.TinySleepNet(nb_classes: int, Chans: int, Fs: int, F: int = 128, kernlength: int = 8, pool: int = 8, dropRate: float = 0.5, batch_momentum: float = 0.1, max_dense_norm: float = 2.0, hidden_lstm: int = 128, return_logits: bool = True, seed: int = None)[source]

Pytorch Implementation of the TinySleepNet model.

TinySleepNet is a minimal but better performing architecture derived from DeepSleepNet (proposed by the same authors). Paper can be found here [tiny] . Github repo can be found here [tinygit] .

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.

  • Fs (float) – The EEG sampling frequency in Hz.

  • F1 (int, optional) –

    The number of output filters in the representation learning part.

    Default = 128

  • kernlength (int, optional) –

    The length of the temporal convolutional layer.

    Default = 8

  • pool (int, optional) –

    The temporal pooling kernel size.

    Default = 8

  • dropRate (float, optional) –

    The dropout percentage in range [0,1].

    Default = 0.5

  • batch_momentum (float, optional) –

    The batch normalization momentum.

    Default = 0.9

  • max_dense_norm (float, optional) –

    A value indicating the max norm constraint to apply on the final dense layer. If None no constraint will be included.

    Default = 1.

  • hidden_lstm (int, optional) –

    Hidden size of the lstm block.

    Default = 128

  • 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

[tiny]

Supratak, Akara, and Yike Guo. “TinySleepNet: An efficient deep learning model for sleep stage scoring based on raw single-channel EEG.” 2020 42nd Annual International Conference of the IEEE Engineering in Medicine & Biology Society (EMBC). IEEE, 2020. https://ieeexplore.ieee.org/abstract/document/9176741

Example

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