Torcheeg

Latest version: v1.1.2

Safety actively analyzes 688568 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 1 of 3

1.1.2

We're excited to announce a new minor release of TorchEEG, version 1.1.2, which significantly improves documentation! Additionally, we've introduced new datasets for emotion recognition and sleep stage detection.

Documentation

We have added complete and runnable demonstrations for all APIs. For example:

python
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])


This demonstrates the usage of DEAPDataset from importing the functionality to invoking it.

Datasets

FACEDDataset wufei-png

python
from torcheeg.datasets import FACEDDataset
from torcheeg import transforms
from torcheeg.datasets.constants import FACED_CHANNEL_LOCATION_DICT

dataset = FACEDDataset(root_path='./Processed_data',
offline_transform=transforms.Compose([
transforms.BandDifferentialEntropy(),
transforms.ToGrid(FACED_CHANNEL_LOCATION_DICT)
]),
online_transform=transforms.ToTensor(),
label_transform=transforms.Compose([
transforms.Select('emotion'),
transforms.Lambda(lambda x: x + 1)
]))
print(dataset[0])
EEG signal (torch.Tensor[4, 8, 9]),
coresponding baseline signal (torch.Tensor[4, 8, 9]),
label (int)


FACEDFeatureDataset wufei-png

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


SEEDVDataset tczhangzhi

python
from torcheeg.datasets import SEEDVDataset
from torcheeg import transforms
from torcheeg.datasets.constants import SEED_V_CHANNEL_LOCATION_DICT

dataset = SEEDVDataset(root_path='./EEG_raw',
offline_transform=transforms.Compose([
transforms.BandDifferentialEntropy(),
transforms.ToGrid(SEED_V_CHANNEL_LOCATION_DICT)
]),
online_transform=transforms.ToTensor(),
label_transform=transforms.Compose([
transforms.Select('emotion'),
transforms.Lambda(lambda x: x + 1)
]))
print(dataset[0])
EEG signal (torch.Tensor[4, 9, 9]),
coresponding baseline signal (torch.Tensor[4, 9, 9]),
label (int)


SEEDVFeatureDataset tczhangzhi

python
from torcheeg.datasets import SEEDVFeatureDataset
from torcheeg import transforms
from torcheeg.datasets.constants_v import SEED_V_CHANNEL_LOCATION_DICT

dataset = SEEDVFeatureDataset(root_path='./EEG_DE_features',
offline_transform=transforms.ToGrid (SEED_V_CHANNEL_LOCATION_DICT),
online_transform=transforms.ToTensor(),
label_transform=transforms.Select('emotion'))
print(dataset[0])
EEG signal (torch.Tensor[5, 9, 9]),
coresponding baseline signal (torch.Tensor[5, 9, 9]),
label (int)


SleepEDFxDataset arrogant-R

python
from torcheeg.datasets import SleepEDFxDataset
from torcheeg import transforms

dataset = SleepEDFxDataset(root_path="./sleep-edf-database-expanded-1.0.0",
num_channels=4,
chunk_size=3000,
remove_unclear_example=True,
online_transform=transforms.ToTensor(),
label_transform=transforms.Compose([
transforms.Select(key="stage"),
transforms.Mapping(map_dict={
"W": 0,
"1": 1,
"2": 2,
"3": 3,
"4": 4,
"R": 5
})
]))

print(dataset[0])
EEG signal (torch.Tensor[2, 3000]),
label (int)


Other Enhancements

Hook functions were refactored tczhangzhi to provide global preprocessing and postprocessing of the trial signal. For example:

python
from functools import partial
from torcheeg.datasets import SEEDFeatureDataset
from torcheeg.transforms import before_hook_normalize

dataset = SEEDFeatureDataset(root_path='./ExtractedFeatures',
feature=['de_movingAve'],
offline_transform=transforms.ToGrid (SEED_CHANNEL_LOCATION_DICT),
online_transform=transforms.ToTensor(),
before_trial=before_hook_normalize,
label_transform=transforms.Compose([
transforms.Select('emotion'),
transforms.Lambda(lambda x: x + 1)
]))


