API Reference#

This is the reference for classes (CamelCase names) and functions (underscore_case names) of Braindecode.

braindecode:

Classifier#

braindecode.classifier:

EEGClassifier(module, *args[, criterion, ...])

Classifier that does not assume softmax activation.

Regressor#

braindecode.regressor:

EEGRegressor(module, *args[, cropped, ...])

Regressor that calls loss function directly.

Models#

braindecode.models.base:

EEGModuleMixin([n_outputs, n_chans, ...])

Mixin class for all EEG models in braindecode.

braindecode.models:

ShallowFBCSPNet([n_chans, n_outputs, ...])

Shallow ConvNet model from Schirrmeister et al 2017.

Deep4Net([n_chans, n_outputs, n_times, ...])

Deep ConvNet model from Schirrmeister et al 2017.

DeepSleepNet([n_outputs, return_feats, ...])

Sleep staging architecture from Supratak et al 2017.

EEGConformer([n_outputs, n_chans, ...])

EEG Conformer.

EEGInception([n_chans, n_outputs, n_times, ...])

EEG Inception for ERP-based classification

EEGInceptionERP([n_chans, n_outputs, ...])

EEG Inception for ERP-based classification

EEGInceptionMI([n_chans, n_outputs, ...])

EEG Inception for Motor Imagery, as proposed in [Rc36ed781f4f5-1]

ATCNet([n_chans, n_outputs, ...])

ATCNet model from [R2ecdb73d6ab9-1]

EEGITNet([n_outputs, n_chans, n_times, ...])

EEG-ITNet: An Explainable Inception Temporal

EEGNetv1([n_chans, n_outputs, n_times, ...])

EEGNet model from Lawhern et al. 2016.

EEGNetv4([n_chans, n_outputs, n_times, ...])

EEGNet v4 model from Lawhern et al 2018.

HybridNet([n_chans, n_outputs, n_times, ...])

Hybrid ConvNet model from Schirrmeister et al 2017.

EEGResNet([n_chans, n_outputs, n_times, ...])

Residual Network for EEG.

TCN([n_chans, n_outputs, n_blocks, ...])

Temporal Convolutional Network (TCN) from Bai et al 2018.

SleepStagerChambon2018([n_chans, sfreq, ...])

Sleep staging architecture from Chambon et al 2018.

SleepStagerBlanco2020([n_chans, sfreq, ...])

Sleep staging architecture from Blanco et al 2020.

SleepStagerEldele2021([sfreq, n_tce, ...])

Sleep Staging Architecture from Eldele et al 2021.

USleep([n_chans, sfreq, depth, ...])

Sleep staging architecture from Perslev et al 2021.

TIDNet([n_chans, n_outputs, n_times, ...])

Thinker Invariance DenseNet model from Kostas et al 2020.

get_output_shape(model, in_chans, ...)

Returns shape of neural network output for batch size equal 1.

TimeDistributed(module)

Apply module on multiple windows.

Training#

braindecode.training:

CroppedLoss(loss_function)

Compute Loss after averaging predictions across time.

TimeSeriesLoss(loss_function)

Compute Loss between timeseries targets and predictions.

CroppedTrialEpochScoring(scoring[, ...])

Class to compute scores for trials from a model that predicts (super)crops.

CroppedTimeSeriesEpochScoring(scoring[, ...])

Class to compute scores for trials from a model that predicts (super)crops with time series target.

PostEpochTrainScoring(scoring[, ...])

Epoch Scoring class that recomputes predictions after the epoch on the training in validation mode.

mixup_criterion(preds, target)

Implements loss for Mixup for EEG data.

trial_preds_from_window_preds(preds, ...)

Assigning window predictions to trials while removing duplicate predictions.

predict_trials(module, dataset[, ...])

Create trialwise predictions and optionally also return trialwise labels from cropped dataset given module.

Datasets#

braindecode.datasets:

BaseDataset(raw[, description, target_name, ...])

Returns samples from an mne.io.Raw object along with a target.

BaseConcatDataset(list_of_ds[, target_transform])

A base class for concatenated datasets.

WindowsDataset(windows[, description, ...])

Returns windows from an mne.Epochs object along with a target.

MOABBDataset(dataset_name, subject_ids[, ...])

A class for moabb datasets.

HGD(subject_ids)

High-gamma dataset described in Schirrmeister et al. 2017.

BNCI2014001(subject_ids)

BNCI 2014-001 Motor Imagery dataset.

TUH(path[, recording_ids, target_name, ...])

