TSUBenckmarkDataset¶
- class torcheeg.datasets.TSUBenckmarkDataset(root_path: str = './TSUBenchmark', chunk_size: int = 250, overlap: int = 0, num_channel: int = 64, 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, io_path: None | str = None, io_size: int = 1048576, io_mode: str = 'lmdb', num_worker: int = 0, verbose: bool = True)[source][source]¶
The benchmark dataset for SSVEP-Based brain-computer interfaces (TSUBenckmark) is provided by the Tsinghua BCI Lab. It presents a benchmark steady-state visual evoked potential (SSVEP) dataset acquired with a 40-target brain-computer interface (BCI) speller. 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: Wang et al.
Year: 2016
Download URL: http://bci.med.tsinghua.edu.cn/
Reference: Wang Y, Chen X, Gao X, et al. A benchmark dataset for SSVEP-based brain-computer interfaces[J]. IEEE Transactions on Neural Systems and Rehabilitation Engineering, 2016, 25(10): 1746-1752.
Stimulus: Each trial started with a visual cue (a red square) indicating a target stimulus. The cue appeared for 0.5s on the screen. Subjects were asked to shift their gaze to the target as soon as possible within the cue duration. Following the cue offset, all stimuli started to flicker on the screen concurrently and lasted 5s. After stimulus offset, the screen was blank for 0.5s before the next trial began, which allowed the subjects to have short breaks between consecutive trials.
Signals: Electroencephalogram (64 channels at 250Hz) of 35 subjects. For each subject, the experiment consisted of 6 blocks. Each block contained 40 trials corresponding to all 40 characters indicated in a random order. Totally 35 people x 6 blocks x 40 trials.
Rating: Frequency and phase values for the 40 trials.
In order to use this dataset, the download folder
data_preprocessed_python
is required, containing the following files:Readme.txt
Sub_info.txt
64-channels.loc
Freq_Phase.mat
S1.mat
…
S35.mat
An example dataset for CNN-based methods:
from torcheeg.datasets import TSUBenckmarkDataset from torcheeg import transforms from torcheeg.datasets.constants.ssvep.tsubenchmark import TSUBenckmark_CHANNEL_LOCATION_DICT dataset = TSUBenckmarkDataset(root_path='./TSUBenchmark', offline_transform=transforms.Compose([ transforms.BandDifferentialEntropy(), transforms.ToGrid(TSUBenckmark_CHANNEL_LOCATION_DICT) ]), online_transform=transforms.ToTensor(), label_transform=transforms.Select(['trial_id'])) print(dataset[0]) # EEG signal (torch.Tensor[250, 10, 11]), # coresponding baseline signal (torch.Tensor[250, 10, 11]), # label (int)
Another example dataset for CNN-based methods:
dataset = TSUBenckmarkDataset(root_path='./TSUBenchmark', online_transform=transforms.Compose([ transforms.ToTensor(), transforms.To2d() ]), label_transform=transforms.Select(['trial_id'])) print(dataset[0]) # EEG signal (torch.Tensor[64, 250]), # coresponding baseline signal (torch.Tensor[64, 250]), # label (int)
An example dataset for GNN-based methods:
dataset = TSUBenckmarkDataset(root_path='./TSUBenchmark', online_transform=transforms.Compose([ ToG(TSUBenckmark_ADJACENCY_MATRIX) ]), label_transform=transforms.Select(['trial_id'])) 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 TSUBenchmark.zip) formats (default:
'./TSUBenchmark'
)chunk_size (int) – Number of data points included in each EEG chunk as training or test samples. (default:
250
)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 64 channels are EEG signals. (default:
64
)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
)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
)