before_hook_normalize provides trial-level normalization before the chunk-level transforms.

python
from torcheeg.datasets import DEAPDataset
from torcheeg.transforms import after_hook_linear_dynamical_system

dataset = DEAPDataset(root_path='./data_preprocessed_python',
offline_transform=transforms.Compose([
transforms.BandDifferentialEntropy(),
transforms.ToGrid(DEAP_CHANNEL_LOCATION_DICT)
]),
online_transform=transforms.ToTensor(),
after_trial=after_hook_linear_dynamical_system,
label_transform=transforms.Compose([
transforms.Select('valence'),
transforms.Binary(5.0),
]))


after_hook_linear_dynamical_system smooths the features of each chunk in the trial.

plot_feature_topomap allows users to specify fig_shape to customize the number of rows and columns in the topomap wufei-png


plot_feature_topomap(mock_eeg,
channel_list=DEAP_CHANNEL_LIST,
feature_list=["theta", "alpha", "beta", "gamma"],
fig_shape=(2,2))


Bug fixes in RandomMask by chris7neves

1.1.1

We're excited to announce a new minor release of TorchEEG, version 1.1.1, which significantly enhances the user experience and diligently addresses bugs! Additionally, we've introduced new features for motor imagery and imbalance learning, incorporating more feedback to improve TorchEEG's usability.

Motor Imagery

Support for new datasets and models in motor imagery:

BCICIV2aDataset


dataset = BCICIV2aDataset(io_path=f'./bciciv_2a',
root_path='./BCICIV_2a_mat',
online_transform=transforms.Compose([
transforms.To2d(),
transforms.ToTensor()
]),
label_transform=transforms.Compose([
transforms.Select('label'),
transforms.Lambda(lambda x: x - 1)
]))


EEGFuseNet arrogant-R


model = EEGfuseNet(num_electrodes=20,
hid_channels_gru=16,
num_layers_gru=1,
hid_channels_cnn=1,
chunk_size=128)


ATCNet arrogant-R


model = ATCNet(in_channels=1,
num_classes=4,
num_windows=3,
num_electrodes=22,
chunk_size=128)


FBMSNet arrogant-R


model = FBMSNet(num_classes=4,
num_electrodes=22,
chunk_size=512,
in_channels=9)


CenterLossTrainer arrogant-R


trainer = CenterLossTrainer(decoder=decoder,
classifier=classifier,
num_classes=4,
feature_dim=1152)


Imbalance Learning

Implemented trainers designed for imbalance datasets:

LALossTrainer


trainer = LALossTrainer(model, num_classes=2, class_frequency=train_loader)
trainer.fit(train_loader, val_loader)
trainer.test(test_loader)


LDAMLossTrainer


trainer = LDAMLossTrainer(model, num_classes=2, class_frequency=train_loader)
trainer.fit(train_loader, val_loader)
trainer.test(test_loader)


EQLossTrainer


trainer = EQLossTrainer(model, num_classes=2, class_frequency=train_loader)
trainer.fit(train_loader, val_loader)
trainer.test(test_loader)


FocalLossTrainer


trainer = FocalLossTrainer(model, num_classes=2, class_frequency=train_loader)
trainer.fit(train_loader, val_loader)
trainer.test(test_loader)


WCELossTrainer


trainer = WCELossTrainer(model, num_classes=2, class_frequency=train_loader)
trainer.fit(train_loader, val_loader)
trainer.test(test_loader)


Additionally, more evaluation metrics for imbalance datasets are supported in the trainers, e.g., `'matthews', 'auroc', 'kappa'`.

Other Enhancements

Added logging for more user-friendly outputs:


