torcheeg.datasets

DEAPDataset

class torcheeg.datasets.DEAPDataset(root_path: str = './data_preprocessed_python', chunk_size: int = 128, overlap: int = 0, channel_num: int = 32, baseline_num: int = 3, baseline_chunk_size: int = 128, online_transform: Union[None, Callable] = None, offline_transform: Union[None, Callable] = None, label_transform: Union[None, Callable] = None, io_path: str = './io/deap', num_worker: int = 1, verbose: bool = True)[source]

Bases: BaseDataset

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).

An example dataset for CNN-based methods:

dataset = DEAPDataset(io_path=f'./deap',
                      root_path='./data_preprocessed_python',
                      offline_transform=.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[128, 9, 9]),
# coresponding baseline signal (torch.Tensor[128, 9, 9]),
# label (int)

Another example dataset for CNN-based methods:

dataset = DEAPDataset(io_path=f'./deap',
                      root_path='./data_preprocessed_python',
                      online_transform=transforms.Compose([
                          transforms.ToTensor(),
                          transforms.Lambda(lambda x: x.unsqueeze(0))
                      ]),
                      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:

dataset = DEAPDataset(io_path=f'./deap',
                      root_path='./data_preprocessed_python',
                      online_transform=transforms.Compose([
                          transforms.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)

In particular, TorchEEG utilizes the producer-consumer model to allow multi-process data preprocessing. If your data preprocessing is time consuming, consider increasing num_worker for higher speedup.

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. (default: 128)

  • overlap (int) – The number of overlapping data points between different chunks when dividing EEG chunks. (default: 0)

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

  • baseline_num (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)

  • io_path (str) – The path to generated unified data IO, cached as an intermediate result. (default: /io/deap)

  • num_worker (str) – How many subprocesses to use for data processing. (default: 1)

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

DREAMERDataset

class torcheeg.datasets.DREAMERDataset(mat_path: str = './DREAMER.mat', chunk_size: int = 128, overlap: int = 0, channel_num: int = 14, baseline_num: int = 61, baseline_chunk_size: int = 128, online_transform: Union[None, Callable] = None, offline_transform: Union[None, Callable] = None, label_transform: Union[None, Callable] = None, io_path: str = './io/dreamer', num_worker: int = 1, verbose: bool = True)[source]

Bases: BaseDataset

A multi-modal database consisting of electroencephalogram and electrocardiogram signals recorded during affect elicitation by means of audio-visual stimuli. 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: Katsigiannis et al.

  • Year: 2017

  • Download URL: https://zenodo.org/record/546113

  • Reference: Katsigiannis S, Ramzan N. DREAMER: A database for emotion recognition through EEG and ECG signals from wireless low-cost off-the-shelf devices[J]. IEEE journal of biomedical and health informatics, 2017, 22(1): 98-107.

  • Stimulus: 18 movie clips.

  • Signals: Electroencephalogram (14 channels at 128Hz), and electrocardiogram (2 channels at 256Hz) of 23 subjects.

  • Rating: Arousal, valence, like/dislike, dominance, familiarity (all ona scale from 1 to 5).

An example dataset for CNN-based methods:

dataset = DREAMERDataset(io_path=f'./dreamer',
                      mat_path='./DREAMER.mat',
                      offline_transform=.Compose([
                          transforms.BandDifferentialEntropy(),
                          transforms.ToGrid(DREAMER_CHANNEL_LOCATION_DICT)
                      ]),
                      online_transform=transforms.ToTensor(),
                      label_transform=transforms.Compose([
                          transforms.Select('valence'),
                          transforms.Binary(3.0),
                      ]))
print(dataset[0])
# EEG signal (torch.Tensor[128, 9, 9]),
# coresponding baseline signal (torch.Tensor[128, 9, 9]),
# label (int)

Another example dataset for CNN-based methods:

dataset = DREAMERDataset(io_path=f'./dreamer',
                      mat_path='./DREAMER.mat',
                      online_transform=transforms.Compose([
                          transforms.ToTensor(),
                          transforms.Lambda(lambda x: x.unsqueeze(0))
                      ]),
                      label_transform=transforms.Compose([
                          transforms.Select(['valence', 'arousal']),
                          transforms.Binary(3.0),
                          transforms.BinariesToCategory()
                      ]))
print(dataset[0])
# EEG signal (torch.Tensor[1, 14, 128]),
# coresponding baseline signal (torch.Tensor[1, 14, 128]),
# label (int)

An example dataset for GNN-based methods:

dataset = DREAMERDataset(io_path=f'./dreamer',
                      mat_path='./DREAMER.mat',
                      online_transform=transforms.Compose([
                          transforms.ToG(DREAMER_ADJACENCY_MATRIX)
                      ]),
                      label_transform=transforms.Compose([
                          transforms.Select('arousal'),
                          transforms.Binary(3.0)
                      ]))
print(dataset[0])
# EEG signal (torch_geometric.data.Data),
# coresponding baseline signal (torch_geometric.data.Data),
# label (int)

In particular, TorchEEG utilizes the producer-consumer model to allow multi-process data preprocessing. If your data preprocessing is time consuming, consider increasing num_worker for higher speedup.

Parameters
  • mat_path (str) – Downloaded data files in pickled matlab formats (default: './DREAMER.mat')

  • chunk_size (int) – Number of data points included in each EEG chunk as training or test samples. (default: 128)

  • overlap (int) – The number of overlapping data points between different chunks when dividing EEG chunks. (default: 0)

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

  • baseline_num (int) – Number of baseline signal chunks used. (default: 61)

  • baseline_chunk_size (int) – Number of data points included in each baseline signal chunk. The baseline signal in the DREAMER dataset has a total of 7808 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)

  • io_path (str) – The path to generated unified data IO, cached as an intermediate result. (default: /io/dreamer)

  • num_worker (str) – How many subprocesses to use for data processing. (default: 1)

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

SEEDDataset

class torcheeg.datasets.SEEDDataset(root_path: str = './Preprocessed_EEG', chunk_size: int = 200, overlap: int = 0, channel_num: int = 62, online_transform: Union[None, Callable] = None, offline_transform: Union[None, Callable] = None, label_transform: Union[None, Callable] = None, io_path: str = './io/seed', num_worker: int = 1, verbose: bool = True)[source]

Bases: BaseDataset

The SJTU Emotion EEG Dataset (SEED), is a collection of EEG datasets provided by the BCMI laboratory, which is led by Prof. Bao-Liang Lu. 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: Zheng et al.

  • Year: 2015

  • Download URL: https://bcmi.sjtu.edu.cn/home/seed/index.html

  • Reference: Zheng W L, Lu B L. Investigating critical frequency bands and channels for EEG-based emotion recognition with deep neural networks[J]. IEEE Transactions on Autonomous Mental Development, 2015, 7(3): 162-175.

  • Stimulus: 15 four-minute long film clips from six Chinese movies.

  • Signals: Electroencephalogram (62 channels at 200Hz) of 15 subjects, and eye movement data of 12 subjects. Each subject conducts the experiment three times, with an interval of about one week, totally 15 people x 3 times = 45

  • Rating: positive (-1), negative (0), and neutral (1).

An example dataset for CNN-based methods:

dataset = SEEDDataset(io_path=f'./seed',
                      root_path='./Preprocessed_EEG',
                      offline_transform=transforms.Compose([
                          transforms.BandDifferentialEntropy(),
                          transforms.ToGrid(SEED_CHANNEL_LOCATION_DICT)
                      ]),
                      online_transform=transforms.ToTensor(),
                      label_transform=transforms.Compose([
                          transforms.Select(['emotion']),
                          transforms.Lambda(x: x + 1)
                      ]))
print(dataset[0])
# EEG signal (torch.Tensor[200, 9, 9]),
# coresponding baseline signal (torch.Tensor[200, 9, 9]),
# label (int)

Another example dataset for CNN-based methods:

dataset = SEEDDataset(io_path=f'./seed',
                      root_path='./Preprocessed_EEG',
                      online_transform=transforms.Compose([
                          transforms.ToTensor(),
                          transforms.Lambda(lambda x: x.unsqueeze(0))
                      ]),
                      label_transform=transforms.Compose([
                          transforms.Select(['emotion']),
                          transforms.Lambda(x: x + 1)
                      ]))
print(dataset[0])
# EEG signal (torch.Tensor[62, 200]),
# coresponding baseline signal (torch.Tensor[62, 200]),
# label (int)

An example dataset for GNN-based methods:

dataset = SEEDDataset(io_path=f'./seed',
                      root_path='./Preprocessed_EEG',
                      online_transform=transforms.Compose([
                          transforms.ToG(SEED_ADJACENCY_MATRIX)
                      ]),
                      label_transform=transforms.Compose([
                          transforms.Select(['emotion']),
                          transforms.Lambda(x: x + 1)
                      ]))
print(dataset[0])
# EEG signal (torch_geometric.data.Data),
# coresponding baseline signal (torch_geometric.data.Data),
# label (int)

In particular, TorchEEG utilizes the producer-consumer model to allow multi-process data preprocessing. If your data preprocessing is time consuming, consider increasing num_worker for higher speedup.

Parameters
  • root_path (str) – Downloaded data files in matlab (unzipped Preprocessed_EEG.zip) formats (default: './Preprocessed_EEG')

  • chunk_size (int) – Number of data points included in each EEG chunk as training or test samples. (default: 200)

  • overlap (int) – The number of overlapping data points between different chunks when dividing EEG chunks. (default: 0)

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

  • 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)

  • io_path (str) – The path to generated unified data IO, cached as an intermediate result. (default: /io/seed)

  • num_worker (str) – How many subprocesses to use for data processing. (default: 1)

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