We open sourced our internal EEG analysis library, TorchEEG! Welcome to TorchEEG!
Highlights
* **torcheeg.datasets:** The packaged benchmark dataset implementation provides a multi-process preprocessing interface. All datasets rely on a set of efficient IO APIs, [torcheeg.io](https://torcheeg.readthedocs.io/en/latest/torcheeg.io.html), to store data preprocessing results on disk and read them quickly during training. Data preprocessing and storage support multiprocessing (speed up!).
- DREAMER dataset from Katsigiannis et al.: [DREAMER: A database for emotion recognition through EEG and ECG signals from wireless low-cost off-the-shelf devices](https://ieeexplore.ieee.org/abstract/document/7887697).
python
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),
]))
- SEED dataset from Zheng et al.: [Investigating critical frequency bands and channels for EEG-based emotion recognition with deep neural networks](https://ieeexplore.ieee.org/abstract/document/7104132).
python
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)
]))
- DEAP dataset from Koelstra et al.: [DEAP: A database for emotion analysis; using physiological signals](https://ieeexplore.ieee.org/abstract/document/5871728).
python
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),
]))
* **torcheeg.transforms:** TorchEEG provides extensive data transformation tools to help users build EEG data representations suitable for a variety of task formulation and a variety of model structures.
* Feature Engineering: BandDifferentialEntropy, BandPowerSpectralDensity, BandMeanAbsoluteDeviation, BandKurtosis, BandSkewness, Concatenate.
python
transform = BandDifferentialEntropy()
transform(torch.randn(32, 128))
transform = BandDifferentialEntropy()
transform(torch.randn(32, 128))
transform = BandMeanAbsoluteDeviation()
transform(torch.randn(32, 128))
transform = BandKurtosis()
transform(torch.randn(32, 128))
transform = BandSkewness()
transform(torch.randn(32, 128))
transform = Concatenate([
BandDifferentialEntropy(),
BandMeanAbsoluteDeviation()
])
transform(torch.randn(32, 128))
* General Operation: MeanStdNormalize, MinMaxNormalize.
python
transform = MeanStdNormalize(axis=0)
transform(torch.randn(32, 128))
transform = MinMaxNormalize(axis=0)
transform(torch.randn(32, 128))
* For CNN: To2d, ToGrid, ToInterpolatedGrid.
python
transform = To2d()
transform(torch.randn(32, 128))
transform = ToGrid(DEAP_CHANNEL_LOCATION_DICT)
transform(torch.randn(32, 128))
transform = ToInterpolatedGrid(DEAP_CHANNEL_LOCATION_DICT)
transform(torch.randn(32, 128))
* For GNN: ToG.
python
transform = ToG(adj=DEAP_ADJACENCY_MATRIX)
transform(np.random.randn(32, 128))
* For Augmentation: ToTensor, Resize, RandomNoise, RandomMask.
python
transform = ToTensor()
transform(np.random.randn(32, 128))
transform = ToTensor(size=(64, 64))
transform(torch.randn(128, 9, 9))
transform = RandomNoise(p=0.5)
transform(torch.randn(32, 128))
transform = RandomMask()
transform(torch.randn(32, 128))
* For Label Construction: Select, Binary, BinariesToCategory.
python
transform = Select(key='valence')
transform({'valence': 4.5, 'arousal': 5.5, 'subject': 7})
transform = Binary(threshold=5.0)
transform(4.5)
transform = BinariesToCategory()
transform([0, 0])
* **torcheeg.model_selection:** Extensive dataset partitioning methods for users to experiment with different settings.
* Subject Dependent: KFoldTrialPerSubject, train_test_split_trial_per_subject.
python
cv = KFoldTrialPerSubject(n_splits=5, shuffle=True, split_path='./split')
cv.split(dataset)
train_test_split_trial_per_subject(dataset=dataset, split_path='./split')
* Subject Independent: LeaveOneSubjectOut.
python
cv = LeaveOneSubjectOut('./split')
cv.split(dataset)
* Conventional: KFoldDataset, train_test_split_dataset, KFoldTrial, train_test_split_trial.
python
cv = KFoldDataset(n_splits=5, shuffle=True, split_path='./split')
cv.split(dataset)
train_test_split_dataset(dataset=dataset, split_path='./split')
cv = KFoldTrial(n_splits=5, shuffle=False, split_path='./split')
cv.split(dataset)
train_test_split_trial(dataset=dataset, split_path='./split')