[2024-01-03 14:23:47] INFO (torcheeg/MainThread) ✅ | All processed EEG data has been cached to ./deap_ioplbntrqhvfdmkuwxea.
[2024-01-03 14:23:47] INFO (torcheeg/MainThread) 😊 | Please set io_path to ./deap_ioplbntrqhvfdmkuwxea for the next run, to directly read from the cache if you wish to skip the data processing step.
[2024-01-03 14:23:47] INFO (torcheeg/MainThread) 📊 | Create the split of train and test set.
[2024-01-03 14:23:47] INFO (torcheeg/MainThread) 😊 | Please set split_path to ./split_fiudpjqbhmcnaoltwzgr for the next run, if you want to use the same setting for the experiment.
.[2024-01-03 14:23:50] INFO (torcheeg/MainThread) 🔍 | Processing EEG data. Processed EEG data has been cached to ./tmp_out/deap_kuyvdgizqhfcsbmlrxae.
[2024-01-03 14:23:50] INFO (torcheeg/MainThread) ⏳ | Monitoring the detailed processing of a record for debugging. The processing of other records will only be reported in percentage to keep it clean.


Bug fixes in `train_test_split_cross_trial`, `train_test_split_groupby_trial`, and `train_test_split_per_subject_groupby_trial` by Nhix00

Bug fixes in `BandDifferentialEntropy` by arrogant-R

Corrections of typos in the documentation by dawin2015.

1.1.0

We are thrilled to announce a significant new release for TorchEEG! Taking your valuable feedback on TorchEEG v1.0 to heart, we've revamped our dataset and trainer modules. New dataset and algorithmic supports have been added to address issues like data scarcity and non-stationary characteristics in EEG analysis. We've also improved our documentation to help you achieve even better performance.

Welcome to the All-New TorchEEG!

Revamped Dataset

Thanks to joblib-based parallelism, offline parallel processing of datasets is now possible on Windows, Mac, Linux, and even within notebooks!

python
Parallel(n_jobs=self.num_worker)(
delayed(self.save_record)(
io_path=io_path,
io_size=io_size,
io_mode=io_mode,
file_id=file_id,
file=file,
process_record=self.process_record,
**kwargs)
for file_id, file in tqdm(enumerate(records),
disable=not self.verbose,
desc="[PROCESS]",
total=len(records)))


Data reading and processing logic are now more modular and easier to understand, thanks to our new generator object-based approach.

python
class AMIGOSDataset(BaseDataset):
staticmethod
def process_record(file: Any = None,
...):
code snippet
...


**Note**: Datasets cached with versions below TorchEEG v1.1.0 are no longer supported. Please regenerate your dataset caches.

New Datasets

CSVFolderDataset introducing a new dataset API for reading custom datasets with ease.

python
Example usage
...
dataset = CSVFolderDataset(csv_path='./data.csv',
read_fn=default_read_fn,
online_transform=transforms.ToTensor(),
label_transform=transforms.Select('label'),
num_worker=4)


FolderDataset introducing a new dataset API for reading custom datasets organized in folders. talhaanwarch

python
Example usage
...
dataset = FolderDataset(io_path='./folder',
root_path='./root_folder',
structure='subject_in_label',
num_channel=14,
online_transform=transforms.ToTensor(),
label_transform=transforms.Compose([
transforms.Select('label'),
transforms.Lambda(lambda x: label_map[x])
]),
num_worker=4)


MOABBDataset is added for accessing motor imagery-related datasets from MoABB. bruAristimunha

python
Example usage
...
dataset = moabb_dataset.MOABBDataset(
configurations
)


Updated Trainer

Users can now effortlessly utilize PyTorch Lightning's multi-GPU functionalities.

python
trainer = ClassifierTrainer(model, devices=2, accelerator='gpu')
trainer.fit(train_loader, val_loader)
trainer.test(test_loader)


More metrics are now available, allowing easy reporting of precision, recall, f1 score, and other metrics.

python
trainer = ClassifierTrainer(model, devices=1, accelerator='gpu', metrics=['f1score'])
trainer.fit(train_loader, val_loader)
trainer.test(test_loader)


Now, you can easily implement your own algorithms by overriding the `training_step`.

python
class MyClassifierTrainer(ClassifierTrainer):
code snippet
...


New Trainers for Advanced Algorithms

New trainers like ADATrainer, CORALTrainer, DANTrainer, and others have been added to support domain adaptation algorithms.

