Shortcuts

Conformer

class torcheeg.models.Conformer(num_electrodes: int = 62, sampling_rate: int = 200, embed_dropout: float = 0.5, hid_channels: int = 40, depth: int = 6, heads: int = 10, dropout: float = 0.5, forward_expansion: int = 4, forward_dropout: float = 0.5, cls_channels: int = 32, cls_dropout: float = 0.5, num_classes: int = 2)[source][source]

The EEG Conformer model is based on the paper “EEG Conformer: Convolutional Transformer for EEG Decoding and Visualization”. For more details, please refer to the following information.

Below is a recommended suite for use in emotion recognition tasks:

from torcheeg.models import Conformer
from torcheeg.datasets import SEEDDataset
from torcheeg import transforms
from torch.utils.data import DataLoader

dataset = SEEDDataset(root_path='./Preprocessed_EEG',
                      offline_transform=transforms.Compose([
                          transforms.MinMaxNormalize(axis=-1),
                          transforms.To2d()
                      ]),
                      online_transform=transforms.ToTensor(),
                      label_transform=transforms.Compose([
                          transforms.Select('emotion'),
                          transforms.Lambda(lambda x: x + 1)
                      ]))

model = Conformer(num_electrodes=62,
                  sampling_rate=200,
                  hid_channels=40,
                  depth=6,
                  heads=10,
                  dropout=0.5,
                  forward_expansion=4,
                  forward_dropout=0.5,
                  num_classes=2)

x, y = next(iter(DataLoader(dataset, batch_size=64)))
model(x)
Parameters:
  • num_electrodes (int) – The number of electrodes. (default: 62)

  • sampling_rate (int) – The sampling rate of EEG signals. (default: 200)

  • hid_channels (int) – The feature dimension of embeded patch. (default: 40)

  • depth (int) – The number of attention layers for each transformer block. (default: 6)

  • heads (int) – The number of attention heads for each attention layer. (default: 10)

  • dropout (float) – The dropout rate of the attention layer. (default: 0.5)

  • forward_expansion (int) – The expansion factor of the feedforward layer. (default: 4)

  • forward_dropout (float) – The dropout rate of the feedforward layer. (default: 0.5)

  • num_classes (int) – The number of classes. (default: 2)

forward(x: Tensor) Tensor[source][source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources