DEAPDataset¶
- class torcheeg.datasets.DEAPDataset(root_path: str = './data_preprocessed_python', chunk_size: int = 128, overlap: int = 0, num_channel: int = 32, num_baseline: int = 3, baseline_chunk_size: int = 128, 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_session: 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]¶
A multimodal dataset for the analysis of human affective states. 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: Koelstra et al.
Year: 2012
Download URL: https://www.eecs.qmul.ac.uk/mmv/datasets/deap/download.html
Reference: Koelstra S, Muhl C, Soleymani M, et al. DEAP: A database for emotion analysis; using physiological signals[J]. IEEE transactions on affective computing, 2011, 3(1): 18-31.
Stimulus: 40 one-minute long excerpts from music videos.
Signals: Electroencephalogram (32 channels at 512Hz, downsampled to 128Hz), skinconductance level (SCL), respiration amplitude, skin temperature,electrocardiogram, blood volume by plethysmograph, electromyograms ofZygomaticus and Trapezius muscles (EMGs), electrooculogram (EOG), face video (for 22 participants).
Rating: Arousal, valence, like/dislike, dominance (all ona scale from 1 to 9), familiarity (on a scale from 1 to 5).
In order to use this dataset, the download folder
data_preprocessed_python
is required, containing the following files:s01.dat
s02.dat
s03.dat
…
s32.dat
An example dataset for CNN-based methods:
from torcheeg.datasets import DEAPDataset from torcheeg import transforms from torcheeg.datasets.constants import DEAP_CHANNEL_LOCATION_DICT dataset = DEAPDataset(root_path='./data_preprocessed_python', offline_transform=transforms.Compose([ transforms.BandDifferentialEntropy(), transforms.ToGrid(DEAP_CHANNEL_LOCATION_DICT) ]), online_transform=transforms.ToTensor(), label_transform=transforms.Compose([ transforms.Select('valence'), transforms.Binary(5.0), ])) print(dataset[0]) # EEG signal (torch.Tensor[4, 9, 9]), # coresponding baseline signal (torch.Tensor[4, 9, 9]), # label (int)
Another example dataset for CNN-based methods:
from torcheeg.datasets import DEAPDataset from torcheeg import transforms dataset = DEAPDataset(root_path='./data_preprocessed_python', online_transform=transforms.Compose([ transforms.To2d(), transforms.ToTensor() ]), label_transform=transforms.Compose([ transforms.Select(['valence', 'arousal']), transforms.Binary(5.0), transforms.BinariesToCategory() ])) print(dataset[0]) # EEG signal (torch.Tensor[1, 32, 128]), # coresponding baseline signal (torch.Tensor[1, 32, 128]), # label (int)
An example dataset for GNN-based methods:
from torcheeg.datasets import DEAPDataset from torcheeg import transforms from torcheeg.datasets.constants import DEAP_ADJACENCY_MATRIX from torcheeg.transforms.pyg import ToG dataset = DEAPDataset(root_path='./data_preprocessed_python', online_transform=transforms.Compose([ ToG(DEAP_ADJACENCY_MATRIX) ]), label_transform=transforms.Compose([ transforms.Select('arousal'), transforms.Binary(5.0) ])) 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 pickled python/numpy (unzipped data_preprocessed_python.zip) formats (default:
'./data_preprocessed_python'
)chunk_size (int) – Number of data points included in each EEG chunk as training or test samples. If set to -1, the EEG signal of a trial is used as a sample of a chunk. (default:
128
)overlap (int) – The number of overlapping data points between different chunks when dividing EEG chunks. (default:
0
)num_channel (int) – Number of channels used, of which the first 32 channels are EEG signals. (default:
32
)num_baseline (int) – Number of baseline signal chunks used. (default:
3
)baseline_chunk_size (int) – Number of data points included in each baseline signal chunk. The baseline signal in the DEAP dataset has a total of 384 data points. (default:
128
)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 2D EEG signal with shape (number of electrodes, number of data points), whose ideal output shape is also (number of electrodes, number of data points).
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) andkey
(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 topickle
, pickle-based persistence files are used. When io_mode is set tomemory
, 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
)