Temple University Hospital (TUH) EEG Corpus (www.isip.piconepress.com/projects/tuh_eeg/html/downloads.shtml#c_tueg).

TUHAbnormal(path[, recording_ids, ...])

Temple University Hospital (TUH) Abnormal EEG Corpus.

SleepPhysionet([subject_ids, recording_ids, ...])

Sleep Physionet dataset.

BCICompetitionIVDataset4([subject_ids])

BCI competition IV dataset 4.

create_from_X_y(X, y, drop_last_window, sfreq)

Create a BaseConcatDataset of WindowsDatasets from X and y to be used for decoding with skorch and braindecode, where X is a list of pre-cut trials and y are corresponding targets.

create_from_mne_raw(raws, ...[, ...])

Create WindowsDatasets from mne.RawArrays

create_from_mne_epochs(list_of_epochs, ...)

Create WindowsDatasets from mne.Epochs

Preprocessing#

braindecode.preprocessing:

create_windows_from_events(concat_ds[, ...])

Create windows based on events in mne.Raw.

create_fixed_length_windows(concat_ds[, ...])

Windower that creates sliding windows.

create_windows_from_target_channels(concat_ds)

exponential_moving_demean(data[, ...])

Perform exponential moving demeanining.

exponential_moving_standardize(data[, ...])

Perform exponential moving standardization.

filterbank(raw, frequency_bands[, ...])

Applies multiple bandpass filters to the signals in raw.

preprocess(concat_ds, preprocessors[, ...])

Apply preprocessors to a concat dataset.

Preprocessor(fn, *[, apply_on_array])

Preprocessor for an MNE Raw or Epochs object.

Resample([up, down, npad, axis, window, ...])

Resample an array.

DropChannels(ch_names[, on_missing])

Drop channel(s).

SetEEGReference([ref_channels, projection, ...])

Specify which reference to use for EEG data.

Filter(l_freq, h_freq[, picks, ...])

Filter a subset of channels.

Pick(picks[, exclude, verbose])

Pick a subset of channels.

Crop([tmin, tmax, include_tmax, verbose])

Crop raw data file.

Data Utils#

braindecode.datautil:

save_concat_dataset(path, concat_dataset[, ...])

load_concat_dataset(path, preload[, ...])

Load a stored BaseConcatDataset of BaseDatasets or WindowsDatasets from files.

Samplers#

braindecode.samplers:

RecordingSampler(metadata[, random_state])

Base sampler simplifying sampling from recordings.

SequenceSampler(metadata, n_windows, ...[, ...])

Sample sequences of consecutive windows.

RelativePositioningSampler(metadata, ...[, ...])

Sample examples for the relative positioning task from [R0467437a2408-Banville2020].

BalancedSequenceSampler(metadata, n_windows)

Balanced sampling of sequences of consecutive windows with categorical targets.

Augmentation#

braindecode.augmentation:

Transform([probability, random_state])

Basic transform class used for implementing data augmentation operations.

IdentityTransform([probability, random_state])

Identity transform.

Compose(transforms)

Transform composition.

AugmentedDataLoader(dataset[, transforms, ...])

A base dataloader class customized to applying augmentation Transforms.

TimeReverse(probability[, random_state])

Flip the time axis of each input with a given probability.

SignFlip(probability[, random_state])

Flip the sign axis of each input with a given probability.

FTSurrogate(probability[, ...])

FT surrogate augmentation of a single EEG channel, as proposed in [Ra7c6c14d9bd9-1].

ChannelsShuffle(probability[, p_shuffle, ...])

Randomly shuffle channels in EEG data matrix.

ChannelsDropout(probability[, p_drop, ...])

Randomly set channels to flat signal.

GaussianNoise(probability[, std, random_state])

Randomly add white noise to all channels.

ChannelsSymmetry(probability, ordered_ch_names)

Permute EEG channels inverting left and right-side sensors.

SmoothTimeMask(probability[, ...])

Smoothly replace a randomly chosen contiguous part of all channels by zeros.

BandstopFilter(probability, sfreq[, ...])

Apply a band-stop filter with desired bandwidth at a randomly selected frequency position between 0 and max_freq.

FrequencyShift(probability, sfreq[, ...])

Add a random shift in the frequency domain to all channels.

SensorsRotation(probability, ...[, axis, ...])

Interpolates EEG signals over sensors rotated around the desired axis with an angle sampled uniformly between -max_degree and max_degree.

SensorsZRotation(probability, ordered_ch_names)

Interpolates EEG signals over sensors rotated around the Z axis with an angle sampled uniformly between -max_degree and max_degree.

SensorsYRotation(probability, ordered_ch_names)

Interpolates EEG signals over sensors rotated around the Y axis with an angle sampled uniformly between -max_degree and max_degree.

SensorsXRotation(probability, ordered_ch_names)

Interpolates EEG signals over sensors rotated around the X axis with an angle sampled uniformly between -max_degree and max_degree.

Mixup(alpha[, beta_per_sample, random_state])

Implements Iterator for Mixup for EEG data.

functional.identity(X, y)

Identity operation.

functional.time_reverse(X, y)

Flip the time axis of each input.

functional.sign_flip(X, y)

Flip the sign axis of each input.

functional.ft_surrogate(X, y, ...[, ...])

FT surrogate augmentation of a single EEG channel, as proposed in [R52a4658fffa7-1].

functional.channels_dropout(X, y, p_drop[, ...])

Randomly set channels to flat signal.

functional.channels_shuffle(X, y, p_shuffle)

Randomly shuffle channels in EEG data matrix.

functional.channels_permute(X, y, permutation)

Permute EEG channels according to fixed permutation matrix.

functional.gaussian_noise(X, y, std[, ...])

Randomly add white Gaussian noise to all channels.

functional.smooth_time_mask(X, y, ...)

Smoothly replace a contiguous part of all channels by zeros.

functional.bandstop_filter(X, y, sfreq, ...)

Apply a band-stop filter with desired bandwidth at the desired frequency position.

functional.frequency_shift(X, y, delta_freq, ...)

Adds a shift in the frequency domain to all channels.

functional.sensors_rotation(X, y, ...)

Interpolates EEG signals over sensors rotated around the desired axis with the desired angle.

functional.mixup(X, y, lam, idx_perm)

Mixes two channels of EEG data.

Utils#

braindecode.util:

set_random_seeds(seed, cuda[, cudnn_benchmark])

Set seeds for python random module numpy.random and torch.

Visualization#

braindecode.visualization:

compute_amplitude_gradients(model, dataset, ...)

plot_confusion_matrix(confusion_mat[, ...])

Generates a confusion matrix with additional precision and sensitivity metrics as in [R8046536b33dd-1].