Shortcuts

FACEDFeatureDataset

class torcheeg.datasets.FACEDFeatureDataset(root_path: str = './EEG_Features/DE', num_channel: int = 30, online_transform: None | Callable = None, offline_transform: None | Callable = None, label_transform: None | Callable = None, before_trial: None | Callable = None, after_trial: None | Callable = None, after_subject: None | Callable = None, io_path: None | str = None, io_size: int = 1048576, io_mode: str = 'lmdb', num_worker: int = 0, verbose: bool = True)[source][source]

The FACED dataset was provided by the Tsinghua Laboratory of Brain and Intelligence. The Finer-grained Affective Computing EEG Dataset (FACED) recorded 32-channel EEG signals from 123 subjects. During the experiment, subjects watched 28 emotion-elicitation video clips covering nine emotion categories (amusement, inspiration, joy, tenderness; anger, fear, disgust, sadness, and neutral emotion), providing a fine-grained and balanced categorization on both the positive and negative sides of emotion. This class generates training samples and test samples according to the given parameters, and caches the generated results in a unified input and output format (IO). The relevant information of the dataset is as follows:

  • Author: Please refer to the downloaded URL.

  • Year: 2023

  • Download URL: https://www.synapse.org/#!Synapse:syn50614194/files/

  • Reference: Please refer to the downloaded URL.

  • Stimulus: video clips.

  • Signals: Electroencephalogram (30 channels at 250Hz) and two channels of left/right mastoid signals from 123 subjects.

  • Rating: 28 video clips are annotated in valence and discrete emotion dimensions. The valence is divided into positive (1), negative (-1), and neutral (0). Discrete emotions are divided into anger (0), disgust (1), fear (2), sadness (3), neutral (4), amusement (5), inspiration (6), joy (7), and tenderness (8).

In order to use this dataset, the download folder :obj:`EEG_Features`(download from this url: https://www.synapse.org/#!Synapse:syn52368847) is required, containing the following files:

EEG_Features/
├── DE/
│   ├── sub000.pkl.pkl  # will be renamed to sub000.pkl automatically
│   ├── sub001.pkl.pkl
│   ├── sub002.pkl.pkl
│   └── ...
└── PSD/
    ├── sub000.pkl.pkl
    └── ...

An example dataset for CNN-based methods:

from torcheeg.datasets import FACEDFeatureDataset
from torcheeg import transforms
from torcheeg.datasets.constants import FACED_CHANNEL_LOCATION_DICT

dataset = FACEDFeatureDataset(root_path='./EEG_Features/DE',
                               offline_transform=transforms.ToGrid(FACED_CHANNEL_LOCATION_DICT),
                               online_transform=transforms.ToTensor(),
                               label_transform=transforms.Select('emotion'))
print(dataset[0])
# EEG signal (torch.Tensor[5, 8, 9]),
# coresponding baseline signal (torch.Tensor[5, 8, 9]),
# label (int)

An example dataset for GNN-based methods:

from torcheeg.datasets import FACEDFeatureDataset
from torcheeg import transforms
from torcheeg.datasets.constants import FACED_ADJACENCY_MATRIX
from torcheeg.transforms.pyg import ToG

dataset = FACEDFeatureDataset(root_path='./EEG_Features/DE',
                               online_transform=ToG(FACED_ADJACENCY_MATRIX),
                               label_transform=transforms.Select('emotion'))
print(dataset[0])
# EEG signal (torch_geometric.data.Data),
# coresponding baseline signal (torch_geometric.data.Data),
# label (int)
Parameters:
  • root_path (str) – Downloaded data files in matlab (unzipped EEG_Features.zip) formats (default: './EEG_Features/DE', optional: './EEG_Features/PSD')

  • num_channel (int) – Number of channels used, of which the first 30 channels are EEG signals. (default: 30)

  • online_transform (Callable, optional) – The transformation of the EEG signals and baseline EEG signals. The input is a np.ndarray, and the ouput is used as the first and second value of each element in the dataset. (default: None)

  • offline_transform (Callable, optional) – The usage is the same as online_transform, but executed before generating IO intermediate results. (default: None)

  • label_transform (Callable, optional) – The transformation of the label. The input is an information dictionary, and the ouput is used as the third value of each element in the dataset. (default: None)

  • before_trial (Callable, optional) – The hook performed on the trial to which the sample belongs. It is performed before the offline transformation and thus typically used to implement context-dependent sample transformations, such as moving averages, etc. The input of this hook function is a 3D EEG signal with shape (number of electrodes, number of windows, number of frequency bands), whose ideal output shape is also (number of electrodes, number of windows, number of frequency bands).

  • after_trial (Callable, optional) – The hook performed on the trial to which the sample belongs. It is performed after the offline transformation and thus typically used to implement context-dependent sample transformations, such as moving averages, etc. The input and output of this hook function should be a sequence of dictionaries representing a sequence of EEG samples. Each dictionary contains two key-value pairs, indexed by eeg (the EEG signal matrix) and key (the index in the database) respectively.

  • io_path (str) – The path to generated unified data IO, cached as an intermediate result. If set to None, a random path will be generated. (default: None)

  • io_size (int) – Maximum size database may grow to; used to size the memory mapping. If database grows larger than map_size, an exception will be raised and the user must close and reopen. (default: 1048576)

  • io_mode (str) – Storage mode of EEG signal. When io_mode is set to lmdb, TorchEEG provides an efficient database (LMDB) for storing EEG signals. LMDB may not perform well on limited operating systems, where a file system based EEG signal storage is also provided. When io_mode is set to pickle, pickle-based persistence files are used. When io_mode is set to memory, memory are used. (default: lmdb)

  • num_worker (int) – Number of subprocesses to use for data loading. 0 means that the data will be loaded in the main process. (default: 0)

  • verbose (bool) – Whether to display logs during processing, such as progress bars, etc. (default: True)

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