braindecode 1.8.1.dev176535733__tar.gz → 1.8.1.dev181104868__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.dev176535733 → braindecode-1.8.1.dev181104868}/NOTICE.txt +1 -0
- {braindecode-1.8.1.dev176535733/braindecode.egg-info → braindecode-1.8.1.dev181104868}/PKG-INFO +5 -4
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/augmentation/functional.py +1 -1
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/augmentation/transforms.py +4 -2
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/datasets/tuh.py +7 -2
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/__init__.py +4 -0
- braindecode-1.8.1.dev181104868/braindecode/models/brainbert.py +448 -0
- braindecode-1.8.1.dev181104868/braindecode/models/brant.py +477 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/dgcnn.py +4 -1
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/eegpt.py +3 -2
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/interpolated.py +5 -2
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/reve.py +11 -82
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/summary.csv +2 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/util.py +7 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/zuna.py +8 -34
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/modules/convolution.py +4 -2
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/preprocessing/windowers.py +11 -2
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/util.py +44 -0
- braindecode-1.8.1.dev181104868/braindecode/version.py +1 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868/braindecode.egg-info}/PKG-INFO +5 -4
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode.egg-info/SOURCES.txt +2 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode.egg-info/requires.txt +4 -3
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/docs/api.rst +4 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/docs/conf.py +6 -1
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/docs/install/install.rst +4 -1
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/docs/whats_new.rst +48 -1
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/pyproject.toml +4 -4
- braindecode-1.8.1.dev176535733/braindecode/version.py +0 -1
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/LICENSE.txt +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/MANIFEST.in +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/README.rst +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/__init__.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/augmentation/__init__.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/augmentation/base.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/classifier.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/datasets/__init__.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/datasets/_notebook_viewer.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/datasets/base.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/datasets/bbci.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/datasets/bcicomp.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/datasets/bids/__init__.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/datasets/bids/datasets.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/datasets/bids/format.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/datasets/bids/hub.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/datasets/bids/hub_format.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/datasets/bids/hub_io.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/datasets/bids/hub_validation.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/datasets/bids/iterable.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/datasets/chb_mit.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/datasets/collate.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/datasets/mne.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/datasets/moabb.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/datasets/nmt.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/datasets/registry.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/datasets/siena.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/datasets/sleep_physio_challe_18.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/datasets/sleep_physionet.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/datasets/utils.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/datasets/xy.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/datautil/__init__.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/datautil/channel_utils.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/datautil/hub_formats.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/datautil/serialization.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/datautil/util.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/eegneuralnet.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/functional/__init__.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/functional/functions.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/functional/initialization.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/atcnet.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/attentionbasenet.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/attn_sleep.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/base.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/bendr.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/biot.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/brainmodule.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/cbramod.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/codebrain.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/config.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/contrawr.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/ctnet.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/dance.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/deep4.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/deepsleepnet.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/eegconformer.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/eegdino.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/eeginception_erp.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/eeginception_mi.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/eegitnet.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/eegminer.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/eegnet.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/eegnex.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/eegsimpleconv.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/eegsym.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/eegtcnet.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/emg2qwerty.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/fbcnet.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/fblightconvnet.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/fbmsnet.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/hybrid.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/ifnet.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/labram.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/luna.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/medformer.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/meta_neuromotor.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/msvtnet.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/mvpformer.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/neuropose.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/patchedtransformer.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/sccnet.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/sensingdynamics.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/shallow_fbcsp.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/signal_jepa.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/sinc_shallow.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/sleep_stager_blanco_2020.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/sleep_stager_chambon_2018.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/sparcnet.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/sstdpn.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/steegformer.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/syncnet.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/tcformer.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/tcn.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/tidnet.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/tsinception.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/usleep.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/vemg2pose.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/modules/__init__.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/modules/activation.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/modules/attention.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/modules/blocks.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/modules/dance_modules.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/modules/filter.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/modules/interpolation.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/modules/layers.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/modules/linear.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/modules/parametrization.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/modules/stats.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/modules/util.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/modules/wrapper.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/preprocessing/__init__.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/preprocessing/eegprep_preprocess.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/preprocessing/mne_preprocess.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/preprocessing/preprocess.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/preprocessing/util.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/regressor.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/samplers/__init__.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/samplers/base.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/samplers/ssl.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/training/__init__.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/training/callbacks.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/training/losses.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/training/scoring.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/visualization/__init__.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/visualization/activations.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/visualization/attribution.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/visualization/confusion_matrices.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/visualization/frequency.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/visualization/metrics.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/visualization/sanity.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/visualization/topology.py +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode.egg-info/dependency_links.txt +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode.egg-info/top_level.txt +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/docs/Makefile +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/docs/_templates/autosummary/class.rst +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/docs/_templates/autosummary/class_in_subdir.rst +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/docs/_templates/autosummary/function.rst +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/docs/_templates/autosummary/function_in_subdir.rst +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/docs/cite.rst +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/docs/help.rst +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/docs/index.rst +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/docs/install/install_pip.rst +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/docs/install/install_source.rst +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/docs/models/categorization/attention.rst +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/docs/models/categorization/channel.rst +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/docs/models/categorization/convolution.rst +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/docs/models/categorization/filterbank.rst +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/docs/models/categorization/gnn.rst +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/docs/models/categorization/interpretable.rst +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/docs/models/categorization/lbm.rst +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/docs/models/categorization/recurrent.rst +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/docs/models/categorization/spd.rst +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/docs/models/models.rst +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/docs/models/models_categorization.rst +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/docs/models/models_table.rst +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/docs/models/models_visualization.rst +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/docs/sg_execution_times.rst +0 -0
- {braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/setup.cfg +0 -0
{braindecode-1.8.1.dev176535733/braindecode.egg-info → braindecode-1.8.1.dev181104868}/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.dev181104868
|
|
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>
|
|
@@ -22,8 +22,8 @@ Requires-Python: >=3.11
|
|
|
22
22
|
Description-Content-Type: text/x-rst
|
|
23
23
|
License-File: LICENSE.txt
|
|
24
24
|
License-File: NOTICE.txt
|
|
25
|
-
Requires-Dist: torch>=2.
|
|
26
|
-
Requires-Dist: torchaudio>=2.
|
|
25
|
+
Requires-Dist: torch>=2.4
|
|
26
|
+
Requires-Dist: torchaudio>=2.4
|
|
27
27
|
Requires-Dist: mne>=1.11.0
|
|
28
28
|
Requires-Dist: mne_bids>=0.18
|
|
29
29
|
Requires-Dist: h5py
|
|
@@ -47,6 +47,7 @@ Requires-Dist: captum>=0.7.0; extra == "viz"
|
|
|
47
47
|
Provides-Extra: tests
|
|
48
48
|
Requires-Dist: pytest<9.1; extra == "tests"
|
|
49
49
|
Requires-Dist: pytest-cov; extra == "tests"
|
|
50
|
+
Requires-Dist: pytest-xdist>=3.8.0; extra == "tests"
|
|
50
51
|
Requires-Dist: codecov; extra == "tests"
|
|
51
52
|
Requires-Dist: pytest_cases; extra == "tests"
|
|
52
53
|
Requires-Dist: mypy; extra == "tests"
|
|
@@ -57,7 +58,7 @@ Provides-Extra: typing
|
|
|
57
58
|
Requires-Dist: exca>=0.5.10; extra == "typing"
|
|
58
59
|
Requires-Dist: numpydantic>=1.7; extra == "typing"
|
|
59
60
|
Provides-Extra: docs
|
|
60
|
-
Requires-Dist: sphinx_gallery; extra == "docs"
|
|
61
|
+
Requires-Dist: sphinx_gallery>=0.17; extra == "docs"
|
|
61
62
|
Requires-Dist: sphinx_rtd_theme; extra == "docs"
|
|
62
63
|
Requires-Dist: sphinx-autodoc-typehints; extra == "docs"
|
|
63
64
|
Requires-Dist: sphinx-autobuild; extra == "docs"
|
|
@@ -1002,7 +1002,7 @@ def sensors_rotation(
|
|
|
1002
1002
|
``mne`` through::
|
|
1003
1003
|
|
|
1004
1004
|
>>> ten_twenty_montage = mne.channels.make_standard_montage(
|
|
1005
|
-
... 'standard_1020'
|
|
1005
|
+
... 'standard_1020' # 'colin27_1020' on MNE >= 1.13
|
|
1006
1006
|
... ).get_positions()['ch_pos']
|
|
1007
1007
|
axis : 'x' | 'y' | 'z'
|
|
1008
1008
|
Axis around which to rotate.
|
|
@@ -13,6 +13,8 @@ import numpy as np
|
|
|
13
13
|
import torch
|
|
14
14
|
from mne.channels import make_standard_montage
|
|
15
15
|
|
|
16
|
+
from braindecode.util import resolve_montage_name
|
|
17
|
+
|
|
16
18
|
from .base import Transform
|
|
17
19
|
from .functional import (
|
|
18
20
|
amplitude_scale,
|
|
@@ -703,7 +705,7 @@ def _get_standard_10_20_positions(raw_or_epoch=None, ordered_ch_names=None):
|
|
|
703
705
|
)
|
|
704
706
|
if ordered_ch_names is None:
|
|
705
707
|
ordered_ch_names = raw_or_epoch.info["ch_names"]
|
|
706
|
-
ten_twenty_montage = make_standard_montage("standard_1020")
|
|
708
|
+
ten_twenty_montage = make_standard_montage(resolve_montage_name("standard_1020"))
|
|
707
709
|
positions_dict = ten_twenty_montage.get_positions()["ch_pos"]
|
|
708
710
|
positions_subdict = {
|
|
709
711
|
k: positions_dict[k] for k in ordered_ch_names if k in positions_dict
|
|
@@ -729,7 +731,7 @@ class SensorsRotation(Transform):
|
|
|
729
731
|
`mne` through::
|
|
730
732
|
|
|
731
733
|
>>> ten_twenty_montage = mne.channels.make_standard_montage(
|
|
732
|
-
... 'standard_1020'
|
|
734
|
+
... 'standard_1020' # 'colin27_1020' on MNE >= 1.13
|
|
733
735
|
... ).get_positions()['ch_pos']
|
|
734
736
|
|
|
735
737
|
axis : 'x' | 'y' | 'z', optional
|
{braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/datasets/tuh.py
RENAMED
|
@@ -25,6 +25,7 @@ import pandas as pd
|
|
|
25
25
|
from joblib import Parallel, delayed
|
|
26
26
|
|
|
27
27
|
from braindecode.datasets.base import BaseConcatDataset, RawDataset
|
|
28
|
+
from braindecode.util import resolve_montage_name
|
|
28
29
|
|
|
29
30
|
|
|
30
31
|
class TUH(BaseConcatDataset):
|
|
@@ -182,7 +183,9 @@ class TUH(BaseConcatDataset):
|
|
|
182
183
|
}
|
|
183
184
|
raw.rename_channels(mapping_strip)
|
|
184
185
|
|
|
185
|
-
montage1005 = mne.channels.make_standard_montage(
|
|
186
|
+
montage1005 = mne.channels.make_standard_montage(
|
|
187
|
+
resolve_montage_name("standard_1005")
|
|
188
|
+
)
|
|
186
189
|
mapping_eeg_names = {
|
|
187
190
|
c.upper(): c for c in montage1005.ch_names if c.upper() in raw.ch_names
|
|
188
191
|
}
|
|
@@ -207,7 +210,9 @@ class TUH(BaseConcatDataset):
|
|
|
207
210
|
|
|
208
211
|
@staticmethod
|
|
209
212
|
def _set_montage(raw):
|
|
210
|
-
montage = mne.channels.make_standard_montage(
|
|
213
|
+
montage = mne.channels.make_standard_montage(
|
|
214
|
+
resolve_montage_name("standard_1005")
|
|
215
|
+
)
|
|
211
216
|
raw.set_montage(montage, on_missing="ignore")
|
|
212
217
|
|
|
213
218
|
@staticmethod
|
{braindecode-1.8.1.dev176535733 → braindecode-1.8.1.dev181104868}/braindecode/models/__init__.py
RENAMED
|
@@ -6,7 +6,9 @@ from .attn_sleep import AttnSleep
|
|
|
6
6
|
from .base import EEGModuleMixin
|
|
7
7
|
from .bendr import BENDR, InterpolatedBENDR
|
|
8
8
|
from .biot import BIOT, InterpolatedBIOT
|
|
9
|
+
from .brainbert import BrainBERT
|
|
9
10
|
from .brainmodule import BrainModule
|
|
11
|
+
from .brant import Brant
|
|
10
12
|
from .cbramod import CBraMod
|
|
11
13
|
from .codebrain import CodeBrain
|
|
12
14
|
from .contrawr import ContraWR
|
|
@@ -87,6 +89,7 @@ __all__ = [
|
|
|
87
89
|
"EEGModuleMixin",
|
|
88
90
|
"BIOT",
|
|
89
91
|
"BENDR",
|
|
92
|
+
"BrainBERT",
|
|
90
93
|
"CBraMod",
|
|
91
94
|
"CodeBrain",
|
|
92
95
|
"ContraWR",
|
|
@@ -95,6 +98,7 @@ __all__ = [
|
|
|
95
98
|
"Deep4Net",
|
|
96
99
|
"DeepSleepNet",
|
|
97
100
|
"BrainModule",
|
|
101
|
+
"Brant",
|
|
98
102
|
"EEGConformer",
|
|
99
103
|
"EEGDINO",
|
|
100
104
|
"EEGPT",
|
|
@@ -0,0 +1,448 @@
|
|
|
1
|
+
# Authors: Adam Mounir <am91ris@gmail.com>
|
|
2
|
+
#
|
|
3
|
+
# License: BSD (3-clause)
|
|
4
|
+
"""BrainBERT (Wang et al., ICLR 2023): a spectrogram Transformer for intracranial
|
|
5
|
+
signals, ported weight-for-weight from https://github.com/czlwang/BrainBERT with
|
|
6
|
+
the STFT front-end moved inside the model. See :class:`BrainBERT`.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import warnings
|
|
12
|
+
|
|
13
|
+
import torch
|
|
14
|
+
import torch.nn as nn
|
|
15
|
+
import torch.nn.functional as F
|
|
16
|
+
from einops.layers.torch import Rearrange, Reduce
|
|
17
|
+
|
|
18
|
+
from braindecode.functional import sinusoidal_positional_encoding
|
|
19
|
+
from braindecode.models.base import EEGModuleMixin
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class BrainBERT(EEGModuleMixin, nn.Module, license="unknown"):
|
|
23
|
+
r"""BrainBERT from Wang et al. (2023) [BrainBERT2023]_.
|
|
24
|
+
|
|
25
|
+
:bdg-danger:`Foundation Model` :bdg-info:`Attention/Transformer`
|
|
26
|
+
|
|
27
|
+
.. figure:: https://arxiv.org/html/2302.14367v1/figures/model.png
|
|
28
|
+
:align: center
|
|
29
|
+
:alt: BrainBERT architecture
|
|
30
|
+
|
|
31
|
+
BrainBERT is a self-supervised foundation model for intracranial signals
|
|
32
|
+
(sEEG/iEEG). It takes as input not the waveform but its **spectrogram**: a
|
|
33
|
+
short-time Fourier transform maps each channel onto a series of time frames,
|
|
34
|
+
and each frame is one token. A linear projection and a fixed sinusoidal
|
|
35
|
+
positional encoding are followed by a stack of standard Transformer encoder
|
|
36
|
+
layers. The model is pre-trained by masked spectrogram modelling, i.e. by
|
|
37
|
+
reconstructing masked time/frequency patches, and the representation of each
|
|
38
|
+
frame thus serves downstream decoding.
|
|
39
|
+
|
|
40
|
+
In the present implementation, we compute the STFT inside ``forward`` (the
|
|
41
|
+
``spectrogram`` submodule), so that the model still takes the
|
|
42
|
+
standard ``(batch, n_chans, n_times)`` input, whereas the upstream reference
|
|
43
|
+
takes a pre-computed spectrogram as input. The input encoding and the encoder
|
|
44
|
+
match the upstream ``MaskedTFModel`` to 1e-5.
|
|
45
|
+
|
|
46
|
+
The released checkpoint was trained on signals sampled at **2048 Hz** and
|
|
47
|
+
re-referenced with a Laplacian, with ``nperseg=400``, ``noverlap=350`` and the
|
|
48
|
+
first ``idx_freq_cutoff=40`` frequency bins. The defaults below give a modest,
|
|
49
|
+
ready-to-run model; the **released ("large") model** uses ``hidden_dim=768``,
|
|
50
|
+
``ffn_dim=3072``, ``n_heads=12`` and ``n_layers=6`` (about 43M parameters),
|
|
51
|
+
and passing these values reproduces it.
|
|
52
|
+
|
|
53
|
+
**The pooling follows the published downstream protocol.** Upstream processes
|
|
54
|
+
one electrode at a time, averages the ``pool_n_frames=10`` encoder outputs
|
|
55
|
+
centred on the window (``outputs[:, middle-5:middle+5].mean`` in
|
|
56
|
+
``preprocessors/spec_pretrained.py``) and applies a linear probe; the average
|
|
57
|
+
over every frame appears in that file only as a commented-out alternative. We
|
|
58
|
+
use the average over the central frames and add a mean over channels, which
|
|
59
|
+
is the identity for ``n_chans=1``: a single-channel BrainBERT thus reproduces
|
|
60
|
+
the upstream feature exactly, and several channels remain supported as the
|
|
61
|
+
braindecode generalisation. Pass ``pool_n_frames=None`` to average every
|
|
62
|
+
frame. To obtain one output per electrode as upstream does, build the model
|
|
63
|
+
with ``n_chans=1`` and stack the electrodes in the batch.
|
|
64
|
+
|
|
65
|
+
.. important::
|
|
66
|
+
**Pre-trained weights are available.** The checkpoint released by the
|
|
67
|
+
authors is available from the Hugging Face Hub::
|
|
68
|
+
|
|
69
|
+
model = BrainBERT.from_pretrained(
|
|
70
|
+
"braindecode/brainbert-pretrained", n_outputs=2
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
It has the "large" configuration above; ``n_chans``, ``n_times`` and
|
|
74
|
+
``n_outputs`` may change freely, since the frames are pooled and the head
|
|
75
|
+
is specific to the task (pass these, not ``chs_info`` or
|
|
76
|
+
``input_window_seconds``, which conflict with the saved config). The
|
|
77
|
+
upstream repository provides no LICENSE file, so we mark the licence of
|
|
78
|
+
the weights as unknown rather than assume a permissive one.
|
|
79
|
+
|
|
80
|
+
.. note::
|
|
81
|
+
As in the upstream front-end, a channel whose z-scored spectrogram is
|
|
82
|
+
flat (a dead channel) is set to ones, and a ``NaN`` sample zeroes that
|
|
83
|
+
channel's whole spectrogram for the window, without a warning.
|
|
84
|
+
|
|
85
|
+
.. versionadded:: 1.9
|
|
86
|
+
|
|
87
|
+
Parameters
|
|
88
|
+
----------
|
|
89
|
+
hidden_dim : int, optional
|
|
90
|
+
Transformer model width ``D``. Default 192. The released model uses 768.
|
|
91
|
+
ffn_dim : int, optional
|
|
92
|
+
Inner dimension of the Transformer feed-forward blocks. Default 384.
|
|
93
|
+
The released model uses 3072.
|
|
94
|
+
n_layers : int, optional
|
|
95
|
+
Number of Transformer encoder layers. Default 2. Released model: 6.
|
|
96
|
+
n_heads : int, optional
|
|
97
|
+
Number of attention heads. Default 4. Released model: 12.
|
|
98
|
+
nperseg : int, optional
|
|
99
|
+
STFT window length in samples. Default 400.
|
|
100
|
+
noverlap : int, optional
|
|
101
|
+
STFT overlap in samples. Default 350 (hop of 50).
|
|
102
|
+
idx_freq_cutoff : int, optional
|
|
103
|
+
Number of low-frequency STFT bins kept; the Transformer ``input_dim``.
|
|
104
|
+
This is a **bin index**, not a frequency in Hz: the default 40 bins
|
|
105
|
+
reach about 200 Hz at 2048 Hz with ``nperseg=400``. Default 40.
|
|
106
|
+
stft_clip : int, optional
|
|
107
|
+
Boundary frames trimmed from each end of the spectrogram. Default 10,
|
|
108
|
+
as in the upstream ``preprocessors/stft.py`` used with the released
|
|
109
|
+
checkpoint (the demo notebook uses 5; see ``stft_zscore_before_clip``).
|
|
110
|
+
stft_zscore_before_clip : bool, optional
|
|
111
|
+
Whether the spectrogram is z-scored before the boundary frames are
|
|
112
|
+
trimmed. Default ``True``, which together with ``stft_clip=10``
|
|
113
|
+
reproduces the recipe behind the published numbers. Set to ``False``
|
|
114
|
+
with ``stft_clip=5`` to reproduce the upstream demo notebook instead;
|
|
115
|
+
the two recipes are close but not equal, and they yield sequences of
|
|
116
|
+
different length.
|
|
117
|
+
pool_n_frames : int or None, optional
|
|
118
|
+
Number of encoder frames, centred on the window, averaged into the
|
|
119
|
+
pooled representation. Default 10, as upstream. ``None`` averages all
|
|
120
|
+
frames.
|
|
121
|
+
activation : type[nn.Module], optional
|
|
122
|
+
Transformer feed-forward activation class. Default ``nn.GELU`` (as
|
|
123
|
+
pretrained).
|
|
124
|
+
drop_prob : float, optional
|
|
125
|
+
Dropout probability. Default 0.1.
|
|
126
|
+
|
|
127
|
+
References
|
|
128
|
+
----------
|
|
129
|
+
.. [BrainBERT2023] Wang, C., Subramaniam, V., Yaari, A.U., Kreiman, G.,
|
|
130
|
+
Katz, B., Cases, I. and Barbu, A., 2023. BrainBERT: Self-supervised
|
|
131
|
+
representation learning for intracranial recordings. In International
|
|
132
|
+
Conference on Learning Representations, ICLR.
|
|
133
|
+
Code: https://github.com/czlwang/BrainBERT
|
|
134
|
+
"""
|
|
135
|
+
|
|
136
|
+
def __init__(
|
|
137
|
+
self,
|
|
138
|
+
# --- BrainBERT hyper-parameters (modest defaults; "large" in docstring) ---
|
|
139
|
+
hidden_dim: int = 192,
|
|
140
|
+
ffn_dim: int = 384,
|
|
141
|
+
n_layers: int = 2,
|
|
142
|
+
n_heads: int = 4,
|
|
143
|
+
nperseg: int = 400,
|
|
144
|
+
noverlap: int = 350,
|
|
145
|
+
idx_freq_cutoff: int = 40,
|
|
146
|
+
stft_clip: int = 10,
|
|
147
|
+
stft_zscore_before_clip: bool = True,
|
|
148
|
+
pool_n_frames: int | None = 10,
|
|
149
|
+
activation: type[nn.Module] = nn.GELU,
|
|
150
|
+
drop_prob: float = 0.1,
|
|
151
|
+
# --- braindecode mandatory signal parameters ---
|
|
152
|
+
n_outputs=None,
|
|
153
|
+
n_chans=None,
|
|
154
|
+
chs_info=None,
|
|
155
|
+
n_times=None,
|
|
156
|
+
input_window_seconds=None,
|
|
157
|
+
sfreq=None,
|
|
158
|
+
):
|
|
159
|
+
super().__init__(
|
|
160
|
+
n_outputs=n_outputs,
|
|
161
|
+
n_chans=n_chans,
|
|
162
|
+
chs_info=chs_info,
|
|
163
|
+
n_times=n_times,
|
|
164
|
+
input_window_seconds=input_window_seconds,
|
|
165
|
+
sfreq=sfreq,
|
|
166
|
+
)
|
|
167
|
+
del n_outputs, n_chans, chs_info, n_times, input_window_seconds, sfreq
|
|
168
|
+
|
|
169
|
+
# Refuse rather than silently fall back to a different pooling: the
|
|
170
|
+
# number of frames averaged is part of the published protocol.
|
|
171
|
+
if pool_n_frames is not None and pool_n_frames <= 0:
|
|
172
|
+
raise ValueError(
|
|
173
|
+
f"pool_n_frames must be positive; got {pool_n_frames}. "
|
|
174
|
+
"Pass None to average every frame instead."
|
|
175
|
+
)
|
|
176
|
+
self.pool_n_frames = pool_n_frames
|
|
177
|
+
self.min_frames = 1 if pool_n_frames is None else pool_n_frames
|
|
178
|
+
if self._sfreq is not None and self._sfreq != 2048:
|
|
179
|
+
warnings.warn(
|
|
180
|
+
f"BrainBERT was pretrained at 2048 Hz; the STFT bins of a {self._sfreq}"
|
|
181
|
+
" Hz signal cover other frequencies. Resample to 2048 Hz.",
|
|
182
|
+
stacklevel=2,
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
self.spectrogram = _STFTSpectrogram(
|
|
186
|
+
nperseg=nperseg,
|
|
187
|
+
noverlap=noverlap,
|
|
188
|
+
idx_freq_cutoff=idx_freq_cutoff,
|
|
189
|
+
clip=stft_clip,
|
|
190
|
+
zscore_before_clip=stft_zscore_before_clip,
|
|
191
|
+
)
|
|
192
|
+
n_frames = self.spectrogram.n_frames(self.n_times)
|
|
193
|
+
if n_frames < self.min_frames:
|
|
194
|
+
min_n_times = self.spectrogram.min_n_times(self.min_frames)
|
|
195
|
+
raise ValueError(
|
|
196
|
+
f"n_times={self.n_times} gives {n_frames} STFT frames; the pooling "
|
|
197
|
+
f"needs {self.min_frames}, i.e. n_times >= {min_n_times} with these "
|
|
198
|
+
"STFT settings."
|
|
199
|
+
)
|
|
200
|
+
|
|
201
|
+
# The re-hosted Hub checkpoint already uses this port's names. The
|
|
202
|
+
# authors' original ``.pth`` calls the input block ``input_encoding``;
|
|
203
|
+
# load ``torch.load(path, weights_only=False)["model"]`` with
|
|
204
|
+
# ``strict=False`` (its fixed ``pe`` table and pre-training head are
|
|
205
|
+
# dropped).
|
|
206
|
+
self.mapping = {
|
|
207
|
+
f"input_encoding.{name}": f"input_embedding.{name}"
|
|
208
|
+
for name in (
|
|
209
|
+
"in_proj.weight",
|
|
210
|
+
"in_proj.bias",
|
|
211
|
+
"layer_norm.weight",
|
|
212
|
+
"layer_norm.bias",
|
|
213
|
+
)
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
self.input_embedding = _BrainBERTInputEmbedding(
|
|
217
|
+
input_dim=idx_freq_cutoff,
|
|
218
|
+
hidden_dim=hidden_dim,
|
|
219
|
+
drop_prob=drop_prob,
|
|
220
|
+
# upstream table size; inputs longer than n_times stay allowed.
|
|
221
|
+
max_len=max(5000, n_frames),
|
|
222
|
+
)
|
|
223
|
+
encoder_layer = nn.TransformerEncoderLayer(
|
|
224
|
+
d_model=hidden_dim,
|
|
225
|
+
nhead=n_heads,
|
|
226
|
+
dim_feedforward=ffn_dim,
|
|
227
|
+
activation=activation(),
|
|
228
|
+
dropout=drop_prob,
|
|
229
|
+
batch_first=True,
|
|
230
|
+
)
|
|
231
|
+
# No padding mask is ever passed, so the nested-tensor fast path (and its
|
|
232
|
+
# warning for activations other than ReLU/GELU) is simply off.
|
|
233
|
+
self.transformer = nn.TransformerEncoder(
|
|
234
|
+
encoder_layer, num_layers=n_layers, enable_nested_tensor=False
|
|
235
|
+
)
|
|
236
|
+
# Each channel is its own sequence for the Transformer, as upstream feeds
|
|
237
|
+
# one electrode at a time; the pooling then averages frames and channels.
|
|
238
|
+
self.merge_channels = Rearrange(
|
|
239
|
+
"batch chans frames bins -> (batch chans) frames bins"
|
|
240
|
+
)
|
|
241
|
+
self.split_channels = Rearrange(
|
|
242
|
+
"(batch chans) frames dim -> batch chans frames dim", chans=self.n_chans
|
|
243
|
+
)
|
|
244
|
+
self.pool = Reduce("batch chans frames dim -> batch dim", "mean")
|
|
245
|
+
# Upstream's downstream probe is a bare linear layer
|
|
246
|
+
# (``models/linear_wav_baseline.py``), with no normalisation in front.
|
|
247
|
+
self.final_layer = nn.Linear(hidden_dim, self.n_outputs)
|
|
248
|
+
|
|
249
|
+
def reset_head(self, n_outputs: int) -> None:
|
|
250
|
+
"""Swap the classification head for a new number of outputs."""
|
|
251
|
+
self._set_n_outputs(n_outputs)
|
|
252
|
+
head = nn.Linear(self.final_layer.in_features, n_outputs)
|
|
253
|
+
self.final_layer = head.to(self.final_layer.weight)
|
|
254
|
+
|
|
255
|
+
def forward(self, x: torch.Tensor, return_features: bool = False):
|
|
256
|
+
"""Decode a batch of signals.
|
|
257
|
+
|
|
258
|
+
Parameters
|
|
259
|
+
----------
|
|
260
|
+
x : torch.Tensor
|
|
261
|
+
Input of shape ``(batch, n_chans, n_times)``.
|
|
262
|
+
return_features : bool
|
|
263
|
+
If ``True``, return the pooled encoder embedding instead of the
|
|
264
|
+
class logits, as ``{"features": pooled, "cls_token": None}``
|
|
265
|
+
(braindecode foundation-model convention). BrainBERT pools the
|
|
266
|
+
centre frames and then the channels, and has no class token, hence
|
|
267
|
+
``cls_token`` is ``None``. A scripted model (``torch.jit.script``)
|
|
268
|
+
ignores this flag and always returns the logits.
|
|
269
|
+
|
|
270
|
+
Returns
|
|
271
|
+
-------
|
|
272
|
+
torch.Tensor or dict
|
|
273
|
+
Class logits of shape ``(batch, n_outputs)``, or the feature dict
|
|
274
|
+
``{"features", "cls_token"}`` when ``return_features`` is set.
|
|
275
|
+
"""
|
|
276
|
+
if x.shape[1] != self.n_chans:
|
|
277
|
+
raise ValueError(f"Expected {self.n_chans} channels, got {x.shape[1]}.")
|
|
278
|
+
|
|
279
|
+
# 1. spectrogram front-end.
|
|
280
|
+
spec = self.spectrogram(x) # (batch, n_chans, n_frames, idx_freq_cutoff)
|
|
281
|
+
n_frames = spec.shape[2]
|
|
282
|
+
# An input shorter than the model was built for must still give enough
|
|
283
|
+
# frames, otherwise the centre slice below silently shrinks.
|
|
284
|
+
if n_frames < self.min_frames:
|
|
285
|
+
raise ValueError(
|
|
286
|
+
f"Input of {x.shape[-1]} samples gives {n_frames} spectrogram "
|
|
287
|
+
f"frames; at least {self.min_frames} are needed."
|
|
288
|
+
)
|
|
289
|
+
spec = self.merge_channels(spec) # (batch * n_chans, n_frames, idx_freq_cutoff)
|
|
290
|
+
|
|
291
|
+
# 2. input encoding + Transformer over the sequence of frames.
|
|
292
|
+
h = self.input_embedding(spec) # (batch * n_chans, n_frames, hidden_dim)
|
|
293
|
+
z = self.transformer(h) # (batch * n_chans, n_frames, hidden_dim)
|
|
294
|
+
z = self.split_channels(z) # (batch, n_chans, n_frames, hidden_dim)
|
|
295
|
+
|
|
296
|
+
# 3. pool the centre frames, then frames and channels.
|
|
297
|
+
if self.pool_n_frames is not None:
|
|
298
|
+
start = n_frames // 2 - self.pool_n_frames // 2
|
|
299
|
+
z = z[:, :, start : start + self.pool_n_frames]
|
|
300
|
+
pooled = self.pool(z) # (batch, hidden_dim)
|
|
301
|
+
logits = self.final_layer(pooled)
|
|
302
|
+
if return_features:
|
|
303
|
+
if torch.jit.is_scripting():
|
|
304
|
+
return logits
|
|
305
|
+
return {"features": pooled, "cls_token": None} # nosec B105
|
|
306
|
+
return logits
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
class _STFTSpectrogram(nn.Module):
|
|
310
|
+
"""Magnitude STFT spectrogram, computed inside the model.
|
|
311
|
+
|
|
312
|
+
Pure-torch replacement for BrainBERT's scipy front-end (``signal.stft`` +
|
|
313
|
+
magnitude + z-score), so the model consumes raw signal rather than a
|
|
314
|
+
pre-extracted spectrogram. No learnable parameters. Framing follows
|
|
315
|
+
:func:`scipy.signal.stft` with ``boundary="zeros"``, ``padded=True``, a
|
|
316
|
+
periodic Hann window and ``scaling="spectrum"``.
|
|
317
|
+
|
|
318
|
+
Upstream ships two recipes that differ in the order of the z-score and the
|
|
319
|
+
boundary trimming, and in how many frames are trimmed; see ``stft_clip`` and
|
|
320
|
+
``stft_zscore_before_clip`` in :class:`BrainBERT`.
|
|
321
|
+
|
|
322
|
+
Parameters
|
|
323
|
+
----------
|
|
324
|
+
nperseg : int
|
|
325
|
+
STFT window length, in samples.
|
|
326
|
+
noverlap : int
|
|
327
|
+
Number of samples of overlap between consecutive windows.
|
|
328
|
+
idx_freq_cutoff : int
|
|
329
|
+
Number of low-frequency one-sided bins kept (a bin index, not Hz).
|
|
330
|
+
clip : int
|
|
331
|
+
Number of boundary frames trimmed from each end.
|
|
332
|
+
zscore_before_clip : bool
|
|
333
|
+
Whether the per-bin z-score over time precedes the trimming.
|
|
334
|
+
"""
|
|
335
|
+
|
|
336
|
+
def __init__(
|
|
337
|
+
self,
|
|
338
|
+
nperseg: int = 400,
|
|
339
|
+
noverlap: int = 350,
|
|
340
|
+
idx_freq_cutoff: int = 40,
|
|
341
|
+
clip: int = 10,
|
|
342
|
+
zscore_before_clip: bool = True,
|
|
343
|
+
):
|
|
344
|
+
super().__init__()
|
|
345
|
+
if not 0 <= noverlap < nperseg:
|
|
346
|
+
raise ValueError(
|
|
347
|
+
f"noverlap ({noverlap}) must be in [0, nperseg={nperseg})."
|
|
348
|
+
)
|
|
349
|
+
if not 1 <= idx_freq_cutoff <= nperseg // 2 + 1:
|
|
350
|
+
raise ValueError(
|
|
351
|
+
f"idx_freq_cutoff ({idx_freq_cutoff}) must be in [1, "
|
|
352
|
+
f"{nperseg // 2 + 1}] for nperseg={nperseg}."
|
|
353
|
+
)
|
|
354
|
+
if clip < 0:
|
|
355
|
+
raise ValueError(f"clip must be >= 0; got {clip}.")
|
|
356
|
+
self.nperseg = nperseg
|
|
357
|
+
self.idx_freq_cutoff = idx_freq_cutoff
|
|
358
|
+
self.clip = clip
|
|
359
|
+
self.zscore_before_clip = zscore_before_clip
|
|
360
|
+
# "zscore" as upstream; pipelines that apply their own statistics (the
|
|
361
|
+
# Neuroprobe global z-score recipes) set it to "none" on the instance.
|
|
362
|
+
self.normalizing = "zscore"
|
|
363
|
+
self.step = nperseg - noverlap
|
|
364
|
+
self.boundary_pad = nperseg // 2 # scipy boundary="zeros"
|
|
365
|
+
# scipy's periodic Hann window; non-persistent, rebuilt in __init__.
|
|
366
|
+
self.register_buffer(
|
|
367
|
+
"window", torch.hann_window(nperseg, periodic=True), persistent=False
|
|
368
|
+
)
|
|
369
|
+
|
|
370
|
+
def _padded_length(self, n_times: int) -> int:
|
|
371
|
+
"""Signal length after scipy's ``boundary="zeros"`` and ``padded=True``."""
|
|
372
|
+
length = n_times + 2 * self.boundary_pad
|
|
373
|
+
return length + (-(length - self.nperseg)) % self.step
|
|
374
|
+
|
|
375
|
+
def n_frames(self, n_times: int) -> int:
|
|
376
|
+
"""Number of output frames for a signal of ``n_times`` samples."""
|
|
377
|
+
n_seg = (self._padded_length(n_times) - self.nperseg) // self.step + 1
|
|
378
|
+
return n_seg - 2 * self.clip
|
|
379
|
+
|
|
380
|
+
def min_n_times(self, n_frames: int) -> int:
|
|
381
|
+
"""Shortest signal that yields at least ``n_frames`` output frames."""
|
|
382
|
+
n_seg = n_frames + 2 * self.clip
|
|
383
|
+
return self.nperseg + (n_seg - 2) * self.step + 1 - 2 * self.boundary_pad
|
|
384
|
+
|
|
385
|
+
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
|
386
|
+
"""``(batch, n_chans, n_times)`` -> ``(batch, n_chans, n_frames, cutoff)``."""
|
|
387
|
+
# scipy boundary="zeros": half a window of zeros on each end, then
|
|
388
|
+
# padded=True: extend so an integer number of segments fits.
|
|
389
|
+
if not x.is_floating_point():
|
|
390
|
+
raise TypeError(
|
|
391
|
+
f"BrainBERT expects a floating-point signal, got {x.dtype}."
|
|
392
|
+
)
|
|
393
|
+
n_times = x.shape[-1]
|
|
394
|
+
right_pad = self._padded_length(n_times) - n_times - self.boundary_pad
|
|
395
|
+
xp = F.pad(x, (self.boundary_pad, right_pad)) # (batch, n_chans, padded)
|
|
396
|
+
frames = xp.unfold(-1, self.nperseg, self.step) # (b, c, n_frames, nperseg)
|
|
397
|
+
win = self.window.to(frames.dtype)
|
|
398
|
+
scale = 1.0 / win.sum() # scaling="spectrum"
|
|
399
|
+
spec = torch.fft.rfft(frames * win, dim=-1) # (b, c, n_frames, nperseg//2+1)
|
|
400
|
+
low = spec[..., : self.idx_freq_cutoff] * scale # (b, c, n_frames, cutoff)
|
|
401
|
+
mag = low.abs()
|
|
402
|
+
# The time axis is -2. The z-score and the trimming happen in the order
|
|
403
|
+
# the recipe dictates (see the class docstring).
|
|
404
|
+
if self.normalizing == "zscore" and self.zscore_before_clip:
|
|
405
|
+
mag = self._zscore(mag)
|
|
406
|
+
# upstream stft.py: a flat (e.g. dead) channel becomes ones. Written
|
|
407
|
+
# branch-free so torch.export sees no data-dependent guard.
|
|
408
|
+
degenerate = mag.flatten(start_dim=-2).std(dim=-1) == 0
|
|
409
|
+
mag = mag.masked_fill(degenerate[..., None, None], 1.0)
|
|
410
|
+
if self.clip:
|
|
411
|
+
mag = mag[..., self.clip : -self.clip, :]
|
|
412
|
+
if self.normalizing == "zscore" and not self.zscore_before_clip:
|
|
413
|
+
mag = self._zscore(mag)
|
|
414
|
+
# upstream stft.py: NaNs surviving the statistics are zeroed, not kept.
|
|
415
|
+
return torch.nan_to_num(mag, nan=0.0)
|
|
416
|
+
|
|
417
|
+
@staticmethod
|
|
418
|
+
def _zscore(mag: torch.Tensor) -> torch.Tensor:
|
|
419
|
+
"""Per-bin z-score over time (ddof=0); zero standard deviations become one."""
|
|
420
|
+
mean = mag.mean(dim=-2, keepdim=True)
|
|
421
|
+
std = mag.std(dim=-2, unbiased=False, keepdim=True)
|
|
422
|
+
std = std.masked_fill(std == 0, 1.0)
|
|
423
|
+
return (mag - mean) / std
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
class _BrainBERTInputEmbedding(nn.Module):
|
|
427
|
+
"""Upstream ``TransformerEncoderInput``: linear projection, fixed sinusoidal
|
|
428
|
+
position encoding, LayerNorm and dropout. ``in_proj`` and ``layer_norm``
|
|
429
|
+
keep the upstream names; the sinusoidal table is rebuilt, not persisted."""
|
|
430
|
+
|
|
431
|
+
def __init__(self, input_dim: int, hidden_dim: int, drop_prob: float, max_len: int):
|
|
432
|
+
super().__init__()
|
|
433
|
+
self.in_proj = nn.Linear(input_dim, hidden_dim)
|
|
434
|
+
self.layer_norm = nn.LayerNorm(hidden_dim)
|
|
435
|
+
self.dropout = nn.Dropout(p=drop_prob)
|
|
436
|
+
self.register_buffer(
|
|
437
|
+
"pe", sinusoidal_positional_encoding(max_len, hidden_dim), persistent=False
|
|
438
|
+
)
|
|
439
|
+
|
|
440
|
+
def forward(self, spec: torch.Tensor) -> torch.Tensor:
|
|
441
|
+
h = self.in_proj(spec) # (batch, n_frames, hidden_dim)
|
|
442
|
+
if h.size(1) > self.pe.size(0):
|
|
443
|
+
raise ValueError(
|
|
444
|
+
f"{h.size(1)} frames exceed the positional table ({self.pe.size(0)})."
|
|
445
|
+
)
|
|
446
|
+
h = h + self.pe[: h.size(1)]
|
|
447
|
+
h = self.layer_norm(h)
|
|
448
|
+
return self.dropout(h)
|