braindecode 1.8.1.dev178155531__tar.gz → 1.8.1.dev178237886__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-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/NOTICE.txt +3 -0
- {braindecode-1.8.1.dev178155531/braindecode.egg-info → braindecode-1.8.1.dev178237886}/PKG-INFO +1 -1
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/augmentation/__init__.py +2 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/augmentation/functional.py +5 -1
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/augmentation/transforms.py +185 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/functional/__init__.py +4 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/functional/functions.py +114 -10
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/attn_sleep.py +5 -11
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/base.py +10 -1
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/bendr.py +28 -5
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/biot.py +25 -15
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/brainbert.py +2 -8
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/brainmodule.py +6 -11
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/brainomni.py +79 -44
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/brant.py +5 -4
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/cbramod.py +22 -20
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/codebrain.py +87 -67
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/csbrain.py +31 -15
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/dance.py +1 -1
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/eegdino.py +10 -10
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/eeginception_mi.py +44 -17
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/eegpt.py +47 -74
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/eegsym.py +17 -1
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/labram.py +59 -43
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/luna.py +34 -30
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/mapa.py +108 -71
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/medformer.py +16 -17
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/meta_neuromotor.py +45 -48
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/mirepnet.py +7 -2
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/msvtnet.py +7 -6
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/mvpformer.py +172 -191
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/neurorvq.py +42 -21
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/neurorvq_tokenizer.py +88 -47
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/patchedtransformer.py +0 -1
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/reve.py +38 -52
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/signal_jepa.py +35 -15
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/sleepfm.py +56 -70
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/sstdpn.py +13 -10
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/steegformer.py +6 -4
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/tcformer.py +25 -48
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/tfm_tokenizer.py +8 -15
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/util.py +8 -5
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/modules/attention.py +4 -4
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/modules/dance_modules.py +34 -26
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/modules/filter.py +3 -14
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/modules/layers.py +12 -21
- braindecode-1.8.1.dev178237886/braindecode/modules/linear_attention.py +128 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/modules/parametrization.py +29 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/modules/quantization.py +45 -35
- braindecode-1.8.1.dev178237886/braindecode/version.py +1 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886/braindecode.egg-info}/PKG-INFO +1 -1
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode.egg-info/SOURCES.txt +1 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/docs/api.rst +4 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/docs/whats_new.rst +104 -0
- braindecode-1.8.1.dev178155531/braindecode/version.py +0 -1
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/LICENSE.txt +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/MANIFEST.in +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/README.rst +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/__init__.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/augmentation/base.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/classifier.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/datasets/__init__.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/datasets/_notebook_viewer.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/datasets/base.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/datasets/bbci.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/datasets/bcicomp.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/datasets/bids/__init__.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/datasets/bids/datasets.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/datasets/bids/format.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/datasets/bids/hub.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/datasets/bids/hub_format.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/datasets/bids/hub_io.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/datasets/bids/hub_validation.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/datasets/bids/iterable.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/datasets/chb_mit.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/datasets/collate.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/datasets/mne.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/datasets/moabb.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/datasets/nmt.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/datasets/registry.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/datasets/siena.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/datasets/sleep_physio_challe_18.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/datasets/sleep_physionet.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/datasets/tuh.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/datasets/utils.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/datasets/xy.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/datautil/__init__.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/datautil/channel_utils.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/datautil/hub_formats.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/datautil/serialization.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/datautil/util.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/eegneuralnet.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/functional/_real_dft.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/functional/initialization.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/__init__.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/atcnet.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/attentionbasenet.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/axon.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/barista.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/config.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/contrawr.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/ctnet.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/deep4.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/deepsleepnet.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/dgcnn.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/diver1.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/eeg_clip.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/eegconformer.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/eeginception_erp.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/eegitnet.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/eegminer.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/eegnet.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/eegnex.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/eegsimpleconv.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/eegtcnet.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/emg2qwerty.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/fbcnet.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/fblightconvnet.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/fbmsnet.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/hybrid.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/ifnet.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/mscformer.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/neuropose.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/popt.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/sccnet.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/seizure_transformer.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/sensingdynamics.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/shallow_fbcsp.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/sinc_shallow.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/sleep_stager_blanco_2020.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/sleep_stager_chambon_2018.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/sparcnet.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/summary.csv +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/syncnet.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/tcn.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/tidnet.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/tmsanet.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/tsinception.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/usleep.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/vemg2pose.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/zuna.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/modules/__init__.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/modules/activation.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/modules/blocks.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/modules/channels.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/modules/convolution.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/modules/linear.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/modules/popt_modules.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/modules/stats.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/modules/util.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/modules/wrapper.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/preprocessing/__init__.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/preprocessing/eegprep_preprocess.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/preprocessing/mne_preprocess.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/preprocessing/preprocess.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/preprocessing/util.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/preprocessing/windowers.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/regressor.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/samplers/__init__.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/samplers/base.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/samplers/ssl.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/training/__init__.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/training/callbacks.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/training/losses.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/training/scoring.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/util.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/visualization/__init__.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/visualization/activations.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/visualization/attribution.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/visualization/confusion_matrices.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/visualization/frequency.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/visualization/metrics.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/visualization/sanity.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/visualization/topology.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode.egg-info/dependency_links.txt +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode.egg-info/requires.txt +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode.egg-info/top_level.txt +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/docs/Makefile +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/docs/_templates/autosummary/class.rst +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/docs/_templates/autosummary/class_in_subdir.rst +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/docs/_templates/autosummary/function.rst +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/docs/_templates/autosummary/function_in_subdir.rst +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/docs/agent_docs.rst +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/docs/cite.rst +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/docs/conf.py +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/docs/help.rst +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/docs/index.rst +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/docs/install/install.rst +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/docs/install/install_pip.rst +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/docs/install/install_source.rst +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/docs/models/categorization/attention.rst +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/docs/models/categorization/channel.rst +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/docs/models/categorization/convolution.rst +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/docs/models/categorization/filterbank.rst +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/docs/models/categorization/gnn.rst +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/docs/models/categorization/interpretable.rst +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/docs/models/categorization/lbm.rst +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/docs/models/categorization/recurrent.rst +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/docs/models/categorization/spd.rst +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/docs/models/models.rst +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/docs/models/models_categorization.rst +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/docs/models/models_table.rst +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/docs/models/models_visualization.rst +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/docs/sg_execution_times.rst +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/docs/user_guide/channel_strategies.rst +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/pyproject.toml +0 -0
- {braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/setup.cfg +0 -0
|
@@ -49,6 +49,7 @@ The following components are licensed under the MIT License:
|
|
|
49
49
|
- `braindecode/modules/popt_modules.py`
|
|
50
50
|
- `braindecode/models/brainomni.py`
|
|
51
51
|
- `braindecode/modules/quantization.py`
|
|
52
|
+
- `braindecode/modules/linear_attention.py`
|
|
52
53
|
- `braindecode/models/seizure_transformer.py`
|
|
53
54
|
- `docs/_static/model/seizure_transformer_arch.png`
|
|
54
55
|
- `braindecode/models/tmsanet.py`
|
|
@@ -57,6 +58,8 @@ The `brainomni.py` file is a derivative of `OpenTSLab/BrainOmni` (MIT), whose
|
|
|
57
58
|
SEANet codec derives from Meta's `facebookresearch/encodec` (MIT). The
|
|
58
59
|
`quantization.py` module holds the residual vector quantization derived from
|
|
59
60
|
`lucidrains/vector-quantize-pytorch` (MIT) and the BrainOmni port.
|
|
61
|
+
The `linear_attention.py` module is the part of
|
|
62
|
+
`lucidrains/linear-attention-transformer` (MIT) that BIOT and TFMTokenizer run.
|
|
60
63
|
|
|
61
64
|
### Apache-2.0 Licensed Files
|
|
62
65
|
|
{braindecode-1.8.1.dev178155531/braindecode.egg-info → braindecode-1.8.1.dev178237886}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: braindecode
|
|
3
|
-
Version: 1.8.1.
|
|
3
|
+
Version: 1.8.1.dev178237886
|
|
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>
|
|
@@ -23,6 +23,7 @@ from .transforms import (
|
|
|
23
23
|
SignFlip,
|
|
24
24
|
SmoothTimeMask,
|
|
25
25
|
TimeReverse,
|
|
26
|
+
TrivialAugment,
|
|
26
27
|
)
|
|
27
28
|
|
|
28
29
|
__all__ = [
|
|
@@ -30,6 +31,7 @@ __all__ = [
|
|
|
30
31
|
"IdentityTransform",
|
|
31
32
|
"Compose",
|
|
32
33
|
"AugmentedDataLoader",
|
|
34
|
+
"TrivialAugment",
|
|
33
35
|
"TimeReverse",
|
|
34
36
|
"SignFlip",
|
|
35
37
|
"FTSurrogate",
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
# Gustavo Rodrigues <gustavenrique01@gmail.com>
|
|
4
4
|
# Bruna Lopes <brunajaflopes@gmail.com>
|
|
5
5
|
# Sarthak Tayal <sarthaktayal2@gmail.com>
|
|
6
|
+
# Anton Soloviev <anton@praviel.com>
|
|
6
7
|
#
|
|
7
8
|
# License: BSD (3-clause)
|
|
8
9
|
|
|
@@ -1093,7 +1094,8 @@ def segmentation_reconstruction(
|
|
|
1093
1094
|
y : torch.Tensor
|
|
1094
1095
|
EEG labels for the example or batch.
|
|
1095
1096
|
n_segments : int
|
|
1096
|
-
Number of segments to use in the batch.
|
|
1097
|
+
Number of segments to use in the batch. Any remaining samples are
|
|
1098
|
+
included in the last segment.
|
|
1097
1099
|
data_classes : list[tuple[int, torch.Tensor]]
|
|
1098
1100
|
List of tuples. Each tuple contains the class index and the corresponding EEG data.
|
|
1099
1101
|
rand_indices : array-like
|
|
@@ -1133,6 +1135,8 @@ def segmentation_reconstruction(
|
|
|
1133
1135
|
for idx_segment in range(n_segments):
|
|
1134
1136
|
start = idx_segment * segment_size
|
|
1135
1137
|
end = (idx_segment + 1) * segment_size
|
|
1138
|
+
if idx_segment == n_segments - 1:
|
|
1139
|
+
end = window_size
|
|
1136
1140
|
|
|
1137
1141
|
# Perform the data augmentation
|
|
1138
1142
|
X_aug[np.arange(n_trials), :, start:end] = X_class[
|
|
@@ -1457,3 +1457,188 @@ class BandRotation(Transform):
|
|
|
1457
1457
|
"circular_jitter": self.circular_jitter,
|
|
1458
1458
|
"random_state": self.rng,
|
|
1459
1459
|
}
|
|
1460
|
+
|
|
1461
|
+
|
|
1462
|
+
class TrivialAugment(Transform):
|
|
1463
|
+
"""Apply one randomly sampled label-preserving augmentation per example.
|
|
1464
|
+
|
|
1465
|
+
For every example, independently samples one transform from the pool
|
|
1466
|
+
below and one of ``num_bins`` strengths evenly spaced between that
|
|
1467
|
+
transform's bounds, as in TrivialAugment [1]_. Examples that draw the
|
|
1468
|
+
same transform and strength are transformed in one call; each pooled
|
|
1469
|
+
transform still draws its own randomness per example.
|
|
1470
|
+
|
|
1471
|
+
Default pool (no assumption on the signal's unit, sampling frequency or
|
|
1472
|
+
montage):
|
|
1473
|
+
|
|
1474
|
+
* :class:`TimeReverse` — no strength parameter.
|
|
1475
|
+
* :class:`SignFlip` — no strength parameter.
|
|
1476
|
+
* :class:`FTSurrogate` — phase noise magnitude, 0.2 to 1.
|
|
1477
|
+
* :class:`ChannelsDropout` — channel drop probability, 0.05 to 0.4.
|
|
1478
|
+
* :class:`ChannelsShuffle` — shuffle probability, 0.1 to 0.75.
|
|
1479
|
+
* :class:`SmoothTimeMask` — mask length as a fraction of the window
|
|
1480
|
+
length, 0.05 to 0.25.
|
|
1481
|
+
* :class:`GaussianNoise` — noise standard deviation as a fraction of the
|
|
1482
|
+
sub-batch standard deviation (volts or microvolts alike), 0.02 to 0.3.
|
|
1483
|
+
* :class:`AmplitudeScale` — scale interval ``(1/s, s)``, ``s`` from 1.25
|
|
1484
|
+
to 2.5.
|
|
1485
|
+
|
|
1486
|
+
``sfreq`` adds :class:`BandstopFilter` (bandwidth 0.5 to 4 Hz, capped
|
|
1487
|
+
2.5 Hz below Nyquist) and :class:`FrequencyShift` (maximum shift 0.5 to
|
|
1488
|
+
2 Hz); ``sensors_positions_matrix`` adds :class:`SensorsRotation` around
|
|
1489
|
+
the z axis (5 to 25 degrees).
|
|
1490
|
+
|
|
1491
|
+
Parameters
|
|
1492
|
+
----------
|
|
1493
|
+
probability : float, optional
|
|
1494
|
+
Probability of augmenting each example. Defaults to 1.0.
|
|
1495
|
+
sfreq : float | None, optional
|
|
1496
|
+
Sampling frequency of the signals, in Hz. Defaults to None.
|
|
1497
|
+
sensors_positions_matrix : array-like | None, optional
|
|
1498
|
+
Sensor positions of shape ``(3, n_channels)`` (see
|
|
1499
|
+
:class:`SensorsRotation`). Defaults to None.
|
|
1500
|
+
num_bins : int, optional
|
|
1501
|
+
Number of strength levels per transform. Defaults to 10.
|
|
1502
|
+
random_state : int | numpy.random.RandomState, optional
|
|
1503
|
+
Seed shared by the per-example sampler and every pooled transform.
|
|
1504
|
+
Defaults to None.
|
|
1505
|
+
|
|
1506
|
+
Attributes
|
|
1507
|
+
----------
|
|
1508
|
+
op_names : list of str
|
|
1509
|
+
Names of the transforms in the pool, in sampling order.
|
|
1510
|
+
|
|
1511
|
+
References
|
|
1512
|
+
----------
|
|
1513
|
+
.. [1] Müller, S. G., & Hutter, F. (2021). TrivialAugment:
|
|
1514
|
+
Tuning-free Yet State-of-the-Art Data Augmentation. Proceedings of
|
|
1515
|
+
the IEEE/CVF International Conference on Computer Vision (ICCV),
|
|
1516
|
+
pp. 774-782.
|
|
1517
|
+
"""
|
|
1518
|
+
|
|
1519
|
+
def __init__(
|
|
1520
|
+
self,
|
|
1521
|
+
probability=1.0,
|
|
1522
|
+
sfreq=None,
|
|
1523
|
+
sensors_positions_matrix=None,
|
|
1524
|
+
num_bins=10,
|
|
1525
|
+
random_state=None,
|
|
1526
|
+
):
|
|
1527
|
+
super().__init__(probability=probability, random_state=random_state)
|
|
1528
|
+
if not isinstance(num_bins, (int, np.integer)) or num_bins < 1:
|
|
1529
|
+
raise ValueError(f"num_bins must be a positive integer, got {num_bins}")
|
|
1530
|
+
self.num_bins = int(num_bins)
|
|
1531
|
+
rng = self.rng
|
|
1532
|
+
# (name, strength bounds or None, make(strength) or None: built per call)
|
|
1533
|
+
specs = [
|
|
1534
|
+
("TimeReverse", None, lambda s: TimeReverse(1.0, random_state=rng)),
|
|
1535
|
+
("SignFlip", None, lambda s: SignFlip(1.0, random_state=rng)),
|
|
1536
|
+
(
|
|
1537
|
+
"FTSurrogate",
|
|
1538
|
+
(0.2, 1.0),
|
|
1539
|
+
lambda s: FTSurrogate(1.0, phase_noise_magnitude=s, random_state=rng),
|
|
1540
|
+
),
|
|
1541
|
+
(
|
|
1542
|
+
"ChannelsDropout",
|
|
1543
|
+
(0.05, 0.4),
|
|
1544
|
+
lambda s: ChannelsDropout(1.0, p_drop=s, random_state=rng),
|
|
1545
|
+
),
|
|
1546
|
+
(
|
|
1547
|
+
"ChannelsShuffle",
|
|
1548
|
+
(0.1, 0.75),
|
|
1549
|
+
lambda s: ChannelsShuffle(1.0, p_shuffle=s, random_state=rng),
|
|
1550
|
+
),
|
|
1551
|
+
("SmoothTimeMask", (0.05, 0.25), None),
|
|
1552
|
+
("GaussianNoise", (0.02, 0.3), None),
|
|
1553
|
+
(
|
|
1554
|
+
"AmplitudeScale",
|
|
1555
|
+
(1.25, 2.5),
|
|
1556
|
+
lambda s: AmplitudeScale(1.0, interval=(1.0 / s, s), random_state=rng),
|
|
1557
|
+
),
|
|
1558
|
+
]
|
|
1559
|
+
if sfreq is not None:
|
|
1560
|
+
nyquist = sfreq / 2.0
|
|
1561
|
+
# BandstopFilter needs bandwidth < nyquist - 2; keep a margin
|
|
1562
|
+
max_bandwidth = min(4.0, nyquist - 2.5)
|
|
1563
|
+
if max_bandwidth <= 0.5:
|
|
1564
|
+
raise ValueError(
|
|
1565
|
+
f"sfreq={sfreq} is too small to sample valid band-stop "
|
|
1566
|
+
"bandwidths (needs at least 6.0 Hz)."
|
|
1567
|
+
)
|
|
1568
|
+
specs += [
|
|
1569
|
+
(
|
|
1570
|
+
"BandstopFilter",
|
|
1571
|
+
(0.5, max_bandwidth),
|
|
1572
|
+
lambda s: BandstopFilter(
|
|
1573
|
+
1.0,
|
|
1574
|
+
sfreq=sfreq,
|
|
1575
|
+
bandwidth=s,
|
|
1576
|
+
max_freq=nyquist,
|
|
1577
|
+
random_state=rng,
|
|
1578
|
+
),
|
|
1579
|
+
),
|
|
1580
|
+
(
|
|
1581
|
+
"FrequencyShift",
|
|
1582
|
+
(0.5, 2.0),
|
|
1583
|
+
lambda s: FrequencyShift(
|
|
1584
|
+
1.0, sfreq=sfreq, max_delta_freq=s, random_state=rng
|
|
1585
|
+
),
|
|
1586
|
+
),
|
|
1587
|
+
]
|
|
1588
|
+
if sensors_positions_matrix is not None:
|
|
1589
|
+
specs.append(
|
|
1590
|
+
(
|
|
1591
|
+
"SensorsRotation",
|
|
1592
|
+
(5.0, 25.0),
|
|
1593
|
+
lambda s: SensorsRotation(
|
|
1594
|
+
1.0,
|
|
1595
|
+
sensors_positions_matrix=sensors_positions_matrix,
|
|
1596
|
+
max_degrees=s,
|
|
1597
|
+
random_state=rng,
|
|
1598
|
+
),
|
|
1599
|
+
)
|
|
1600
|
+
)
|
|
1601
|
+
|
|
1602
|
+
self._pool = []
|
|
1603
|
+
for name, bounds, make in specs:
|
|
1604
|
+
if bounds is None:
|
|
1605
|
+
strengths = [None]
|
|
1606
|
+
else:
|
|
1607
|
+
strengths = np.linspace(*bounds, self.num_bins).tolist()
|
|
1608
|
+
variants = None if make is None else [make(s) for s in strengths]
|
|
1609
|
+
self._pool.append((name, strengths, variants))
|
|
1610
|
+
# pre-built transforms as submodules (pickle, ``.to()``)
|
|
1611
|
+
self._static_transforms = torch.nn.ModuleList(
|
|
1612
|
+
v for _, _, variants in self._pool if variants for v in variants
|
|
1613
|
+
)
|
|
1614
|
+
self.op_names = [name for name, _, _ in self._pool]
|
|
1615
|
+
|
|
1616
|
+
def operation(self, X, y):
|
|
1617
|
+
"""Apply one sampled transform and strength to each example of X."""
|
|
1618
|
+
n_strengths = np.array([len(strengths) for _, strengths, _ in self._pool])
|
|
1619
|
+
op_ids = self.rng.randint(0, len(self._pool), size=X.shape[0])
|
|
1620
|
+
bin_ids = self.rng.randint(0, self.num_bins, size=X.shape[0])
|
|
1621
|
+
# magnitude-free transforms collapse all examples onto bin 0
|
|
1622
|
+
bin_ids[n_strengths[op_ids] == 1] = 0
|
|
1623
|
+
keys = op_ids * self.num_bins + bin_ids
|
|
1624
|
+
|
|
1625
|
+
out_X, out_y = X.clone(), y.clone()
|
|
1626
|
+
for key in np.unique(keys):
|
|
1627
|
+
group = torch.from_numpy(np.flatnonzero(keys == key)).to(X.device)
|
|
1628
|
+
op_i, bin_j = divmod(int(key), self.num_bins)
|
|
1629
|
+
name, strengths, variants = self._pool[op_i]
|
|
1630
|
+
X_sub = X[group]
|
|
1631
|
+
if variants is not None:
|
|
1632
|
+
transform = variants[bin_j]
|
|
1633
|
+
elif name == "SmoothTimeMask":
|
|
1634
|
+
n_mask = max(1, int(round(strengths[bin_j] * X.shape[-1])))
|
|
1635
|
+
transform = SmoothTimeMask(
|
|
1636
|
+
1.0, mask_len_samples=n_mask, random_state=self.rng
|
|
1637
|
+
)
|
|
1638
|
+
else: # GaussianNoise, std relative to the sub-batch (unit-free)
|
|
1639
|
+
std = strengths[bin_j] * X_sub.std().item()
|
|
1640
|
+
transform = GaussianNoise(1.0, std=std, random_state=self.rng)
|
|
1641
|
+
tr_X, tr_y = transform(X_sub, y[group])
|
|
1642
|
+
out_X[group] = tr_X.to(out_X.dtype)
|
|
1643
|
+
out_y[group] = tr_y
|
|
1644
|
+
return out_X, out_y
|
{braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/functional/__init__.py
RENAMED
|
@@ -3,11 +3,13 @@ from .functions import (
|
|
|
3
3
|
daubechies_filters,
|
|
4
4
|
drop_path,
|
|
5
5
|
dwt_max_level,
|
|
6
|
+
fft_conv1d,
|
|
6
7
|
hilbert_freq,
|
|
7
8
|
identity,
|
|
8
9
|
iou_1d,
|
|
9
10
|
pairwise_iou_1d,
|
|
10
11
|
plv_time,
|
|
12
|
+
prefer_fft_conv,
|
|
11
13
|
rotate_pairs,
|
|
12
14
|
safe_log,
|
|
13
15
|
sinusoidal_positional_encoding,
|
|
@@ -22,11 +24,13 @@ __all__ = [
|
|
|
22
24
|
"daubechies_filters",
|
|
23
25
|
"drop_path",
|
|
24
26
|
"dwt_max_level",
|
|
27
|
+
"fft_conv1d",
|
|
25
28
|
"hilbert_freq",
|
|
26
29
|
"identity",
|
|
27
30
|
"iou_1d",
|
|
28
31
|
"pairwise_iou_1d",
|
|
29
32
|
"plv_time",
|
|
33
|
+
"prefer_fft_conv",
|
|
30
34
|
"rotate_pairs",
|
|
31
35
|
"safe_log",
|
|
32
36
|
"sinusoidal_positional_encoding",
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
from __future__ import annotations
|
|
8
8
|
|
|
9
9
|
import math
|
|
10
|
+
from typing import Optional
|
|
10
11
|
|
|
11
12
|
import numpy as np
|
|
12
13
|
import torch
|
|
@@ -54,6 +55,95 @@ def spectral_input(x: torch.Tensor) -> torch.Tensor:
|
|
|
54
55
|
return x.to(torch.promote_types(x.dtype, torch.float32))
|
|
55
56
|
|
|
56
57
|
|
|
58
|
+
def fft_conv1d(
|
|
59
|
+
x: torch.Tensor, weight: torch.Tensor, bias: Optional[torch.Tensor] = None
|
|
60
|
+
) -> torch.Tensor:
|
|
61
|
+
"""``F.conv1d(x, weight, bias, padding="same")`` computed with FFTs.
|
|
62
|
+
|
|
63
|
+
Equal to the direct convolution up to float rounding: the FFT is long
|
|
64
|
+
enough for a linear (not circular) convolution. Its cost barely grows with
|
|
65
|
+
the kernel size, so it is faster than the direct one for long kernels on
|
|
66
|
+
CPU (see :func:`prefer_fft_conv`). float16/bfloat16 inputs are computed in
|
|
67
|
+
float32 (:func:`spectral_input`) and cast back.
|
|
68
|
+
|
|
69
|
+
Parameters
|
|
70
|
+
----------
|
|
71
|
+
x : torch.Tensor
|
|
72
|
+
Input of shape ``(batch, in_channels, n_times)``.
|
|
73
|
+
weight : torch.Tensor
|
|
74
|
+
Kernels of shape ``(out_channels, in_channels, kernel_size)``.
|
|
75
|
+
bias : torch.Tensor | None
|
|
76
|
+
Bias of shape ``(out_channels,)``.
|
|
77
|
+
|
|
78
|
+
Returns
|
|
79
|
+
-------
|
|
80
|
+
torch.Tensor
|
|
81
|
+
Output of shape ``(batch, out_channels, n_times)``, dtype and device of
|
|
82
|
+
``x``. For an even ``kernel_size`` it is aligned like torch's
|
|
83
|
+
``padding="same"`` (the extra zero padded on the right).
|
|
84
|
+
"""
|
|
85
|
+
n_times, kernel_size = x.shape[-1], weight.shape[-1]
|
|
86
|
+
# >= n_times + kernel_size - 1 (no circular wrap-around), even and
|
|
87
|
+
# 5-smooth: the fast cases of a real FFT
|
|
88
|
+
n_fft = 2 * _next_fast_len((n_times + kernel_size) // 2)
|
|
89
|
+
xs = spectral_input(x)
|
|
90
|
+
# conv1d is a cross-correlation: a convolution with the flipped kernel
|
|
91
|
+
x_f = torch.fft.rfft(xs, n=n_fft).permute(2, 0, 1) # (freq, batch, in)
|
|
92
|
+
w_f = torch.fft.rfft(weight.to(xs).flip(-1), n=n_fft).permute(2, 1, 0)
|
|
93
|
+
# Per frequency (batch, in) @ (in, out) in complex numbers, as one real
|
|
94
|
+
# matmul (a complex one is slower on CPU): [Re x; Im x] @ [Re w, Im w]
|
|
95
|
+
# (columns interleaved) holds the four real products.
|
|
96
|
+
p = torch.cat([x_f.real, x_f.imag], 1) @ torch.view_as_real(w_f).flatten(2)
|
|
97
|
+
p = p.unflatten(1, [2, x.shape[0]]).unflatten(3, [-1, 2]) # x re/im, w re/im
|
|
98
|
+
y_f = torch.complex(
|
|
99
|
+
p[:, 0, :, :, 0] - p[:, 1, :, :, 1], p[:, 0, :, :, 1] + p[:, 1, :, :, 0]
|
|
100
|
+
)
|
|
101
|
+
y = torch.fft.irfft(y_f.permute(1, 2, 0), n=n_fft)
|
|
102
|
+
# "same" output t is sample t + kernel_size // 2 of the full convolution
|
|
103
|
+
y = y[..., kernel_size // 2 : kernel_size // 2 + n_times]
|
|
104
|
+
if bias is not None:
|
|
105
|
+
y = y + bias.to(y).unsqueeze(-1)
|
|
106
|
+
return y.to(x)
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def prefer_fft_conv(x: torch.Tensor, kernel_size: int) -> bool:
|
|
110
|
+
"""Whether :func:`fft_conv1d` is expected to beat a direct convolution.
|
|
111
|
+
|
|
112
|
+
Rule measured for :class:`~braindecode.models.EEGInceptionMI` (48 to 240
|
|
113
|
+
channels, 128-500 Hz, 2 CPU threads, oneDNN on and off): on CPU the FFT
|
|
114
|
+
wins for float16/bfloat16 inputs (no fast half-precision CPU convolution)
|
|
115
|
+
and from ``batch_size * kernel_size >= 600`` if also
|
|
116
|
+
``in_channels * kernel_size >= 120``: with one or two input channels a
|
|
117
|
+
float32 direct convolution stays cheaper up to k = 85 / 31 (13 long
|
|
118
|
+
temporal convolutions of the model zoo, 22 channels x batch 32). GPUs and
|
|
119
|
+
HPUs (no complex dtype) keep the direct convolution.
|
|
120
|
+
|
|
121
|
+
Parameters
|
|
122
|
+
----------
|
|
123
|
+
x : torch.Tensor
|
|
124
|
+
Input of the convolution, ``(batch, in_channels, n_times)``.
|
|
125
|
+
kernel_size : int
|
|
126
|
+
Kernel length in samples.
|
|
127
|
+
"""
|
|
128
|
+
return x.device.type == "cpu" and (
|
|
129
|
+
x.element_size() == 2
|
|
130
|
+
or (x.shape[0] * kernel_size >= 600 and x.shape[1] * kernel_size >= 120)
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def _next_fast_len(n: int) -> int:
|
|
135
|
+
"""Smallest ``2^a 3^b 5^c >= n`` (scipy's ``next_fast_len(n, real=True)``)."""
|
|
136
|
+
n -= 1
|
|
137
|
+
m = 0
|
|
138
|
+
while m != 1:
|
|
139
|
+
n += 1
|
|
140
|
+
m = n
|
|
141
|
+
for p in [2, 3, 5]:
|
|
142
|
+
while m % p == 0:
|
|
143
|
+
m = m // p
|
|
144
|
+
return n
|
|
145
|
+
|
|
146
|
+
|
|
57
147
|
def drop_path(
|
|
58
148
|
x, drop_prob: float = 0.0, training: bool = False, scale_by_keep: bool = True
|
|
59
149
|
):
|
|
@@ -197,6 +287,7 @@ def hilbert_freq(x: torch.Tensor, forward_fourier: bool = True) -> torch.Tensor:
|
|
|
197
287
|
return _real_dft.hilbert_freq_real(x, forward_fourier).to(x.dtype)
|
|
198
288
|
|
|
199
289
|
input_dtype = x.dtype
|
|
290
|
+
cast_back = x.is_floating_point()
|
|
200
291
|
# ``view_as_complex`` does not accept bfloat16 real/imaginary pairs. The
|
|
201
292
|
# HPU path can produce bfloat16 Fourier coefficients under autocast, so do
|
|
202
293
|
# the complex-valued part in float32 and restore the real-valued contract
|
|
@@ -224,9 +315,8 @@ def hilbert_freq(x: torch.Tensor, forward_fourier: bool = True) -> torch.Tensor:
|
|
|
224
315
|
x = torch.fft.ifft(x, norm=None, dim=-1) # returns complex signal
|
|
225
316
|
x = torch.view_as_real(x)
|
|
226
317
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
return x
|
|
318
|
+
# Integer input stays float (casting back would truncate the analytic signal).
|
|
319
|
+
return x.to(input_dtype) if cast_back else x
|
|
230
320
|
|
|
231
321
|
|
|
232
322
|
def plv_time(
|
|
@@ -281,18 +371,24 @@ def plv_time(
|
|
|
281
371
|
)
|
|
282
372
|
# Normalize the analytic signal to obtain unit vectors (phasors).
|
|
283
373
|
unit_phasor = analytic_signal / amplitude.unsqueeze(-1)
|
|
374
|
+
# The real/imaginary slices are strided (step 2): matmul copied each of
|
|
375
|
+
# them for every product, per batch matrix. Copy them once.
|
|
376
|
+
real = unit_phasor[..., 0].contiguous()
|
|
377
|
+
imag = unit_phasor[..., 1].contiguous()
|
|
378
|
+
real_t = real.transpose(-2, -1).contiguous()
|
|
379
|
+
imag_t = imag.transpose(-2, -1).contiguous()
|
|
284
380
|
|
|
285
381
|
# Compute the real part of the outer product between phasors of
|
|
286
382
|
# different channels.
|
|
287
|
-
real_real = torch.matmul(
|
|
383
|
+
real_real = torch.matmul(real, real_t)
|
|
288
384
|
|
|
289
385
|
# Compute the imaginary part of the outer product between phasors of
|
|
290
386
|
# different channels.
|
|
291
|
-
imag_imag = torch.matmul(
|
|
387
|
+
imag_imag = torch.matmul(imag, imag_t)
|
|
292
388
|
|
|
293
389
|
# Compute the cross-terms for the real and imaginary parts.
|
|
294
|
-
real_imag = torch.matmul(
|
|
295
|
-
imag_real = torch.matmul(
|
|
390
|
+
real_imag = torch.matmul(real, imag_t)
|
|
391
|
+
imag_real = torch.matmul(imag, real_t)
|
|
296
392
|
|
|
297
393
|
# Combine the real and imaginary parts to form the complex correlation.
|
|
298
394
|
correlation_real = real_real + imag_imag
|
|
@@ -412,7 +508,14 @@ def dwt_max_level(n_times: int, filter_len: int) -> int:
|
|
|
412
508
|
"""
|
|
413
509
|
if n_times < filter_len:
|
|
414
510
|
return 0
|
|
415
|
-
|
|
511
|
+
# floor(log2(n_times / (filter_len - 1))) in integers (TorchScript has no
|
|
512
|
+
# math.log2): the largest level with (filter_len - 1) * 2**level <= n_times.
|
|
513
|
+
ratio = n_times // (filter_len - 1)
|
|
514
|
+
level = 0
|
|
515
|
+
while ratio >= 2:
|
|
516
|
+
ratio = ratio // 2
|
|
517
|
+
level += 1
|
|
518
|
+
return level
|
|
416
519
|
|
|
417
520
|
|
|
418
521
|
def wavelet_decomposition(
|
|
@@ -456,8 +559,9 @@ def wavelet_decomposition(
|
|
|
456
559
|
)
|
|
457
560
|
approx, detail = F.conv1d(padded, weight, stride=2).unbind(dim=1)
|
|
458
561
|
details.append(detail)
|
|
459
|
-
|
|
460
|
-
|
|
562
|
+
details.reverse() # [cD_n, ..., cD_1]
|
|
563
|
+
out = torch.cat([approx] + details, dim=-1)
|
|
564
|
+
return out.reshape(list(leading) + [-1])
|
|
461
565
|
|
|
462
566
|
|
|
463
567
|
def sinusoidal_positional_encoding(
|
{braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/attn_sleep.py
RENAMED
|
@@ -407,16 +407,12 @@ class _MRCNN(nn.Module):
|
|
|
407
407
|
##########################################################################################
|
|
408
408
|
|
|
409
409
|
|
|
410
|
-
def _attention(
|
|
411
|
-
|
|
412
|
-
) -> tuple[torch.Tensor, torch.Tensor]:
|
|
413
|
-
"""Implementation of Scaled dot product attention."""
|
|
410
|
+
def _attention(query: torch.Tensor, key: torch.Tensor) -> torch.Tensor:
|
|
411
|
+
"""Scaled dot product attention weights."""
|
|
414
412
|
# d_k - dimension of the query and key vectors
|
|
415
413
|
d_k = query.size(-1)
|
|
416
414
|
scores = torch.matmul(query, key.transpose(-2, -1)) / math.sqrt(d_k)
|
|
417
|
-
|
|
418
|
-
output = torch.matmul(p_attn, value) # (B, h, T, d_k)
|
|
419
|
-
return output, p_attn
|
|
415
|
+
return F.softmax(scores, dim=-1) # attention weights
|
|
420
416
|
|
|
421
417
|
|
|
422
418
|
class _MultiHeadedAttention(nn.Module):
|
|
@@ -464,10 +460,8 @@ class _MultiHeadedAttention(nn.Module):
|
|
|
464
460
|
.transpose(1, 2)
|
|
465
461
|
)
|
|
466
462
|
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
attn = self.dropout(attn_weights)
|
|
470
|
-
# recompute the weighted sum with dropped weights
|
|
463
|
+
# apply dropout to the *weights*, then the weighted sum
|
|
464
|
+
attn = self.dropout(_attention(query, key))
|
|
471
465
|
x = torch.matmul(attn, value)
|
|
472
466
|
|
|
473
467
|
# merge heads and project
|
{braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/base.py
RENAMED
|
@@ -26,6 +26,7 @@ from braindecode.models.util import (
|
|
|
26
26
|
track_model_init_kwargs,
|
|
27
27
|
)
|
|
28
28
|
from braindecode.modules.channels import ChannelLayer
|
|
29
|
+
from braindecode.modules.parametrization import make_parametrizations_scriptable
|
|
29
30
|
from braindecode.version import __version__
|
|
30
31
|
|
|
31
32
|
huggingface_hub = _soft_import(
|
|
@@ -431,7 +432,7 @@ class EEGModuleMixin(_BaseHubMixin, metaclass=_BraindecodeDocstringMeta):
|
|
|
431
432
|
and self._input_window_seconds is not None
|
|
432
433
|
and self._sfreq is not None
|
|
433
434
|
):
|
|
434
|
-
return round(self._input_window_seconds * self._sfreq)
|
|
435
|
+
return int(round(self._input_window_seconds * self._sfreq))
|
|
435
436
|
elif self._n_times is None:
|
|
436
437
|
raise ValueError(
|
|
437
438
|
"n_times could not be inferred. "
|
|
@@ -452,6 +453,8 @@ class EEGModuleMixin(_BaseHubMixin, metaclass=_BraindecodeDocstringMeta):
|
|
|
452
453
|
"input_window_seconds could not be inferred. "
|
|
453
454
|
"Either specify input_window_seconds or n_times and sfreq."
|
|
454
455
|
)
|
|
456
|
+
if torch.jit.is_scripting(): # may be an int, e.g. from a Hub config
|
|
457
|
+
return float(self._input_window_seconds)
|
|
455
458
|
return self._input_window_seconds
|
|
456
459
|
|
|
457
460
|
@property
|
|
@@ -467,6 +470,8 @@ class EEGModuleMixin(_BaseHubMixin, metaclass=_BraindecodeDocstringMeta):
|
|
|
467
470
|
"sfreq could not be inferred. "
|
|
468
471
|
"Either specify sfreq or input_window_seconds and n_times."
|
|
469
472
|
)
|
|
473
|
+
if torch.jit.is_scripting(): # may be an int, e.g. from a Hub config
|
|
474
|
+
return float(self._sfreq)
|
|
470
475
|
return self._sfreq
|
|
471
476
|
|
|
472
477
|
@property
|
|
@@ -474,6 +479,10 @@ class EEGModuleMixin(_BaseHubMixin, metaclass=_BraindecodeDocstringMeta):
|
|
|
474
479
|
"""Input data shape."""
|
|
475
480
|
return (1, self.n_chans, self.n_times)
|
|
476
481
|
|
|
482
|
+
def __prepare_scriptable__(self):
|
|
483
|
+
# Called by torch.jit.script before compiling the model.
|
|
484
|
+
return make_parametrizations_scriptable(self)
|
|
485
|
+
|
|
477
486
|
def get_output_shape(self) -> tuple[int, ...]:
|
|
478
487
|
"""Returns shape of neural network output for batch size equal 1.
|
|
479
488
|
|
{braindecode-1.8.1.dev178155531 → braindecode-1.8.1.dev178237886}/braindecode/models/bendr.py
RENAMED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
# License: BSD (3-clause)
|
|
5
5
|
|
|
6
6
|
import copy
|
|
7
|
+
from typing import Dict, Optional, Union
|
|
7
8
|
|
|
8
9
|
import numpy as np
|
|
9
10
|
import torch
|
|
@@ -364,7 +365,9 @@ class BENDR(EEGModuleMixin, nn.Module):
|
|
|
364
365
|
self._update_init_kwargs(final_layer=True)
|
|
365
366
|
self._build_head(n_outputs)
|
|
366
367
|
|
|
367
|
-
def forward(
|
|
368
|
+
def forward(
|
|
369
|
+
self, x: torch.Tensor, return_features: bool = False
|
|
370
|
+
) -> Union[torch.Tensor, Dict[str, Optional[torch.Tensor]]]:
|
|
368
371
|
if self.channel_tokenizer is not None:
|
|
369
372
|
x = self.channel_tokenizer(x)[0]
|
|
370
373
|
encoded = self.encoder(x)
|
|
@@ -394,7 +397,11 @@ class BENDR(EEGModuleMixin, nn.Module):
|
|
|
394
397
|
# feature: [batch_size, encoder_h]
|
|
395
398
|
|
|
396
399
|
if return_features:
|
|
397
|
-
|
|
400
|
+
out: Dict[str, Optional[torch.Tensor]] = {
|
|
401
|
+
"features": feature,
|
|
402
|
+
"cls_token": None,
|
|
403
|
+
}
|
|
404
|
+
return out
|
|
398
405
|
|
|
399
406
|
if self.final_layer is not None:
|
|
400
407
|
feature = self.final_layer(feature)
|
|
@@ -468,6 +475,23 @@ class _ConvEncoderBENDR(nn.Module):
|
|
|
468
475
|
return self.encoder(x)
|
|
469
476
|
|
|
470
477
|
|
|
478
|
+
class _TFixupEncoderLayer(nn.TransformerEncoderLayer):
|
|
479
|
+
"""Post-norm layer without the fast path (never taken: ``batch_first=False``),
|
|
480
|
+
which reads ``norm1.weight``, an Identity under T-Fixup, and cannot be scripted."""
|
|
481
|
+
|
|
482
|
+
def forward(
|
|
483
|
+
self,
|
|
484
|
+
src: torch.Tensor,
|
|
485
|
+
src_mask: Optional[torch.Tensor] = None,
|
|
486
|
+
src_key_padding_mask: Optional[torch.Tensor] = None,
|
|
487
|
+
is_causal: bool = False,
|
|
488
|
+
) -> torch.Tensor:
|
|
489
|
+
x = self.norm1(
|
|
490
|
+
src + self._sa_block(src, src_mask, src_key_padding_mask, is_causal)
|
|
491
|
+
)
|
|
492
|
+
return self.norm2(x + self._ff_block(x))
|
|
493
|
+
|
|
494
|
+
|
|
471
495
|
class _BENDRContextualizer(nn.Module):
|
|
472
496
|
r"""Transformer-based contextualizer for BENDR."""
|
|
473
497
|
|
|
@@ -526,7 +550,7 @@ class _BENDRContextualizer(nn.Module):
|
|
|
526
550
|
# --- Transformer Encoder Layers ---
|
|
527
551
|
# Paper uses T-Fixup: remove internal LayerNorm layers
|
|
528
552
|
|
|
529
|
-
encoder_layer =
|
|
553
|
+
encoder_layer = _TFixupEncoderLayer(
|
|
530
554
|
d_model=self.transformer_dim, # Use projected dimension
|
|
531
555
|
nhead=heads,
|
|
532
556
|
dim_feedforward=hidden_feedforward,
|
|
@@ -588,7 +612,6 @@ class _BENDRContextualizer(nn.Module):
|
|
|
588
612
|
float(self.start_token),
|
|
589
613
|
device=x.device,
|
|
590
614
|
dtype=x.dtype,
|
|
591
|
-
requires_grad=False,
|
|
592
615
|
)
|
|
593
616
|
x = torch.cat([token_emb, x], dim=0)
|
|
594
617
|
# x: [seq_len + 1, batch_size, transformer_dim]
|
|
@@ -604,7 +627,7 @@ class _BENDRContextualizer(nn.Module):
|
|
|
604
627
|
# x: [seq_len + 1, batch_size, transformer_dim]
|
|
605
628
|
|
|
606
629
|
# Permute to (B, C, T) format for Conv1d output layer
|
|
607
|
-
x =
|
|
630
|
+
x = x.permute(1, 2, 0)
|
|
608
631
|
# x: [batch_size, transformer_dim, seq_len + 1]
|
|
609
632
|
|
|
610
633
|
# Apply output projection (Conv1d expects B, C, T)
|