braindecode 2.1.0.dev179572252__tar.gz → 2.1.0.dev181162869__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {braindecode-2.1.0.dev179572252/braindecode.egg-info → braindecode-2.1.0.dev181162869}/PKG-INFO +1 -1
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/base.py +10 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/biot.py +30 -6
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/labram.py +104 -25
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/luna.py +70 -12
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/reve.py +68 -11
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/modules/linear_attention.py +27 -10
- braindecode-2.1.0.dev181162869/braindecode/version.py +1 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869/braindecode.egg-info}/PKG-INFO +1 -1
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/docs/whats_new.rst +8 -0
- braindecode-2.1.0.dev179572252/braindecode/version.py +0 -1
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/LICENSE.txt +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/MANIFEST.in +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/NOTICE.txt +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/README.rst +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/__init__.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/augmentation/__init__.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/augmentation/base.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/augmentation/functional.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/augmentation/transforms.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/classifier.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/datasets/__init__.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/datasets/_notebook_viewer.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/datasets/base.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/datasets/bbci.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/datasets/bcicomp.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/datasets/bids/__init__.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/datasets/bids/datasets.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/datasets/bids/hub.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/datasets/bids/hub_format.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/datasets/bids/hub_io.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/datasets/bids/hub_validation.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/datasets/bids/iterable.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/datasets/chb_mit.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/datasets/collate.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/datasets/mne.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/datasets/moabb.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/datasets/nmt.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/datasets/registry.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/datasets/siena.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/datasets/sleep_physio_challe_18.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/datasets/sleep_physionet.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/datasets/tuh.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/datasets/utils.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/datasets/xy.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/datautil/__init__.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/datautil/channel_utils.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/datautil/hub_formats.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/datautil/serialization.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/datautil/util.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/eegneuralnet.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/functional/__init__.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/functional/_lfilter.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/functional/_real_dft.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/functional/attention.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/functional/channel_mask.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/functional/functions.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/functional/initialization.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/functional/patches.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/__init__.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/atcnet.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/attentionbasenet.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/attn_sleep.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/axon.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/barista.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/bendr.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/brainbert.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/brainmodule.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/brainomni.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/brant.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/cbramod.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/codebrain.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/config.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/contrawr.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/csbrain.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/ctnet.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/dance.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/deep4.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/deepsleepnet.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/dgcnn.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/diver1.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/duin.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/eeg_clip.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/eegconformer.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/eegdino.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/eeginception_erp.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/eeginception_mi.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/eegitnet.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/eegminer.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/eegnet.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/eegnex.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/eegpt.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/eegsimpleconv.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/eegsym.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/eegtcnet.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/emg2qwerty.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/epint.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/fbcnet.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/fblightconvnet.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/fbmsnet.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/gcnsnet.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/guetschel2026.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/hybrid.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/ifnet.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/mapa.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/medformer.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/meta_neuromotor.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/mirepnet.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/mscformer.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/msvtnet.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/mvpformer.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/neuropose.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/neurorvq.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/neurorvq_tokenizer.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/patchedtransformer.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/popt.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/sccnet.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/seizure_transformer.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/sensingdynamics.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/shallow_fbcsp.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/signal_jepa.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/sinc_shallow.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/sleep_stager_blanco_2020.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/sleep_stager_chambon_2018.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/sleepfm.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/sparcnet.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/sstdpn.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/steegformer.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/summary.csv +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/syncnet.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/tcformer.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/tcn.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/tfm_tokenizer.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/tidnet.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/tmsanet.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/tsinception.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/usleep.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/util.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/vemg2pose.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/zuna.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/modules/__init__.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/modules/activation.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/modules/attention.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/modules/blocks.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/modules/channels.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/modules/convolution.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/modules/dance_modules.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/modules/filter.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/modules/layers.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/modules/linear.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/modules/parametrization.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/modules/quantization.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/modules/stats.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/modules/util.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/modules/wrapper.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/preprocessing/__init__.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/preprocessing/eegprep_preprocess.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/preprocessing/mne_preprocess.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/preprocessing/preprocess.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/preprocessing/util.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/preprocessing/windowers.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/regressor.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/samplers/__init__.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/samplers/base.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/samplers/ssl.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/training/__init__.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/training/_trial_aggregation.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/training/callbacks.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/training/losses.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/training/scoring.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/util.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/visualization/__init__.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/visualization/activations.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/visualization/attribution.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/visualization/confusion_matrices.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/visualization/frequency.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/visualization/metrics.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/visualization/sanity.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/visualization/topology.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode.egg-info/SOURCES.txt +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode.egg-info/dependency_links.txt +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode.egg-info/requires.txt +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode.egg-info/top_level.txt +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/docs/Makefile +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/docs/_templates/autosummary/class.rst +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/docs/_templates/autosummary/class_in_subdir.rst +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/docs/_templates/autosummary/function.rst +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/docs/_templates/autosummary/function_in_subdir.rst +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/docs/agent_docs.rst +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/docs/api.rst +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/docs/cite.rst +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/docs/conf.py +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/docs/help.rst +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/docs/index.rst +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/docs/install/install.rst +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/docs/install/install_pip.rst +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/docs/install/install_source.rst +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/docs/models/categorization/attention.rst +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/docs/models/categorization/channel.rst +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/docs/models/categorization/convolution.rst +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/docs/models/categorization/filterbank.rst +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/docs/models/categorization/gnn.rst +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/docs/models/categorization/interpretable.rst +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/docs/models/categorization/lbm.rst +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/docs/models/categorization/recurrent.rst +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/docs/models/categorization/spd.rst +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/docs/models/models.rst +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/docs/models/models_categorization.rst +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/docs/models/models_table.rst +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/docs/models/models_visualization.rst +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/docs/sg_execution_times.rst +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/docs/user_guide/channel_strategies.rst +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/docs/user_guide/cropped_inference.rst +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/pyproject.toml +0 -0
- {braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/setup.cfg +0 -0
{braindecode-2.1.0.dev179572252/braindecode.egg-info → braindecode-2.1.0.dev181162869}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: braindecode
|
|
3
|
-
Version: 2.1.0.
|
|
3
|
+
Version: 2.1.0.dev181162869
|
|
4
4
|
Summary: Deep learning software to decode EEG, ECG or MEG signals
|
|
5
5
|
Author-email: Robin Tibor Schirrmeister <robintibor@gmail.com>, Bruno Aristimunha Pinto <b.aristimunha@gmail.com>, Alexandre Gramfort <agramfort@meta.com>
|
|
6
6
|
Maintainer-email: Alexandre Gramfort <agramfort@meta.com>, Bruno Aristimunha Pinto <b.aristimunha@gmail.com>, Robin Tibor Schirrmeister <robintibor@gmail.com>
|
{braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/base.py
RENAMED
|
@@ -484,6 +484,16 @@ class EEGModuleMixin(_BaseHubMixin, metaclass=_BraindecodeDocstringMeta):
|
|
|
484
484
|
def _channel_forward(self, *args, chs_info=None, ch_names=None, **kwargs):
|
|
485
485
|
"""``forward`` under a channel strategy: map ``x`` (recorded with
|
|
486
486
|
``chs_info``, default the model's) onto the target, then run the backbone."""
|
|
487
|
+
bound = inspect.signature(type(self).forward).bind_partial(
|
|
488
|
+
self, *args, **kwargs
|
|
489
|
+
)
|
|
490
|
+
if bound.arguments.get("ch_mask") is not None:
|
|
491
|
+
# The channel layer mixes every input channel into each target one,
|
|
492
|
+
# so padding would leak into the real channels.
|
|
493
|
+
raise ValueError(
|
|
494
|
+
"ch_mask needs channel_strategy='native': the channel layer maps "
|
|
495
|
+
"all input channels, padded ones included, onto the target montage."
|
|
496
|
+
)
|
|
487
497
|
if chs_info is None and ch_names is not None: # LaBraM: names of x's channels
|
|
488
498
|
chs_info = [{"ch_name": n} for n in ch_names]
|
|
489
499
|
if args:
|
{braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/biot.py
RENAMED
|
@@ -4,7 +4,7 @@ from warnings import warn
|
|
|
4
4
|
import torch
|
|
5
5
|
import torch.nn as nn
|
|
6
6
|
|
|
7
|
-
from braindecode.functional import spectral_input
|
|
7
|
+
from braindecode.functional import check_ch_mask, masked_mean, spectral_input
|
|
8
8
|
from braindecode.models.base import EEGModuleMixin
|
|
9
9
|
from braindecode.models.util import warn_if_sfreq_differs
|
|
10
10
|
from braindecode.modules import SinusoidalPositionalEncoding
|
|
@@ -239,7 +239,10 @@ class BIOT(EEGModuleMixin, nn.Module):
|
|
|
239
239
|
)
|
|
240
240
|
|
|
241
241
|
def forward(
|
|
242
|
-
self,
|
|
242
|
+
self,
|
|
243
|
+
x: torch.Tensor,
|
|
244
|
+
return_features: bool = False,
|
|
245
|
+
ch_mask: Optional[torch.Tensor] = None,
|
|
243
246
|
) -> Union[
|
|
244
247
|
torch.Tensor,
|
|
245
248
|
Tuple[torch.Tensor, torch.Tensor],
|
|
@@ -256,6 +259,10 @@ class BIOT(EEGModuleMixin, nn.Module):
|
|
|
256
259
|
return_features : bool
|
|
257
260
|
If True, return a dict with ``"features"`` and ``"cls_token"``
|
|
258
261
|
instead of the classification output.
|
|
262
|
+
ch_mask : torch.Tensor, optional
|
|
263
|
+
``(batch, n_chans)`` mask of real channels, see
|
|
264
|
+
:func:`~braindecode.functional.check_ch_mask`. Padded channels are
|
|
265
|
+
never attended to nor pooled; channel tokens follow the position.
|
|
259
266
|
|
|
260
267
|
Returns
|
|
261
268
|
-------
|
|
@@ -266,7 +273,7 @@ class BIOT(EEGModuleMixin, nn.Module):
|
|
|
266
273
|
If legacy ``return_feature=True`` (init param):
|
|
267
274
|
``(out, emb)`` tuple (ignored when ``return_features=True``).
|
|
268
275
|
"""
|
|
269
|
-
emb = self.encoder(x)
|
|
276
|
+
emb = self.encoder(x, ch_mask=check_ch_mask(ch_mask, x))
|
|
270
277
|
|
|
271
278
|
if return_features:
|
|
272
279
|
out: Dict[str, Optional[torch.Tensor]] = {
|
|
@@ -462,7 +469,13 @@ class _BIOTEncoder(nn.Module):
|
|
|
462
469
|
)
|
|
463
470
|
return torch.abs(spectral).to(sample)
|
|
464
471
|
|
|
465
|
-
def forward(
|
|
472
|
+
def forward(
|
|
473
|
+
self,
|
|
474
|
+
x,
|
|
475
|
+
n_channel_offset: int = 0,
|
|
476
|
+
perturb: bool = False,
|
|
477
|
+
ch_mask: Optional[torch.Tensor] = None,
|
|
478
|
+
):
|
|
466
479
|
"""
|
|
467
480
|
Forward pass of the BIOT encoder.
|
|
468
481
|
|
|
@@ -493,6 +506,9 @@ class _BIOTEncoder(nn.Module):
|
|
|
493
506
|
perturb: bool (default False)
|
|
494
507
|
Randomly select a number of time steps and reduce the
|
|
495
508
|
channel embedding to those time steps.
|
|
509
|
+
ch_mask: Tensor, optional
|
|
510
|
+
(batch_size, n_channels) boolean mask of real channels, already
|
|
511
|
+
checked.
|
|
496
512
|
|
|
497
513
|
Returns
|
|
498
514
|
-------
|
|
@@ -500,11 +516,15 @@ class _BIOTEncoder(nn.Module):
|
|
|
500
516
|
(batch_size, emb_size)
|
|
501
517
|
"""
|
|
502
518
|
batch_size, n_chans, n_times = x.shape
|
|
519
|
+
if ch_mask is not None:
|
|
520
|
+
# Padding may hold NaN, which the STFT would spread.
|
|
521
|
+
x = x.masked_fill(~ch_mask[:, :, None], 0.0)
|
|
503
522
|
# One spectrogram for all channels, channel-major so that each
|
|
504
523
|
# channel's (batch, freq, ts) block is contiguous
|
|
505
524
|
spec = self.stft(x.transpose(0, 1).reshape(n_chans * batch_size, 1, n_times))
|
|
506
525
|
spec = spec.unflatten(0, [n_chans, batch_size])
|
|
507
526
|
emb_seq = []
|
|
527
|
+
token_masks = []
|
|
508
528
|
for i in range(n_chans):
|
|
509
529
|
# Getting the spectrogram
|
|
510
530
|
channel_spec_emb = spec[i]
|
|
@@ -543,10 +563,14 @@ class _BIOTEncoder(nn.Module):
|
|
|
543
563
|
selected_ts = torch.randperm(ts)[:ts_new]
|
|
544
564
|
channel_emb = channel_emb[:, selected_ts]
|
|
545
565
|
emb_seq.append(channel_emb)
|
|
566
|
+
if ch_mask is not None:
|
|
567
|
+
token_masks.append(ch_mask[:, i, None].expand(-1, channel_emb.shape[1]))
|
|
546
568
|
|
|
547
569
|
# Concat and transformer
|
|
548
570
|
# (batch_size, 16 * ts, emb)
|
|
549
571
|
emb = torch.cat(emb_seq, dim=1)
|
|
572
|
+
token_mask: Optional[torch.Tensor] = None
|
|
573
|
+
if ch_mask is not None:
|
|
574
|
+
token_mask = torch.cat(token_masks, dim=1)
|
|
550
575
|
# (batch_size, emb)
|
|
551
|
-
|
|
552
|
-
return emb
|
|
576
|
+
return masked_mean(self.transformer(emb, token_mask), token_mask, [1])
|
{braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/labram.py
RENAMED
|
@@ -16,7 +16,13 @@ import torch.nn as nn
|
|
|
16
16
|
from einops.layers.torch import Rearrange
|
|
17
17
|
from torch.nn.init import trunc_normal_
|
|
18
18
|
|
|
19
|
-
from braindecode.functional import
|
|
19
|
+
from braindecode.functional import (
|
|
20
|
+
check_ch_mask,
|
|
21
|
+
init_weights_,
|
|
22
|
+
masked_group_norm,
|
|
23
|
+
masked_mean,
|
|
24
|
+
rescale_parameter,
|
|
25
|
+
)
|
|
20
26
|
from braindecode.functional.attention import _hpu_eager_fused_sdpa
|
|
21
27
|
from braindecode.models.base import EEGModuleMixin
|
|
22
28
|
from braindecode.modules import MLP, DropPath
|
|
@@ -636,6 +642,7 @@ class Labram(EEGModuleMixin, nn.Module):
|
|
|
636
642
|
input_chans,
|
|
637
643
|
return_patch_tokens: bool = False,
|
|
638
644
|
return_all_tokens: bool = False,
|
|
645
|
+
ch_mask: Optional[torch.Tensor] = None,
|
|
639
646
|
):
|
|
640
647
|
"""
|
|
641
648
|
Forward the features of the model.
|
|
@@ -650,6 +657,8 @@ class Labram(EEGModuleMixin, nn.Module):
|
|
|
650
657
|
Whether to return the patch tokens.
|
|
651
658
|
return_all_tokens : bool
|
|
652
659
|
Whether to return all the tokens.
|
|
660
|
+
ch_mask : torch.Tensor, optional
|
|
661
|
+
``(batch, n_chans)`` boolean mask of real channels, already checked.
|
|
653
662
|
|
|
654
663
|
Returns
|
|
655
664
|
-------
|
|
@@ -657,11 +666,23 @@ class Labram(EEGModuleMixin, nn.Module):
|
|
|
657
666
|
The output of the model.
|
|
658
667
|
"""
|
|
659
668
|
batch_size, n_input_chans, _ = x.shape
|
|
669
|
+
token_mask: Optional[torch.Tensor] = None
|
|
670
|
+
key_mask: Optional[torch.Tensor] = None
|
|
671
|
+
if ch_mask is not None:
|
|
672
|
+
# Padding may hold NaN, which the patch embedding would spread.
|
|
673
|
+
x = x.masked_fill(~ch_mask[:, :, None], 0.0)
|
|
674
|
+
# Tokens are (channel, patch), channel outermost; [CLS] is real.
|
|
675
|
+
token_mask = ch_mask.repeat_interleave(self.patch_embed[0].n_patchs, dim=1)
|
|
676
|
+
key_mask = torch.cat(
|
|
677
|
+
[token_mask.new_ones(batch_size, 1), token_mask], dim=1
|
|
678
|
+
)
|
|
660
679
|
|
|
661
680
|
if self.neural_tokenizer:
|
|
662
681
|
# For neural tokenizer: input is (batch, n_chans, n_times)
|
|
663
682
|
# patch_embed returns (batch, n_chans, emb_dim)
|
|
664
|
-
x = self.patch_embed(
|
|
683
|
+
x = self.patch_embed.temporal_conv(
|
|
684
|
+
self.patch_embed.segment_patch(x), ch_mask
|
|
685
|
+
)
|
|
665
686
|
# x shape: (batch, n_chans, emb_dim)
|
|
666
687
|
n_patch = n_input_chans # Use actual input channels, not self.n_chans
|
|
667
688
|
temporal = self.embed_dim
|
|
@@ -730,24 +751,20 @@ class Labram(EEGModuleMixin, nn.Module):
|
|
|
730
751
|
x = self.pos_drop(x)
|
|
731
752
|
|
|
732
753
|
for blk in self.blocks:
|
|
733
|
-
out = blk(x)
|
|
754
|
+
out = blk(x, key_mask=key_mask)
|
|
734
755
|
assert isinstance(out, torch.Tensor) # narrows the Union for TorchScript
|
|
735
756
|
x = out
|
|
736
757
|
|
|
737
758
|
x = self.norm(x)
|
|
738
759
|
if self.fc_norm is not None:
|
|
739
|
-
if return_all_tokens:
|
|
740
|
-
return self.fc_norm(x)
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
return self.fc_norm(tokens)
|
|
744
|
-
return self.fc_norm(tokens.mean(1))
|
|
745
|
-
else:
|
|
746
|
-
if return_all_tokens:
|
|
747
|
-
return x
|
|
748
|
-
elif return_patch_tokens:
|
|
749
|
-
return x[:, 1:]
|
|
760
|
+
if not (return_all_tokens or return_patch_tokens):
|
|
761
|
+
return self.fc_norm(masked_mean(x[:, 1:, :], token_mask, [1]))
|
|
762
|
+
x = self.fc_norm(x)
|
|
763
|
+
elif not (return_all_tokens or return_patch_tokens):
|
|
750
764
|
return x[:, 0]
|
|
765
|
+
if key_mask is not None:
|
|
766
|
+
x = x.masked_fill(~key_mask[:, :, None], 0.0)
|
|
767
|
+
return x if return_all_tokens else x[:, 1:]
|
|
751
768
|
|
|
752
769
|
def forward(
|
|
753
770
|
self,
|
|
@@ -756,6 +773,7 @@ class Labram(EEGModuleMixin, nn.Module):
|
|
|
756
773
|
return_all_tokens: bool = False,
|
|
757
774
|
return_features: bool = False,
|
|
758
775
|
ch_names: Optional[List[str]] = None,
|
|
776
|
+
ch_mask: Optional[torch.Tensor] = None,
|
|
759
777
|
) -> Union[torch.Tensor, Dict[str, torch.Tensor]]:
|
|
760
778
|
"""
|
|
761
779
|
Forward the input EEG data through the model.
|
|
@@ -770,8 +788,10 @@ class Labram(EEGModuleMixin, nn.Module):
|
|
|
770
788
|
return_all_tokens: bool
|
|
771
789
|
Return all the tokens
|
|
772
790
|
return_features : bool
|
|
773
|
-
If True, return a dict with ``"features"`` (patch tokens)
|
|
774
|
-
``"cls_token"``
|
|
791
|
+
If True, return a dict with ``"features"`` (patch tokens),
|
|
792
|
+
``"cls_token"`` and ``"tokens"``, the patch tokens as ``(batch,
|
|
793
|
+
n_chans, n_patches, embed_dim)`` (one row in decoder mode), instead of
|
|
794
|
+
the classification output. Token outputs are zero for padded channels.
|
|
775
795
|
ch_names : list of str, optional
|
|
776
796
|
Channel names matching the channel axis of ``x``.
|
|
777
797
|
Matched case-insensitively against :data:`LABRAM_CHANNEL_ORDER`
|
|
@@ -782,12 +802,22 @@ class Labram(EEGModuleMixin, nn.Module):
|
|
|
782
802
|
a :class:`ValueError` is raised. Only honored when
|
|
783
803
|
``neural_tokenizer=True``; in decoder mode the position
|
|
784
804
|
embedding is sequential and ``ch_names`` has no effect.
|
|
805
|
+
ch_mask : torch.Tensor, optional
|
|
806
|
+
``(batch, n_chans)`` mask of real channels, see
|
|
807
|
+
:func:`~braindecode.functional.check_ch_mask`. Padded channels affect no
|
|
808
|
+
pooled output. Needs ``neural_tokenizer=True``.
|
|
785
809
|
|
|
786
810
|
Returns
|
|
787
811
|
-------
|
|
788
812
|
torch.Tensor or dict
|
|
789
813
|
The output of the model with dimensions (batch, n_outputs)
|
|
790
814
|
"""
|
|
815
|
+
mask = check_ch_mask(ch_mask, x)
|
|
816
|
+
if mask is not None and not self.neural_tokenizer:
|
|
817
|
+
raise ValueError(
|
|
818
|
+
"ch_mask needs neural_tokenizer=True: the decoder averages the "
|
|
819
|
+
"channels into each token."
|
|
820
|
+
)
|
|
791
821
|
n_canonical = len(self._canonical_index) # len(LABRAM_CHANNEL_ORDER)
|
|
792
822
|
if ch_names is None:
|
|
793
823
|
if x.shape[1] != n_canonical:
|
|
@@ -820,12 +850,14 @@ class Labram(EEGModuleMixin, nn.Module):
|
|
|
820
850
|
input_chans = torch.tensor(matched, device=x.device, dtype=torch.long)
|
|
821
851
|
|
|
822
852
|
if return_features:
|
|
853
|
+
n_rows = x.shape[1] if self.neural_tokenizer else 1
|
|
823
854
|
x = self.forward_features(
|
|
824
|
-
x, input_chans=input_chans, return_all_tokens=True
|
|
855
|
+
x, input_chans=input_chans, return_all_tokens=True, ch_mask=mask
|
|
825
856
|
)
|
|
826
857
|
out: Dict[str, torch.Tensor] = {
|
|
827
858
|
"features": x[:, 1:, :],
|
|
828
859
|
"cls_token": x[:, 0, :],
|
|
860
|
+
"tokens": x[:, 1:, :].unflatten(1, [n_rows, -1]),
|
|
829
861
|
}
|
|
830
862
|
return out
|
|
831
863
|
|
|
@@ -834,6 +866,7 @@ class Labram(EEGModuleMixin, nn.Module):
|
|
|
834
866
|
input_chans=input_chans,
|
|
835
867
|
return_patch_tokens=return_patch_tokens,
|
|
836
868
|
return_all_tokens=return_all_tokens,
|
|
869
|
+
ch_mask=mask,
|
|
837
870
|
)
|
|
838
871
|
x = self.final_layer(x)
|
|
839
872
|
return x
|
|
@@ -1355,6 +1388,7 @@ class _Attention(nn.Module):
|
|
|
1355
1388
|
x: torch.Tensor,
|
|
1356
1389
|
return_attention: bool = False,
|
|
1357
1390
|
return_qkv: bool = False,
|
|
1391
|
+
key_mask: Optional[torch.Tensor] = None,
|
|
1358
1392
|
) -> Union[torch.Tensor, Tuple[torch.Tensor, torch.Tensor]]:
|
|
1359
1393
|
"""
|
|
1360
1394
|
Apply the attention mechanism to the input tensor.
|
|
@@ -1368,6 +1402,8 @@ class _Attention(nn.Module):
|
|
|
1368
1402
|
return_qkv: bool (default=False)
|
|
1369
1403
|
If True, return the query, key, and value tensors together with
|
|
1370
1404
|
the output tensor.
|
|
1405
|
+
key_mask: torch.Tensor, optional
|
|
1406
|
+
(Batch, N) boolean mask of the keys that take part.
|
|
1371
1407
|
Returns:
|
|
1372
1408
|
--------
|
|
1373
1409
|
x: torch.Tensor
|
|
@@ -1410,6 +1446,11 @@ class _Attention(nn.Module):
|
|
|
1410
1446
|
attn_mask = (
|
|
1411
1447
|
relative_position_bias.permute(2, 0, 1).contiguous().unsqueeze(0)
|
|
1412
1448
|
) # 1, nH, Wh*Ww, Wh*Ww
|
|
1449
|
+
if key_mask is not None:
|
|
1450
|
+
key_bias = torch.zeros(
|
|
1451
|
+
key_mask.shape, dtype=q.dtype, device=q.device
|
|
1452
|
+
).masked_fill(~key_mask, float("-inf"))[:, None, None, :]
|
|
1453
|
+
attn_mask = key_bias if attn_mask is None else attn_mask + key_bias
|
|
1413
1454
|
|
|
1414
1455
|
# Fused kernel, same math. Not with attention dropout in training (it
|
|
1415
1456
|
# would draw other masks). On Gaudi, torch's SDPA trains ~12 % slower
|
|
@@ -1549,7 +1590,11 @@ class _WindowsAttentionBlock(nn.Module):
|
|
|
1549
1590
|
self.gamma_1, self.gamma_2 = None, None
|
|
1550
1591
|
|
|
1551
1592
|
def forward(
|
|
1552
|
-
self,
|
|
1593
|
+
self,
|
|
1594
|
+
x,
|
|
1595
|
+
return_attention: bool = False,
|
|
1596
|
+
return_qkv: bool = False,
|
|
1597
|
+
key_mask: Optional[torch.Tensor] = None,
|
|
1553
1598
|
) -> Union[torch.Tensor, Tuple[torch.Tensor, torch.Tensor]]:
|
|
1554
1599
|
"""
|
|
1555
1600
|
Apply the attention mechanism to the input tensor.
|
|
@@ -1562,6 +1607,8 @@ class _WindowsAttentionBlock(nn.Module):
|
|
|
1562
1607
|
return_qkv: bool (default=False)
|
|
1563
1608
|
If True, return the query, key, and value tensors together with
|
|
1564
1609
|
the output tensor.
|
|
1610
|
+
key_mask: torch.Tensor, optional
|
|
1611
|
+
(Batch, N) boolean mask of the keys that take part.
|
|
1565
1612
|
|
|
1566
1613
|
Returns
|
|
1567
1614
|
-------
|
|
@@ -1570,16 +1617,16 @@ class _WindowsAttentionBlock(nn.Module):
|
|
|
1570
1617
|
"""
|
|
1571
1618
|
|
|
1572
1619
|
if return_attention:
|
|
1573
|
-
return self.attn(self.norm1(x), return_attention=True)
|
|
1620
|
+
return self.attn(self.norm1(x), return_attention=True, key_mask=key_mask)
|
|
1574
1621
|
if return_qkv:
|
|
1575
|
-
out = self.attn(self.norm1(x), return_qkv=return_qkv)
|
|
1622
|
+
out = self.attn(self.norm1(x), return_qkv=return_qkv, key_mask=key_mask)
|
|
1576
1623
|
assert isinstance(out, tuple) # narrows the Union for TorchScript
|
|
1577
1624
|
y, qkv = out
|
|
1578
1625
|
x = x + self.drop_path(self.gamma_1 * y)
|
|
1579
1626
|
x = x + self.drop_path(self.gamma_2 * self.mlp(self.norm2(x)))
|
|
1580
1627
|
return x, qkv
|
|
1581
1628
|
|
|
1582
|
-
y = self.attn(self.norm1(x))
|
|
1629
|
+
y = self.attn(self.norm1(x), key_mask=key_mask)
|
|
1583
1630
|
assert isinstance(y, torch.Tensor) # narrows the Union for TorchScript
|
|
1584
1631
|
if self.gamma_1 is None:
|
|
1585
1632
|
x = x + self.drop_path(y)
|
|
@@ -1678,7 +1725,7 @@ class _TemporalConv(nn.Module):
|
|
|
1678
1725
|
|
|
1679
1726
|
self.transpose_temporal_channel = Rearrange("Batch C NA T -> Batch NA (T C)")
|
|
1680
1727
|
|
|
1681
|
-
def forward(self, x):
|
|
1728
|
+
def forward(self, x, ch_mask: Optional[torch.Tensor] = None):
|
|
1682
1729
|
"""
|
|
1683
1730
|
Apply 3 steps of 2D convolution, GELU activation function,
|
|
1684
1731
|
and GroupNorm.
|
|
@@ -1687,15 +1734,47 @@ class _TemporalConv(nn.Module):
|
|
|
1687
1734
|
-----------
|
|
1688
1735
|
x: torch.Tensor
|
|
1689
1736
|
Input tensor of shape (Batch, Channels, n_patchs, size_patch).
|
|
1737
|
+
ch_mask: torch.Tensor, optional
|
|
1738
|
+
(Batch, Channels) boolean mask of real channels; padded channels
|
|
1739
|
+
then take no part in the GroupNorm statistics.
|
|
1690
1740
|
|
|
1691
1741
|
Returns:
|
|
1692
1742
|
--------
|
|
1693
1743
|
x: torch.Tensor
|
|
1694
1744
|
Output tensor of shape (Batch, NA, Temporal Channel).
|
|
1695
1745
|
"""
|
|
1746
|
+
row_mask: Optional[torch.Tensor] = None
|
|
1747
|
+
if ch_mask is not None:
|
|
1748
|
+
# Flattened rows are (chs npat), channel outermost.
|
|
1749
|
+
row_mask = ch_mask.repeat_interleave(x.shape[2], dim=1)
|
|
1696
1750
|
x = self.channel_patch_flatten(x)
|
|
1697
|
-
x = self.
|
|
1698
|
-
x =
|
|
1699
|
-
|
|
1751
|
+
x = self.conv1(x)
|
|
1752
|
+
x = masked_group_norm(
|
|
1753
|
+
x,
|
|
1754
|
+
self.norm1.num_groups,
|
|
1755
|
+
row_mask,
|
|
1756
|
+
self.norm1.weight,
|
|
1757
|
+
self.norm1.bias,
|
|
1758
|
+
self.norm1.eps,
|
|
1759
|
+
)
|
|
1760
|
+
x = self.conv2(self.act_layer_1(x))
|
|
1761
|
+
x = masked_group_norm(
|
|
1762
|
+
x,
|
|
1763
|
+
self.norm2.num_groups,
|
|
1764
|
+
row_mask,
|
|
1765
|
+
self.norm2.weight,
|
|
1766
|
+
self.norm2.bias,
|
|
1767
|
+
self.norm2.eps,
|
|
1768
|
+
)
|
|
1769
|
+
x = self.conv3(self.act_layer_2(x))
|
|
1770
|
+
x = masked_group_norm(
|
|
1771
|
+
x,
|
|
1772
|
+
self.norm3.num_groups,
|
|
1773
|
+
row_mask,
|
|
1774
|
+
self.norm3.weight,
|
|
1775
|
+
self.norm3.bias,
|
|
1776
|
+
self.norm3.eps,
|
|
1777
|
+
)
|
|
1778
|
+
x = self.act_layer_3(x)
|
|
1700
1779
|
x = self.transpose_temporal_channel(x)
|
|
1701
1780
|
return x
|
{braindecode-2.1.0.dev179572252 → braindecode-2.1.0.dev181162869}/braindecode/models/luna.py
RENAMED
|
@@ -25,7 +25,9 @@ import torch.nn.functional as F
|
|
|
25
25
|
|
|
26
26
|
from braindecode.functional import (
|
|
27
27
|
apply_rotary,
|
|
28
|
+
check_ch_mask,
|
|
28
29
|
init_weights_,
|
|
30
|
+
masked_group_norm,
|
|
29
31
|
rotary_angles,
|
|
30
32
|
rotary_frequencies,
|
|
31
33
|
spectral_input,
|
|
@@ -136,6 +138,9 @@ class LUNA(EEGModuleMixin, nn.Module, license="apache-2.0"):
|
|
|
136
138
|
Retrieved from https://openreview.net/forum?id=uazfjnFL0G
|
|
137
139
|
"""
|
|
138
140
|
|
|
141
|
+
# Class-level, so TorchScript types the cache while it is still empty.
|
|
142
|
+
_channel_location_cache: Dict[int, torch.Tensor]
|
|
143
|
+
|
|
139
144
|
def __init__(
|
|
140
145
|
self,
|
|
141
146
|
# Braindecode EEGModuleMixin parameters
|
|
@@ -315,13 +320,14 @@ class LUNA(EEGModuleMixin, nn.Module, license="apache-2.0"):
|
|
|
315
320
|
x_signal: torch.Tensor,
|
|
316
321
|
channel_locations: torch.Tensor,
|
|
317
322
|
mask: Optional[torch.Tensor] = None,
|
|
323
|
+
ch_mask: Optional[torch.Tensor] = None,
|
|
318
324
|
) -> Tuple[torch.Tensor, torch.Tensor]:
|
|
319
325
|
num_channels = channel_locations.shape[1]
|
|
320
326
|
x_signal = self.tokenizer.prepare_input(x_signal)
|
|
321
327
|
if mask is not None:
|
|
322
328
|
mask = self.tokenizer.prepare_input(mask)
|
|
323
329
|
num_patches_per_channel = x_signal.shape[-1] // self.patch_size
|
|
324
|
-
x_patched = self.patch_embed(x_signal)
|
|
330
|
+
x_patched = self.patch_embed(x_signal, ch_mask)
|
|
325
331
|
freq_embed = self.freq_embed(x_signal)
|
|
326
332
|
x_patched = x_patched + freq_embed
|
|
327
333
|
x_masked = x_patched.clone() # (B, N, D), N = C * num_patches_per_channel
|
|
@@ -342,8 +348,15 @@ class LUNA(EEGModuleMixin, nn.Module, license="apache-2.0"):
|
|
|
342
348
|
channel_locations = channel_locations.to(
|
|
343
349
|
torch.promote_types(dtype, torch.float32)
|
|
344
350
|
)
|
|
345
|
-
|
|
346
|
-
|
|
351
|
+
lows, highs = channel_locations, channel_locations
|
|
352
|
+
if ch_mask is not None:
|
|
353
|
+
# Padded rows may hold anything; the range spans the real ones.
|
|
354
|
+
padded = ~ch_mask[:, :, None]
|
|
355
|
+
channel_locations = channel_locations.masked_fill(padded, 0.0)
|
|
356
|
+
lows = channel_locations.masked_fill(padded, float("inf"))
|
|
357
|
+
highs = channel_locations.masked_fill(padded, float("-inf"))
|
|
358
|
+
channel_min = torch.min(lows, dim=1, keepdim=True)[0]
|
|
359
|
+
channel_max = torch.max(highs, dim=1, keepdim=True)[0]
|
|
347
360
|
channel_locations = (channel_locations - channel_min) / (
|
|
348
361
|
channel_max - channel_min + 1e-8
|
|
349
362
|
)
|
|
@@ -377,10 +390,28 @@ class LUNA(EEGModuleMixin, nn.Module, license="apache-2.0"):
|
|
|
377
390
|
mask: Optional[torch.Tensor] = None,
|
|
378
391
|
channel_locations: Optional[torch.Tensor] = None,
|
|
379
392
|
channel_names: Optional[torch.Tensor] = None,
|
|
393
|
+
ch_mask: Optional[torch.Tensor] = None,
|
|
380
394
|
) -> torch.Tensor:
|
|
381
|
-
"""Forward pass.
|
|
395
|
+
"""Forward pass.
|
|
396
|
+
|
|
397
|
+
``ch_mask`` is an optional ``(batch, n_chans)`` mask of real channels,
|
|
398
|
+
see :func:`~braindecode.functional.check_ch_mask`: padded channels take
|
|
399
|
+
no part in the patch-embedding norms, the location range and the
|
|
400
|
+
channel cross-attention, so each recording gets its output alone.
|
|
401
|
+
Reconstruction (``n_outputs=0``) refuses it.
|
|
402
|
+
"""
|
|
382
403
|
x_signal = X
|
|
383
404
|
B, C, _ = x_signal.shape
|
|
405
|
+
ch_mask = check_ch_mask(ch_mask, X)
|
|
406
|
+
if ch_mask is not None and self.num_classes == 0:
|
|
407
|
+
raise ValueError(
|
|
408
|
+
"ch_mask needs n_outputs > 0: the reconstruction decoder attends "
|
|
409
|
+
"across all channels."
|
|
410
|
+
)
|
|
411
|
+
key_padding_mask: Optional[torch.Tensor] = None
|
|
412
|
+
if ch_mask is not None:
|
|
413
|
+
# Padding may hold NaN, which the patch embedding would spread.
|
|
414
|
+
x_signal = x_signal.masked_fill(~ch_mask[:, :, None], 0.0)
|
|
384
415
|
|
|
385
416
|
if channel_locations is None:
|
|
386
417
|
channel_locations = self.get_default_channel_locations(
|
|
@@ -391,9 +422,12 @@ class LUNA(EEGModuleMixin, nn.Module, license="apache-2.0"):
|
|
|
391
422
|
)
|
|
392
423
|
|
|
393
424
|
x, channel_locations_emb = self.prepare_tokens(
|
|
394
|
-
x_signal, channel_locations, mask=mask
|
|
425
|
+
x_signal, channel_locations, mask=mask, ch_mask=ch_mask
|
|
395
426
|
)
|
|
396
|
-
|
|
427
|
+
if ch_mask is not None:
|
|
428
|
+
# Cross-attention rows are (batch, patch), batch outermost.
|
|
429
|
+
key_padding_mask = ~ch_mask.repeat_interleave(x.shape[0] // B, dim=0)
|
|
430
|
+
x, _ = self.cross_attn(x, key_padding_mask)
|
|
397
431
|
x = x.unflatten(0, (B, -1)).flatten(2) # (B * t, Q, D) -> (B, t, Q * D)
|
|
398
432
|
for blk in self.blocks:
|
|
399
433
|
x = blk(x)
|
|
@@ -821,7 +855,9 @@ class _CrossAttentionBlock(nn.Module):
|
|
|
821
855
|
torch.nn.init.orthogonal_(self.query_embed, gain=1.0)
|
|
822
856
|
self.apply(_init_weights)
|
|
823
857
|
|
|
824
|
-
def forward(
|
|
858
|
+
def forward(
|
|
859
|
+
self, x: torch.Tensor, key_padding_mask: Optional[torch.Tensor] = None
|
|
860
|
+
) -> Tuple[torch.Tensor, Optional[torch.Tensor]]:
|
|
825
861
|
# x is the input with shape (batch_size*num_patches, num_channels, embed_dim)
|
|
826
862
|
batch_size, _, _ = x.size()
|
|
827
863
|
queries = self.query_embed.repeat(batch_size, 1, 1)
|
|
@@ -830,7 +866,7 @@ class _CrossAttentionBlock(nn.Module):
|
|
|
830
866
|
values = self.values_norm(x)
|
|
831
867
|
|
|
832
868
|
attention_out, attention_scores = self.cross_attention(
|
|
833
|
-
query=queries, key=keys, value=values
|
|
869
|
+
query=queries, key=keys, value=values, key_padding_mask=key_padding_mask
|
|
834
870
|
) # Shape: (batch_size*num_patches, num_queries, embed_dim)
|
|
835
871
|
attention_out = self.ffn(attention_out) + attention_out
|
|
836
872
|
|
|
@@ -885,14 +921,36 @@ class _PatchEmbedNetwork(nn.Module):
|
|
|
885
921
|
nn.GELU(),
|
|
886
922
|
)
|
|
887
923
|
|
|
888
|
-
def forward(
|
|
924
|
+
def forward(
|
|
925
|
+
self, x: torch.Tensor, ch_mask: Optional[torch.Tensor] = None
|
|
926
|
+
) -> torch.Tensor:
|
|
889
927
|
"""
|
|
890
928
|
x: (B, C, T)
|
|
929
|
+
ch_mask: optional (B, C) boolean mask of real channels; padded ones
|
|
930
|
+
then take no part in the GroupNorm statistics.
|
|
891
931
|
output: (B, C*S, D) where D = embed_dim and S = ceil(T / patch_size)
|
|
892
932
|
for ``on_non_divisible="pad"``, T // patch_size otherwise
|
|
893
933
|
"""
|
|
894
|
-
x = self.tokenizer(x)
|
|
895
|
-
|
|
896
|
-
x =
|
|
934
|
+
x = self.tokenizer(x) # (B, C, S, P)
|
|
935
|
+
n_patches = x.shape[2]
|
|
936
|
+
x = x.flatten(1, 2).unsqueeze(1) # (B, 1, C * S, P)
|
|
937
|
+
if ch_mask is None:
|
|
938
|
+
x = self.proj_in(x)
|
|
939
|
+
else:
|
|
940
|
+
# Rows are (C S), channel outermost.
|
|
941
|
+
row_mask = ch_mask.repeat_interleave(n_patches, dim=1)
|
|
942
|
+
for layer in self.proj_in:
|
|
943
|
+
# Not isinstance: TorchScript misses renamed (mangled) module types.
|
|
944
|
+
if hasattr(layer, "num_groups"):
|
|
945
|
+
x = masked_group_norm(
|
|
946
|
+
x,
|
|
947
|
+
layer.num_groups,
|
|
948
|
+
row_mask,
|
|
949
|
+
layer.weight,
|
|
950
|
+
layer.bias,
|
|
951
|
+
layer.eps,
|
|
952
|
+
)
|
|
953
|
+
else:
|
|
954
|
+
x = layer(x)
|
|
897
955
|
x = x.permute(0, 2, 3, 1).flatten(2) # (B, CS, D * E)
|
|
898
956
|
return x
|