python
trainer = DDCTrainer(
extractor, classifier, num_classes=10,
devices=1, weight_domain=1.0, accelerator='gpu'
)
trainer.fit(source_loader, target_loader, val_loader)
trainer.test(test_loader)


Pre-training on Unlabeled Data

BYOLTrainer and SimCLRTrainer allow for pre-training on unlabeled datasets.

python
Configure DEAP dataset
contras_dataset = DEAPDataset(
configurations
online_transform=transforms.Compose([
transforms.ToTensor(),
transforms.Contrastive(
transforms.Compose([
transforms.RandomMask(p=0.5),
transforms.RandomNoise(p=0.5)
]), num_views=2
)
])
)

Run BYOL Trainer
trainer = BYOLTrainer(extractor, extract_channels=256, devices=1, accelerator='gpu')
trainer.fit(train_loader, val_loader)


Generative Models Training

BetaVAETrainer, DDPMTrainer, GlowTrainer, and others have been added for generative model training.

python
Set up Generator and Discriminator
g_model = BGenerator(in_channels=128)
d_model = BDiscriminator(in_channels=4)

Run WGANGP Trainer
trainer = WGANGPTrainer(generator=g_model, discriminator=d_model)
trainer.fit(train_loader, val_loader)
trainer.test(test_loader)


Other Updates

- New tutorials and documentation are available [here](https://torcheeg.readthedocs.io/en/latest/auto_examples/index.html). arrogant-R

- Bug fixes: Resolved issues with Dreamer Dataset when `chunk_size = -1`. MicheleBarsotti

Feel free to check out our updated [documentation](https://torcheeg.readthedocs.io/en/latest/auto_examples/index.html) for more details and examples. We're excited for you to try out the new TorchEEG! 🎉

1.0.11

A new minor TorchEEG release that greatly improves the user experience for Windows users! We also fix bugs in TorchEEG v1.0.10. More feedback was taken to improve TorchEEG usability.

Dataset

`io_mode`: On some Windows systems and storage devices, the read and write speed of LMDB is slow. We provide an alternative option, `pickle`, that solves this problem. Its potential risk is that there may be additional IO overhead for samples with low data dimensions.

python
dataset = DEAPDataset(
root_path='./tmp_in/data_preprocessed_python',
offline_transform=transforms.Compose([
transforms.BandDifferentialEntropy(sampling_rate=128,
apply_to_baseline=True),
transforms.BaselineRemoval(),
transforms.ToGrid(DEAP_CHANNEL_LOCATION_DICT)
]),
online_transform=transforms.ToTensor(),
label_transform=transforms.Compose([
transforms.Select('valence'),
transforms.Binary(5.0),
]),
io_mode='pickle', here
chunk_size=128,
baseline_chunk_size=128,
num_baseline=3,
num_worker=4)


`io_size`: auto-tuned IO size. If users cannot know the preprocessed dataset size in advance, they don't need to set it manually. TorchEEG will pre-define a smaller `map_size` and automatically scale when the `map_size` is insufficient.

python
dataset = DEAPDataset(
root_path='./tmp_in/data_preprocessed_python',
offline_transform=transforms.Compose([
transforms.BandDifferentialEntropy(sampling_rate=128,
apply_to_baseline=True),
transforms.BaselineRemoval(),
transforms.ToGrid(DEAP_CHANNEL_LOCATION_DICT)
]),
online_transform=transforms.ToTensor(),
label_transform=transforms.Compose([
transforms.Select('valence'),
transforms.Binary(5.0),
]),
io_size=1024, here
chunk_size=128,
baseline_chunk_size=128,
num_baseline=3,
num_worker=4)


Trainer

`num_classes`: Allows the user to specify the number of classes for classification problems. If not specified, the number of classes is inferred from `model.num_classes`.

python
for GPU
trainer = ClassificationTrainer(model, device_ids=[0], num_classes=2)
for CPU
trainer = ClassificationTrainer(model, device_ids=[], num_classes=2)


Bug Fixes

- Fix a bug that leads to additional overhead when reading and writing to LMDB (Sugewud).

- Fix a bug where partial data are lost when using multi-process datasets on Windows systems (qian317).

- Fix the usage of `pyg`-related modules. Since `torch_geometric` exists as a plugin, we recommend to use `from xx.pyg import xx` (PrLeung):

python
from torcheeg.transforms.pyg import ToG


To help users use TorchEEG more easily, we release an example gallery with about ten examples. Issues that Windows users may need to pay attention to are additionally marked.

1.0.10

A new minor TorchEEG release brings new trainers, models, utils, datasets and transforms to TorchEEG. The TorchEEG team has experimented extensively with generative models and cross-subject algorithms based on domain adaptation, which are considered as cutting-edge research for deep learning-oriented EEG analysis. The related API is now open source! More feedback was taken to improve TorchEEG usability.

Trainer

We offer a variety of trainers for generating models:

- DDPMTrainer and CDDPMTrainer

python
unet = BUNet(in_channels=4)
trainer = DDPMTrainer(unet)
trainer.fit(train_loader, val_loader)
trainer.test(test_loader)

unet = BCUNet(in_channels=4, num_classes=2)
trainer = CDDPMTrainer(unet)
trainer.fit(train_loader, val_loader)
trainer.test(test_loader)


- GANTrainer and CGANTrainer

python
g_model = BGenerator(in_channels=128)
d_model = BDiscriminator(in_channels=4)
trainer = GANTrainer(g_model, d_model)
trainer.fit(train_loader, val_loader)
trainer.test(test_loader)

g_model = BCGenerator(in_channels=128, num_classes=2)
d_model = BCDiscriminator(in_channels=4, num_classes=2)
trainer = CGANTrainer(g_model, d_model)
trainer.fit(train_loader, val_loader)
trainer.test(test_loader)


- VAETrainer and CVAETrainer

python
trainer = VAETrainer(encoder, decoder)
trainer.fit(train_loader, val_loader)
trainer.test(test_loader)


- GlowTrainer

python
model = BGlow(in_channels=4)
trainer = GlowTrainer(model)
trainer.fit(train_loader, val_loader)
trainer.test(test_loader)



Some domain adaptation algorithms were supplemented to show good experimental performance:

- DANTrainer

python
trainer = DANTrainer(extractor, classifier)
trainer.fit(source_loader, target_loader, val_loader)
trainer.test(test_loader)


- ADATrainer

python
trainer = ADATrainer(extractor, classifier)
trainer.fit(source_loader, target_loader, val_loader)
trainer.test(test_loader)

Model

Complemented with a CNN-based hybrid model:

* SSTEmotionNet

python
eeg = torch.randn(2, 32 + 4, 16, 16)
model = SSTEmotionNet(temporal_in_channels=32,
spectral_in_channels=4,
grid_size=(16, 16),
num_classes=2)
pred = model(eeg)


A large number of transformer-based models have been added:

- ViT

python
eeg = torch.randn(1, 32, 128)
model = ArjunViT(chunk_size=128,
t_patch_size=32,
num_classes=2)
pred = model(eeg)


- VanillaTransformer

python
eeg = torch.randn(1, 32, 128)
model = VanillaTransformer(chunk_size=128,
t_patch_size=32,
hid_channels=32,
depth=3,
heads=4,
head_channels=64,
mlp_channels=64,
num_classes=2)
pred = model(eeg)


- ArjunViT

python
eeg = torch.randn(1, 32, 128)
model = ArjunViT(chunk_size=128,
t_patch_size=32,
num_classes=2)
pred = model(eeg)


And GNN-based model:

* LGGNet

python
eeg = torch.rand(2, 1, 32, 128)
model = LGGNet(DEAP_GENERAL_REGION_LIST,
num_electrodes=32,
chunk_size=128)
pred = model(eeg)


Generate model baselines to be adapted to EEG generation:

* BUNet and BCUNet for DDPM

python
unet = BUNet()
eeg = torch.randn(2, 4, 9, 9)
t = torch.randint(low=1, high=1000, size=(2, ))
fake_X = unet(eeg, t)

unet = BCUNet(num_classes=2)
eeg = torch.randn(2, 4, 9, 9)
t = torch.randint(low=1, high=1000, size=(2, ))
y = torch.randint(low=0, high=2, size=(1, ))
fake_X = unet(eeg, t, y)


* BCGenerator , BGenerator, BCDiscriminator, and BDiscriminator for GAN and CGAN

python
g_model = BGenerator(in_channels=128)
d_model = BDiscriminator(in_channels=4)
z = torch.normal(mean=0, std=1, size=(1, 128))
fake_X = g_model(z)
disc_X = d_model(fake_X)

g_model = BCGenerator(in_channels=128, num_classes=3)
d_model = BCDiscriminator(in_channels=4, num_classes=3)
z = torch.normal(mean=0, std=1, size=(1, 128))
y = torch.randint(low=0, high=3, size=(1, ))
fake_X = g_model(z, y)
disc_X = d_model(fake_X, y)


* BCEncoder, BCDecoder, BDecoder, and BDecoder for VAE and CVAE

python
encoder = BEncoder(in_channels=4)
decoder = BDecoder(in_channels=64, out_channels=4)
eeg = torch.randn(1, 4, 9, 9)
mu, logvar = encoder(eeg)
std = torch.exp(0.5 * logvar)
eps = torch.randn_like(std)
z = eps * std + mu
fake_X = decoder(z)

encoder = BCEncoder(in_channels=4, num_classes=3)
decoder = BCDecoder(in_channels=64, out_channels=4, num_classes=3)
y = torch.randint(low=0, high=3, size=(1, ))
eeg = torch.randn(1, 4, 9, 9)
mu, logvar = encoder(eeg, y)
std = torch.exp(0.5 * logvar)
eps = torch.randn_like(std)
z = eps * std + mu
fake_X = decoder(z, y)


* Glow

python
model = BGlow()
mock_eeg = torch.randn(2, 4, 32, 32)
z, nll_loss, y_logits = model(mock_eeg)
loss = nll_loss.mean()
fake_X = model(temperature=1.0, reverse=True)


Utils

Added a new method for visualizing the adjacency matrix:

* plot_adj_connectivity

python
adj = torch.randn(62, 62)
plot_adj_connectivity(adj,
SEED_CHANNEL_LIST,
SEED_GENERAL_REGION_LIST,
num_connectivity=60,
linewidth=1.5)


Datasets

Additional feature datasets are supported, where the publisher has extracted the suggested features:

- SEEDIVDataset

python
dataset = SEEDIVDataset()


- SEEDIVFeatureDataset

python
dataset = SEEDIVFeatureDataset()


- SEEDFeatureDataset

python
dataset = SEEDFeatureDataset()


- MPEDFeatureDataset

python
dataset = MPEDFeatureDataset()


Some hook functions for trial have been added:

- before_trial_normalize

python
dataset = DEAPDataset(before_trial=before_trial_normalize)


- after_trial_normalize

python
dataset = DEAPDataset(after_trial=after_trial_normalize)


- after_trial_moving_avg

python
dataset = DEAPDataset(after_trial=after_trial_moving_avg)



Transforms

New transformation functions have been added:

- Downsample

python
eeg = np.random.randn(32, 128)
transformed_eeg = Downsample(num_points=32, axis=-1)(eeg=eeg)


Concatenate-related transformation functions support cross-use with Compose:

- Concatenate

python
eeg = np.random.randn(32, 128)
transformed_eeg = Concatenate([BandSkewness(), BandBinPower()])(eeg=eeg)


- MapChunk

python
eeg = np.random.randn(64, 1000)
transformed_eeg = MapChunk(BandDifferentialEntropy(),
chunk_size=250,
overlap=0)(eeg=eeg)

Breaking Changes

- The transforms `ConcatenateChunk` changed to `MapChunk `
- Parameter name `frequency` changed to `sampling_rate` in `RandomFrequencyShift`
- `MSRN ` was removed from `torcheeg.models`

1.0.9

A new minor TorchEEG release brings new datasets and transformation supports to TorchEEG. It simplifies the installer and provides `conda` option for the latest v1.0.9 version. The latest TorchEEG further includes new deep learning models. More feedback was taken to improve TorchEEG usability.

Datasets

We provide an implementation of a benchmark dataset for SSVEP-based brain-computer interfaces.

- TSUBenchmark

python
dataset = TSUBenckmarkDataset(io_path=f'./tsu_benchmark',
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']))


Transforms

More transformations to labels are supported.

* BinaryOneVSRest

python
transform = BinaryOneVSRest(positive=1)
transform(y=2)['y']


* FixCategory

python
transform = FixCategory(value=0)
transform(y=3)['y']


More feature extraction methods are implemented.

* BandApproximateEntropy

python
transform = BandApproximateEntropy()
transform(eeg=np.random.randn(32, 128))['eeg'].shape


* BandSampleEntropy

python
transform = BandSampleEntropy()
transform(eeg=np.random.randn(32, 128))['eeg'].shape


* BandSVDEntropy

python
transform = BandSVDEntropy()
transform(eeg=np.random.randn(32, 128))['eeg'].shape


* BandDetrendedFluctuationAnalysis

python
transform = BandDetrendedFluctuationAnalysis()
transform(eeg=np.random.randn(32, 128))['eeg'].shape


* BandHiguchiFractalDimension

python
transform = BandHiguchiFractalDimension()
transform(eeg=np.random.randn(32, 128))['eeg'].shape


* BandHjorth

python
transform = BandHjorth()
transform(eeg=np.random.randn(32, 128))['eeg'].shape


* BandHurst

python
transform = BandHurst()
transform(eeg=np.random.randn(32, 128))['eeg'].shape


* BandPetrosianFractalDimension

python
transform = BandHiguchiFractalDimension()
transform(eeg=np.random.randn(32, 128))['eeg'].shape


* BandBinPower

python
transform = BandBinPower()
transform(eeg=np.random.randn(32, 128))['eeg'].shape


* BandSpectralEntropy

python
transform = BandSampleEntropy()
transform(eeg=np.random.randn(32, 128))['eeg'].shape


* PearsonCorrelation

python
transform = BandSignal()
transform(eeg=np.random.randn(32, 128))['eeg'].shape


* PhaseLockingCorrelation

python
transform = BandSignal()
transform(eeg=np.random.randn(32, 128))['eeg'].shape


* DWTDecomposition

python
transform = DWTDecomposition()
transform(eeg=np.random.randn(32, 1000))['eeg'].shape


Installation

We've simplified the process of installing TorchEEG for the plug-and-play application. Users can complete the installation with one line of command.

shell
install via conda
conda install -c tczhangzhi -c conda-forge torcheeg
or via pip
pip install torcheeg


Graph-related transformations and deep learning models are isolated as plug-ins, and users only need to install them when they use them.

shell
conda install pyg -c pyg

from torcheeg.models.pyg import DGCNN
from torcheeg.transforms.pyg import ToG
from torcheeg.utils.pyg import plot_graph


Deep Learning Models

- GRU

python
eeg = torch.randn(1, 32, 128)
model = GRU(num_electrodes=32, hid_channels=64, num_classes=2)
pred = model(eeg)


- LSTM

python
eeg = torch.randn(1, 32, 128)
model = LSTM(num_electrodes=32, hid_channels=64, num_classes=2)
pred = model(eeg)


- FBCNet

python
eeg = torch.randn(1, 4, 32, 512)
model = FBCNet(num_classes=2,
num_electrodes=32,
chunk_size=512,
in_channels=4,
num_S=32)
pred = model(eeg)


* GIN

python
data = Batch.from_data_list([some_graph])
model = GIN(in_channels=4, hid_channels=64, num_classes=2)
pred = model(data)


Breaking Changes

- Parameter name `baseline_num` changed to `num_baseline`
- Parameter name `channel_num` changed to `num_channel`
- `RGNN` was removed from `torcheeg.models`, added to `torcheeg.models.pyg`
- `ToG` and `ToDynamicG` have been removed from `torcheeg.transforms` and added to `torcheeg.transforms.pyg`
- `plot_graph` was removed from `torcheeg.utils`, added to `torcheeg.utils.pyg.plot_graph`

Page 1 of 3

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.