Braindecode 1.2.0.dev168908090__tar.gz → 1.2.0.dev169062562__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.2.0.dev168908090/braindecode.egg-info → braindecode-1.2.0.dev169062562}/PKG-INFO +1 -1
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/atcnet.py +12 -152
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/eegconformer.py +15 -111
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/eegnet.py +4 -54
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/modules/attention.py +3 -6
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/modules/convolution.py +7 -10
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/modules/filter.py +6 -8
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/training/scoring.py +8 -2
- braindecode-1.2.0.dev169062562/braindecode/version.py +1 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/visualization/gradients.py +1 -6
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562/braindecode.egg-info}/PKG-INFO +1 -1
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/docs/conf.py +0 -3
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/docs/whats_new.rst +0 -7
- braindecode-1.2.0.dev168908090/braindecode/version.py +0 -1
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/LICENSE.txt +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/MANIFEST.in +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/NOTICE.txt +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/README.rst +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/__init__.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/augmentation/__init__.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/augmentation/base.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/augmentation/functional.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/augmentation/transforms.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/classifier.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/datasets/__init__.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/datasets/base.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/datasets/bbci.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/datasets/bcicomp.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/datasets/bids.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/datasets/mne.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/datasets/moabb.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/datasets/nmt.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/datasets/sleep_physio_challe_18.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/datasets/sleep_physionet.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/datasets/tuh.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/datasets/xy.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/datautil/__init__.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/datautil/serialization.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/datautil/util.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/eegneuralnet.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/functional/__init__.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/functional/functions.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/functional/initialization.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/__init__.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/attentionbasenet.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/base.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/biot.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/contrawr.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/ctnet.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/deep4.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/deepsleepnet.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/eeginception_erp.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/eeginception_mi.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/eegitnet.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/eegminer.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/eegnex.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/eegresnet.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/eegsimpleconv.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/eegtcnet.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/fbcnet.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/fblightconvnet.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/fbmsnet.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/hybrid.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/ifnet.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/labram.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/msvtnet.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/sccnet.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/shallow_fbcsp.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/signal_jepa.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/sinc_shallow.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/sleep_stager_blanco_2020.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/sleep_stager_chambon_2018.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/sleep_stager_eldele_2021.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/sparcnet.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/summary.csv +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/syncnet.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/tcn.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/tidnet.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/tsinception.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/usleep.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/util.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/modules/__init__.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/modules/activation.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/modules/blocks.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/modules/layers.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/modules/linear.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/modules/parametrization.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/modules/stats.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/modules/util.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/modules/wrapper.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/preprocessing/__init__.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/preprocessing/mne_preprocess.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/preprocessing/preprocess.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/preprocessing/windowers.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/regressor.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/samplers/__init__.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/samplers/base.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/samplers/ssl.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/training/__init__.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/training/callbacks.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/training/losses.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/util.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/visualization/__init__.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/visualization/confusion_matrices.py +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode.egg-info/SOURCES.txt +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode.egg-info/dependency_links.txt +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode.egg-info/requires.txt +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode.egg-info/top_level.txt +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/docs/Makefile +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/docs/_templates/autosummary/class.rst +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/docs/_templates/autosummary/function.rst +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/docs/api.rst +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/docs/cite.rst +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/docs/help.rst +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/docs/index.rst +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/docs/install/install.rst +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/docs/install/install_pip.rst +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/docs/install/install_source.rst +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/docs/models_summary.rst +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/docs/sg_execution_times.rst +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/pyproject.toml +0 -0
- {braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/setup.cfg +0 -0
{braindecode-1.2.0.dev168908090/braindecode.egg-info → braindecode-1.2.0.dev169062562}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: braindecode
|
|
3
|
-
Version: 1.2.0.
|
|
3
|
+
Version: 1.2.0.dev169062562
|
|
4
4
|
Summary: Deep learning software to decode EEG, ECG or MEG signals
|
|
5
5
|
Author-email: Robin Tibor Schirrmeister <robintibor@gmail.com>
|
|
6
6
|
Maintainer-email: Alexandre Gramfort <agramfort@meta.com>, Bruno Aristimunha Pinto <b.aristimunha@gmail.com>, Robin Tibor Schirrmeister <robintibor@gmail.com>
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/atcnet.py
RENAMED
|
@@ -13,154 +13,13 @@ from braindecode.modules import CausalConv1d, Ensure4d, MaxNormLinear
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
class ATCNet(EEGModuleMixin, nn.Module):
|
|
16
|
-
"""ATCNet from Altaheri et al. (2022) [1]_
|
|
16
|
+
"""ATCNet model from Altaheri et al. (2022) [1]_
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
Pytorch implementation based on official tensorflow code [2]_.
|
|
19
19
|
|
|
20
20
|
.. figure:: https://user-images.githubusercontent.com/25565236/185449791-e8539453-d4fa-41e1-865a-2cf7e91f60ef.png
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
:width: 650px
|
|
24
|
-
|
|
25
|
-
.. rubric:: Architectural Overview
|
|
26
|
-
|
|
27
|
-
ATCNet is a *convolution-first* architecture augmented with a *lightweight attention–TCN*
|
|
28
|
-
sequence module. The end-to-end flow is:
|
|
29
|
-
|
|
30
|
-
- (i) :class:`_ConvBlock` learns temporal filter-banks and spatial projections (EEGNet-style),
|
|
31
|
-
downsampling time to a compact feature map;
|
|
32
|
-
|
|
33
|
-
- (ii) Sliding Windows carve overlapping temporal windows from this map;
|
|
34
|
-
|
|
35
|
-
- (iii) for each window, :class:`_AttentionBlock` applies small multi-head self-attention
|
|
36
|
-
over time, followed by a :class:`_TCNResidualBlock` stack (causal, dilated);
|
|
37
|
-
|
|
38
|
-
- (iv) window-level features are aggregated (mean of window logits or concatenation)
|
|
39
|
-
and mapped via a max-norm–constrained linear layer.
|
|
40
|
-
|
|
41
|
-
Relative to ViT, ATCNet replaces linear patch projection with learned *temporal–spatial*
|
|
42
|
-
convolutions; it processes *parallel* window encoders (attention→TCN) instead of a deep
|
|
43
|
-
stack; and swaps the MLP head for a TCN suited to 1-D EEG sequences.
|
|
44
|
-
|
|
45
|
-
.. rubric:: Macro Components
|
|
46
|
-
|
|
47
|
-
- :class:`_ConvBlock` **(Shallow conv stem → feature map)**
|
|
48
|
-
|
|
49
|
-
- *Operations.*
|
|
50
|
-
- **Temporal conv** (:class:`torch.nn.Conv2d`) with kernel ``(L_t, 1)`` builds a
|
|
51
|
-
FIR-like filter bank (``F1`` maps).
|
|
52
|
-
- **Depthwise spatial conv** (:class:`torch.nn.Conv2d`, ``groups=F1``) with kernel
|
|
53
|
-
``(1, n_chans)`` learns per-filter spatial projections (akin to EEGNet’s CSP-like step).
|
|
54
|
-
- **BN → ELU → AvgPool → Dropout** to stabilize and condense activations.
|
|
55
|
-
- **Refining temporal conv** (:class:`torch.nn.Conv2d`) with kernel ``(L_r, 1)`` +
|
|
56
|
-
**BN → ELU → AvgPool → Dropout**.
|
|
57
|
-
|
|
58
|
-
The output shape is ``(B, F2, T_c, 1)`` with ``F2 = F1·D`` and ``T_c = T/(P1·P2)``.
|
|
59
|
-
Temporal kernels behave as FIR filters; the depthwise-spatial conv yields frequency-specific
|
|
60
|
-
topographies. Pooling acts as a local integrator, reducing variance and imposing a
|
|
61
|
-
useful inductive bias on short EEG windows.
|
|
62
|
-
|
|
63
|
-
- **Sliding-Window Sequencer**
|
|
64
|
-
|
|
65
|
-
From the condensed time axis (length ``T_c``), ATCNet forms ``n`` overlapping windows
|
|
66
|
-
of width ``T_w = T_c - n + 1`` (one start per index). Each window produces a sequence
|
|
67
|
-
``(B, F2, T_w)`` forwarded to its own attention–TCN branch. This creates *parallel*
|
|
68
|
-
encoders over shifted contexts and is key to robustness on nonstationary EEG.
|
|
69
|
-
|
|
70
|
-
- :class:`_AttentionBlock` **(small MHA on temporal positions)**
|
|
71
|
-
|
|
72
|
-
- *Operations.*
|
|
73
|
-
- Rearrange to ``(B, T_w, F2)``,
|
|
74
|
-
- Normalization :class:`torch.nn.LayerNorm`
|
|
75
|
-
- Custom MultiHeadAttention :class:`_MHA` (``num_heads=H``, per-head dim ``d_h``) + residual add,
|
|
76
|
-
- Dropout :class:`torch.nn.Dropout`
|
|
77
|
-
- Rearrange back to ``(B, F2, T_w)``.
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
**Note**: Attention is *local to a window* and purely temporal.
|
|
81
|
-
|
|
82
|
-
*Role.* Re-weights evidence across the window, letting the model emphasize informative
|
|
83
|
-
segments (onsets, bursts) before causal convolutions aggregate history.
|
|
84
|
-
|
|
85
|
-
- :class:`_TCNResidualBlock` **(causal dilated temporal CNN)**
|
|
86
|
-
|
|
87
|
-
- *Operations.*
|
|
88
|
-
- Two :class:`braindecode.modules.CausalConv1d` layers per block with dilation ``1, 2, 4, …``
|
|
89
|
-
- Across blocks of `torch.nn.ELU` + `torch.nn.BatchNorm1d` + `torch.nn.Dropout`) +
|
|
90
|
-
a residual (identity or 1x1 mapping).
|
|
91
|
-
- The final feature used per window is the *last* causal step ``[..., -1]`` (forecast-style).
|
|
92
|
-
|
|
93
|
-
*Role.* Efficient long-range temporal integration with stable gradients; the dilated
|
|
94
|
-
receptive field complements attention’s soft selection.
|
|
95
|
-
|
|
96
|
-
- **Aggregation & Classifier**
|
|
97
|
-
|
|
98
|
-
- *Operations.*
|
|
99
|
-
- Either (a) map each window feature ``(B, F2)`` to logits via :class:`braindecode.modules.MaxNormLinear`
|
|
100
|
-
and **average** across windows (default, matching official code), or
|
|
101
|
-
- (b) **concatenate** all window features ``(B, n·F2)`` and apply a single :class:`MaxNormLinear`.
|
|
102
|
-
The max-norm constraint regularizes the readout.
|
|
103
|
-
|
|
104
|
-
.. rubric:: Convolutional Details
|
|
105
|
-
|
|
106
|
-
- **Temporal.** Temporal structure is learned in three places:
|
|
107
|
-
- (1) the stem’s wide ``(L_t, 1)`` conv (learned filter bank),
|
|
108
|
-
- (2) the refining ``(L_r, 1)`` conv after pooling (short-term dynamics), and
|
|
109
|
-
- (3) the TCN’s causal 1-D convolutions with exponentially increasing dilation
|
|
110
|
-
(long-range dependencies). The minimum sequence length required by the TCN stack is
|
|
111
|
-
``(K_t - 1)·2^{L-1} + 1``; the implementation *auto-scales* kernels/pools/windows
|
|
112
|
-
when inputs are shorter to preserve feasibility.
|
|
113
|
-
|
|
114
|
-
- **Spatial.** A depthwise spatial conv spans the **full montage** (kernel ``(1, n_chans)``),
|
|
115
|
-
producing *per-temporal-filter* spatial projections (no cross-filter mixing at this step).
|
|
116
|
-
This mirrors EEGNet’s interpretability: each temporal filter has its own spatial pattern.
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
.. rubric:: Attention / Sequential Modules
|
|
120
|
-
|
|
121
|
-
- **Type.** Multi-head self-attention with ``H`` heads and per-head dim ``d_h`` implemented
|
|
122
|
-
in :class:`_MHA`, allowing ``embed_dim = H·d_h`` independent of input and output dims.
|
|
123
|
-
- **Shapes.** ``(B, F2, T_w) → (B, T_w, F2) → (B, F2, T_w)``. Attention operates along
|
|
124
|
-
the **temporal** axis within a window; channels/features stay in the embedding dim ``F2``.
|
|
125
|
-
- **Role.** Highlights salient temporal positions prior to causal convolution; small attention
|
|
126
|
-
keeps compute modest while improving context modeling over pooled features.
|
|
127
|
-
|
|
128
|
-
.. rubric:: Additional Mechanisms
|
|
129
|
-
|
|
130
|
-
- **Parallel encoders over shifted windows.** Improves montage/phase robustness by
|
|
131
|
-
ensembling nearby contexts rather than committing to a single segmentation.
|
|
132
|
-
- **Max-norm classifier.** Enforces weight norm constraints at the readout, a common
|
|
133
|
-
stabilization trick in EEG decoding.
|
|
134
|
-
- **ViT vs. ATCNet (design choices).** Convolutional *nonlinear* projection rather than
|
|
135
|
-
linear patchification; attention followed by **TCN** (not MLP); *parallel* window
|
|
136
|
-
encoders rather than stacked encoders.
|
|
137
|
-
|
|
138
|
-
.. rubric:: Usage and Configuration
|
|
139
|
-
|
|
140
|
-
- ``conv_block_n_filters (F1)``, ``conv_block_depth_mult (D)`` → capacity of the stem
|
|
141
|
-
(with ``F2 = F1·D`` feeding attention/TCN), dimensions aligned to ``F2``, like `EEGNetv4`.
|
|
142
|
-
- Pool sizes ``P1,P2`` trade temporal resolution for stability/compute; they set
|
|
143
|
-
``T_c = T/(P1·P2)`` and thus window width ``T_w``.
|
|
144
|
-
- ``n_windows`` controls the ensemble over shifts (compute ∝ windows).
|
|
145
|
-
- ``att_num_heads``, ``att_head_dim`` set attention capacity; keep ``H·d_h ≈ F2``.
|
|
146
|
-
- ``tcn_depth``, ``tcn_kernel_size`` govern receptive field; larger values demand
|
|
147
|
-
longer inputs (see minimum length above). The implementation warns and *rescales*
|
|
148
|
-
kernels/pools/windows if inputs are too short.
|
|
149
|
-
- **Aggregation choice.** ``concat=False`` (default, average of per-window logits) matches
|
|
150
|
-
the official code; ``concat=True`` mirrors the paper’s concatenation variant.
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
Notes
|
|
154
|
-
-----
|
|
155
|
-
- Inputs substantially shorter than the implied minimum length trigger **automatic
|
|
156
|
-
downscaling** of kernels, pools, windows, and TCN kernel size to maintain validity.
|
|
157
|
-
- The attention–TCN sequence operates **per window**; the last causal step is used as the
|
|
158
|
-
window feature, aligning the temporal semantics across windows.
|
|
159
|
-
|
|
160
|
-
.. versionadded:: 1.1
|
|
161
|
-
|
|
162
|
-
- More detailed documentation of the model.
|
|
163
|
-
|
|
21
|
+
:align: center
|
|
22
|
+
:alt: ATCNet Architecture
|
|
164
23
|
|
|
165
24
|
Parameters
|
|
166
25
|
----------
|
|
@@ -226,13 +85,15 @@ class ATCNet(EEGModuleMixin, nn.Module):
|
|
|
226
85
|
Maximum L2-norm constraint imposed on weights of the last
|
|
227
86
|
fully-connected layer. Defaults to 0.25.
|
|
228
87
|
|
|
88
|
+
|
|
229
89
|
References
|
|
230
90
|
----------
|
|
231
|
-
.. [1] H. Altaheri, G. Muhammad
|
|
232
|
-
|
|
233
|
-
IEEE Transactions on Industrial Informatics
|
|
234
|
-
|
|
235
|
-
|
|
91
|
+
.. [1] H. Altaheri, G. Muhammad and M. Alsulaiman,
|
|
92
|
+
Physics-informed attention temporal convolutional network for EEG-based
|
|
93
|
+
motor imagery classification in IEEE Transactions on Industrial Informatics,
|
|
94
|
+
2022, doi: 10.1109/TII.2022.3197419.
|
|
95
|
+
.. [2] EEE-ATCNet implementation.
|
|
96
|
+
https://github.com/Altaheri/EEG-ATCNet/blob/main/models.py
|
|
236
97
|
"""
|
|
237
98
|
|
|
238
99
|
def __init__(
|
|
@@ -695,8 +556,7 @@ class _TCNResidualBlock(nn.Module):
|
|
|
695
556
|
# Reshape the input for the residual connection when necessary
|
|
696
557
|
if in_channels != n_filters:
|
|
697
558
|
self.reshaping_conv = nn.Conv1d(
|
|
698
|
-
|
|
699
|
-
out_channels=n_filters,
|
|
559
|
+
n_filters,
|
|
700
560
|
kernel_size=1,
|
|
701
561
|
padding="same",
|
|
702
562
|
)
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/eegconformer.py
RENAMED
|
@@ -12,126 +12,33 @@ from braindecode.modules import FeedForwardBlock, MultiHeadAttention
|
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
class EEGConformer(EEGModuleMixin, nn.Module):
|
|
15
|
-
"""EEG Conformer from Song et al. (2022) [song2022]_.
|
|
15
|
+
"""EEG Conformer from Song et al. (2022) from [song2022]_.
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
.. figure:: https://raw.githubusercontent.com/eeyhsong/EEG-Conformer/refs/heads/main/visualization/Fig1.png
|
|
17
|
+
.. figure:: https://raw.githubusercontent.com/eeyhsong/EEG-Conformer/refs/heads/main/visualization/Fig1.png
|
|
20
18
|
:align: center
|
|
21
19
|
:alt: EEGConformer Architecture
|
|
22
|
-
:width: 600px
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
.. rubric:: Architectural Overview
|
|
26
|
-
|
|
27
|
-
EEG-Conformer is a *convolution-first* model augmented with a *lightweight transformer
|
|
28
|
-
encoder*. The end-to-end flow is:
|
|
29
|
-
|
|
30
|
-
- (i) :class:`_PatchEmbedding` converts the continuous EEG into a compact sequence of tokens via a :class:`ShallowFBCSPNet` temporal–spatial conv stem and temporal pooling;
|
|
31
|
-
- (ii) :class:`_TransformerEncoder applies small multi-head self-attention to integrate longer-range temporal context across tokens;
|
|
32
|
-
- (iii) :class:`_ClassificationHead` aggregates the sequence and performs a linear readout.
|
|
33
|
-
This preserves the strong inductive biases of shallow CNN filter banks while adding
|
|
34
|
-
just enough attention to capture dependencies beyond the pooling horizon [song2022]_.
|
|
35
|
-
|
|
36
|
-
.. rubric:: Macro Components
|
|
37
|
-
|
|
38
|
-
- :class:`_PatchEmbedding` **(Shallow conv stem → tokens)**
|
|
39
|
-
|
|
40
|
-
- *Operations.*
|
|
41
|
-
- A temporal convolution (`:class:`torch.nn.Conv2d`) ``(1 x L_t)`` forms a data-driven "filter bank";
|
|
42
|
-
- A spatial convolution (`:class:`torch.nn.Conv2d`) (n_chans x 1)`` projects across electrodes, collapsing the channel axis into a virtual channel.
|
|
43
|
-
- **Normalization function** `:class:torch.nn.BatchNorm`
|
|
44
|
-
- **Activation function** `:class:torch.nn.ELU`
|
|
45
|
-
- **Average Pooling** `:class:torch.nn.AvgPool` along time (kernel ``(1, P)`` with stride ``(1, S)``)
|
|
46
|
-
- final ``1x1`` :class:`torch.nn.Linear` projection.
|
|
47
|
-
|
|
48
|
-
The result is rearranged to a token sequence ``(B, S_tokens, D)``, where ``D = n_filters_time``.
|
|
49
|
-
|
|
50
|
-
*Interpretability/robustness.* Temporal kernels can be inspected as FIR filters;
|
|
51
|
-
the spatial conv yields channel projections analogous to :class:`ShallowFBCSPNet`’s learned
|
|
52
|
-
spatial filters. Temporal pooling stabilizes statistics and reduces sequence length.
|
|
53
|
-
|
|
54
|
-
- :class:`_TransformerEncoder` **(context over temporal tokens)**
|
|
55
|
-
|
|
56
|
-
- *Operations.*
|
|
57
|
-
- A stack of ``att_depth`` encoder blocks. :class:`_TransformerEncoderBlock`
|
|
58
|
-
- Each block applies LayerNorm :class:`torch.nn.LayerNorm`
|
|
59
|
-
- Multi-Head Self-Attention (``att_heads``) with dropout + residual :class:`MultiHeadAttention` (:class:`torch.nn.Dropout`)
|
|
60
|
-
- LayerNorm :class:`torch.nn.LayerNorm`
|
|
61
|
-
- 2-layer feed-forward (≈4x expansion, :class:`torch.nn.GELU`) with dropout + residual.
|
|
62
|
-
|
|
63
|
-
Shapes remain ``(B, S_tokens, D)`` throughout.
|
|
64
20
|
|
|
65
|
-
|
|
66
|
-
extending effective receptive fields at modest cost.
|
|
21
|
+
Convolutional Transformer for EEG decoding.
|
|
67
22
|
|
|
68
|
-
|
|
23
|
+
The paper and original code with more details about the methodological
|
|
24
|
+
choices are available at the [song2022]_ and [ConformerCode]_.
|
|
69
25
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
- final Linear to classes.
|
|
26
|
+
This neural network architecture receives a traditional braindecode input.
|
|
27
|
+
The input shape should be three-dimensional matrix representing the EEG
|
|
28
|
+
signals.
|
|
74
29
|
|
|
75
|
-
|
|
76
|
-
linear probing or downstream tasks.
|
|
30
|
+
`(batch_size, n_channels, n_timesteps)`.
|
|
77
31
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
bands and transients. Subsequent **AvgPool** along time performs local integration,
|
|
83
|
-
converting activations into “patches” (tokens). Pool length/stride control the
|
|
84
|
-
token rate and set the lower bound on temporal context within each token.
|
|
85
|
-
|
|
86
|
-
- **Spatial (how electrodes are processed).**
|
|
87
|
-
A single conv with kernel ``(n_chans x 1)`` spans the full montage to learn spatial
|
|
88
|
-
projections for each temporal feature map, collapsing the channel axis into a
|
|
89
|
-
virtual channel before tokenization. This mirrors the shallow spatial step in
|
|
90
|
-
:class:`ShallowFBCSPNet` (temporal filters → spatial projection → temporal condensation).
|
|
91
|
-
|
|
92
|
-
- **Spectral (how frequency content is captured).**
|
|
93
|
-
No explicit Fourier/wavelet stage is used. Spectral selectivity emerges implicitly
|
|
94
|
-
from the learned temporal kernels; pooling further smooths high-frequency noise.
|
|
95
|
-
The effective spectral resolution is thus governed by ``L_t`` and the pooling
|
|
96
|
-
configuration.
|
|
97
|
-
|
|
98
|
-
.. rubric:: Attention / Sequential Modules
|
|
99
|
-
|
|
100
|
-
- **Type.** Standard multi-head self-attention (MHA) with ``att_heads`` heads over the token sequence.
|
|
101
|
-
- **Shapes.** Input/Output: ``(B, S_tokens, D)``; attention operates along the ``S_tokens`` axis.
|
|
102
|
-
- **Role.** Re-weights and integrates evidence across pooled windows, capturing dependencies
|
|
103
|
-
longer than any single token while leaving channel relationships to the convolutional stem.
|
|
104
|
-
The design is intentionally *small*—attention refines rather than replaces convolutional feature extraction.
|
|
105
|
-
|
|
106
|
-
.. rubric:: Additional Mechanisms
|
|
107
|
-
|
|
108
|
-
- **Parallel with ShallowFBCSPNet.** Both begin with a learned temporal filter bank,
|
|
109
|
-
spatial projection across electrodes, and early temporal condensation.
|
|
110
|
-
:class:`ShallowFBCSPNet` then computes band-power (via squaring/log-variance), whereas
|
|
111
|
-
EEG-Conformer applies BN/ELU and **continues with attention** over tokens to
|
|
112
|
-
refine temporal context before classification.
|
|
113
|
-
|
|
114
|
-
- **Tokenization knob.** ``pool_time_length`` and especially ``pool_time_stride`` set
|
|
115
|
-
the number of tokens ``S_tokens``. Smaller strides → more tokens and higher attention
|
|
116
|
-
capacity (but higher compute); larger strides → fewer tokens and stronger inductive bias.
|
|
117
|
-
|
|
118
|
-
- **Embedding dimension = filters.** ``n_filters_time`` serves double duty as both the
|
|
119
|
-
number of temporal filters in the stem and the transformer’s embedding size ``D``,
|
|
120
|
-
simplifying dimensional alignment.
|
|
121
|
-
|
|
122
|
-
.. rubric:: Usage and Configuration
|
|
123
|
-
|
|
124
|
-
- **Instantiation.** Choose ``n_filters_time`` (embedding size ``D``) and
|
|
125
|
-
``filter_time_length`` to match the rhythms of interest. Tune
|
|
126
|
-
``pool_time_length/stride`` to trade temporal resolution for sequence length.
|
|
127
|
-
Keep ``att_depth`` modest (e.g., 4–6) and set ``att_heads`` to divide ``D``.
|
|
128
|
-
``final_fc_length="auto"`` infers the flattened size from PatchEmbedding.
|
|
32
|
+
The EEG Conformer architecture is composed of three modules:
|
|
33
|
+
- PatchEmbedding
|
|
34
|
+
- TransformerEncoder
|
|
35
|
+
- ClassificationHead
|
|
129
36
|
|
|
130
37
|
Notes
|
|
131
38
|
-----
|
|
132
39
|
The authors recommend using data augmentation before using Conformer,
|
|
133
40
|
e.g. segmentation and recombination,
|
|
134
|
-
Please refer to the original paper and code for more details
|
|
41
|
+
Please refer to the original paper and code for more details.
|
|
135
42
|
|
|
136
43
|
The model was initially tuned on 4 seconds of 250 Hz data.
|
|
137
44
|
Please adjust the scale of the temporal convolutional layer,
|
|
@@ -140,10 +47,7 @@ class EEGConformer(EEGModuleMixin, nn.Module):
|
|
|
140
47
|
.. versionadded:: 0.8
|
|
141
48
|
|
|
142
49
|
We aggregate the parameters based on the parts of the models, or
|
|
143
|
-
when the parameters were used first, e.g.
|
|
144
|
-
|
|
145
|
-
.. versionadded:: 1.1
|
|
146
|
-
|
|
50
|
+
when the parameters were used first, e.g. n_filters_time.
|
|
147
51
|
|
|
148
52
|
Parameters
|
|
149
53
|
----------
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/eegnet.py
RENAMED
|
@@ -20,60 +20,13 @@ from braindecode.modules import (
|
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
class EEGNetv4(EEGModuleMixin, nn.Sequential):
|
|
23
|
-
"""EEGNet v4 model from Lawhern et al. (2018) [
|
|
24
|
-
|
|
25
|
-
:bdg-success:`Convolution` :bdg-secondary:`Depthwise–Separable`
|
|
23
|
+
"""EEGNet v4 model from Lawhern et al. (2018) [EEGNet4]_.
|
|
26
24
|
|
|
27
25
|
.. figure:: https://content.cld.iop.org/journals/1741-2552/15/5/056013/revision2/jneaace8cf01_hr.jpg
|
|
28
26
|
:align: center
|
|
29
|
-
:alt:
|
|
30
|
-
:width: 600px
|
|
31
|
-
|
|
32
|
-
.. rubric:: Architectural Overview
|
|
33
|
-
|
|
34
|
-
EEGNetv4 is a compact convolutional network designed for EEG decoding with a
|
|
35
|
-
pipeline that mirrors classical EEG processing:
|
|
36
|
-
- (i) learn temporal frequency-selective filters,
|
|
37
|
-
- (ii) learn spatial filters for those frequencies, and
|
|
38
|
-
- (iii) condense features with depthwise–separable convolutions before a lightweight classifier.
|
|
39
|
-
|
|
40
|
-
The architecture is deliberately small (temporal convolutional and spatial patterns) [Lawhern2018]_.
|
|
41
|
-
|
|
42
|
-
.. rubric:: Macro Components
|
|
43
|
-
|
|
44
|
-
- **Temporal convolution**
|
|
45
|
-
Temporal convolution applied per channel; learns ``F1`` kernels that act as data-driven band-pass filters.
|
|
46
|
-
- **Depthwise Spatial Filtering.**
|
|
47
|
-
Depthwise convolution spanning the channel dimension with ``groups = F1``,
|
|
48
|
-
yielding ``D`` spatial filters for each temporal filter (no cross-filter mixing).
|
|
49
|
-
- **Norm–Nonlinearity–Pooling (+ dropout).**
|
|
50
|
-
Batch normalization → ELU → temporal pooling, with dropout.
|
|
51
|
-
- **Depthwise–Separable Convolution Block.**
|
|
52
|
-
(a) depthwise temporal conv to refine temporal structure;
|
|
53
|
-
(b) pointwise 1x1 conv to mix feature maps into ``F2`` combinations.
|
|
54
|
-
- **Classifier Head.**
|
|
55
|
-
Lightweight 1x1 conv or dense layer (often with max-norm constraint).
|
|
27
|
+
:alt: EEGNet4 Architecture
|
|
56
28
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
**Temporal.** The initial temporal convs serve as a *learned filter bank*:
|
|
60
|
-
long 1-D kernels (implemented as 2-D with singleton spatial extent) emphasize oscillatory bands and transients.
|
|
61
|
-
Because this stage is linear prior to BN/ELU, kernels can be analyzed as FIR filters to reveal each feature’s spectrum [Lawhern2018]_.
|
|
62
|
-
|
|
63
|
-
**Spatial.** The depthwise spatial conv spans the full channel axis (kernel height = #electrodes; temporal size = 1).
|
|
64
|
-
With ``groups = F1``, each temporal filter learns its own set of ``D`` spatial projections—akin to CSP, learned end-to-end and
|
|
65
|
-
typically regularized with max-norm.
|
|
66
|
-
|
|
67
|
-
**Spectral.** No explicit Fourier/wavelet transform is used. Frequency structure
|
|
68
|
-
is captured implicitly by the temporal filter bank; later depthwise temporal kernels act as short-time integrators/refiners.
|
|
69
|
-
|
|
70
|
-
.. rubric:: Additional Comments
|
|
71
|
-
|
|
72
|
-
- **Filter-bank structure:** Parallel temporal kernels (``F1``) emulate classical filter banks; pairing them with frequency-specific spatial filters
|
|
73
|
-
yields features mappable to rhythms and topographies.
|
|
74
|
-
- **Depthwise & separable convs:** Parameter-efficient decomposition (depthwise + pointwise) retains power while limiting overfitting
|
|
75
|
-
[Chollet2017]_ and keeps temporal vs. mixing steps interpretable.
|
|
76
|
-
- **Regularization:** Batch norm, dropout, pooling, and optional max-norm on spatial kernels aid stability on small EEG datasets.
|
|
29
|
+
See details in [EEGNet4]_.
|
|
77
30
|
|
|
78
31
|
Parameters
|
|
79
32
|
----------
|
|
@@ -115,13 +68,10 @@ class EEGNetv4(EEGModuleMixin, nn.Sequential):
|
|
|
115
68
|
|
|
116
69
|
References
|
|
117
70
|
----------
|
|
118
|
-
.. [
|
|
71
|
+
.. [EEGNet4] Lawhern, V. J., Solon, A. J., Waytowich, N. R., Gordon, S. M.,
|
|
119
72
|
Hung, C. P., & Lance, B. J. (2018). EEGNet: a compact convolutional
|
|
120
73
|
neural network for EEG-based brain–computer interfaces. Journal of
|
|
121
74
|
neural engineering, 15(5), 056013.
|
|
122
|
-
.. [Chollet2017] Chollet, F., *Xception: Deep Learning with Depthwise Separable
|
|
123
|
-
Convolutions*, CVPR, 2017.
|
|
124
|
-
|
|
125
75
|
"""
|
|
126
76
|
|
|
127
77
|
def __init__(
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/modules/attention.py
RENAMED
|
@@ -157,8 +157,7 @@ class FCA(nn.Module):
|
|
|
157
157
|
):
|
|
158
158
|
super(FCA, self).__init__()
|
|
159
159
|
mapper_y = [freq_idx]
|
|
160
|
-
|
|
161
|
-
raise ValueError("in_channels must be divisible by number of DCT filters")
|
|
160
|
+
assert in_channels % len(mapper_y) == 0
|
|
162
161
|
|
|
163
162
|
self.weight = nn.Parameter(
|
|
164
163
|
self.get_dct_filter(seq_len, mapper_y, in_channels), requires_grad=False
|
|
@@ -296,8 +295,7 @@ class ECA(nn.Module):
|
|
|
296
295
|
def __init__(self, in_channels: int, kernel_size: int):
|
|
297
296
|
super(ECA, self).__init__()
|
|
298
297
|
self.gap = nn.AdaptiveAvgPool2d(1)
|
|
299
|
-
|
|
300
|
-
raise ValueError("kernel size must be odd for same padding")
|
|
298
|
+
assert kernel_size % 2 == 1, "kernel size must be odd for same padding"
|
|
301
299
|
self.conv = nn.Conv1d(
|
|
302
300
|
1, 1, kernel_size=kernel_size, padding=kernel_size // 2, bias=False
|
|
303
301
|
)
|
|
@@ -532,8 +530,7 @@ class CBAM(nn.Module):
|
|
|
532
530
|
nn.ReLU(),
|
|
533
531
|
nn.Conv2d(in_channels // reduction_rate, in_channels, 1, bias=False),
|
|
534
532
|
)
|
|
535
|
-
|
|
536
|
-
raise ValueError("kernel size must be odd for same padding")
|
|
533
|
+
assert kernel_size % 2 == 1, "kernel size must be odd for same padding"
|
|
537
534
|
self.conv = nn.Conv2d(2, 1, (1, kernel_size), padding=(0, kernel_size // 2))
|
|
538
535
|
|
|
539
536
|
def forward(self, x):
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/modules/convolution.py
RENAMED
|
@@ -136,8 +136,7 @@ class CombinedConv(nn.Module):
|
|
|
136
136
|
# Calculate bias terms
|
|
137
137
|
if self.bias_time:
|
|
138
138
|
time_bias = self.conv_time.bias
|
|
139
|
-
|
|
140
|
-
raise RuntimeError("conv_time.bias is None despite bias_time=True")
|
|
139
|
+
assert time_bias is not None
|
|
141
140
|
calculated_bias = (
|
|
142
141
|
self.conv_spat.weight.squeeze()
|
|
143
142
|
.sum(-1)
|
|
@@ -146,8 +145,7 @@ class CombinedConv(nn.Module):
|
|
|
146
145
|
)
|
|
147
146
|
if self.bias_spat:
|
|
148
147
|
spat_bias = self.conv_spat.bias
|
|
149
|
-
|
|
150
|
-
raise RuntimeError("conv_spat.bias is None despite bias_spat=True")
|
|
148
|
+
assert spat_bias is not None
|
|
151
149
|
if calculated_bias is None:
|
|
152
150
|
calculated_bias = spat_bias
|
|
153
151
|
else:
|
|
@@ -192,12 +190,11 @@ class CausalConv1d(nn.Conv1d):
|
|
|
192
190
|
dilation=1,
|
|
193
191
|
**kwargs,
|
|
194
192
|
):
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
)
|
|
193
|
+
assert "padding" not in kwargs, (
|
|
194
|
+
"The padding parameter is controlled internally by "
|
|
195
|
+
f"{type(self).__name__} class. You should not try to override this"
|
|
196
|
+
" parameter."
|
|
197
|
+
)
|
|
201
198
|
|
|
202
199
|
super().__init__(
|
|
203
200
|
in_channels=in_channels,
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/modules/filter.py
RENAMED
|
@@ -452,14 +452,12 @@ class GeneralizedGaussianFilter(nn.Module):
|
|
|
452
452
|
self.inverse_fourier = inverse_fourier
|
|
453
453
|
self.affine_group_delay = affine_group_delay
|
|
454
454
|
self.clamp_f_mean = clamp_f_mean
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
if len(shape) * in_channels != out_channels:
|
|
462
|
-
raise ValueError("len(shape) * in_channels must equal out_channels")
|
|
455
|
+
assert out_channels % in_channels == 0, (
|
|
456
|
+
"out_channels has to be multiple of in_channels"
|
|
457
|
+
)
|
|
458
|
+
assert len(f_mean) * in_channels == out_channels
|
|
459
|
+
assert len(bandwidth) * in_channels == out_channels
|
|
460
|
+
assert len(shape) * in_channels == out_channels
|
|
463
461
|
|
|
464
462
|
# Range from 0 to half sample rate, normalized
|
|
465
463
|
self.n_range = nn.Parameter(
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/training/scoring.py
RENAMED
|
@@ -11,6 +11,7 @@ from contextlib import contextmanager
|
|
|
11
11
|
|
|
12
12
|
import numpy as np
|
|
13
13
|
import torch
|
|
14
|
+
from mne.utils.check import check_version
|
|
14
15
|
from skorch.callbacks.scoring import EpochScoring
|
|
15
16
|
from skorch.dataset import unpack_data
|
|
16
17
|
from skorch.utils import to_numpy
|
|
@@ -369,8 +370,13 @@ class PostEpochTrainScoring(EpochScoring):
|
|
|
369
370
|
y_preds = []
|
|
370
371
|
y_test = []
|
|
371
372
|
for batch in iterator:
|
|
372
|
-
|
|
373
|
-
|
|
373
|
+
batch_X, batch_y = unpack_data(batch)
|
|
374
|
+
# TODO: remove after skorch 0.10 release
|
|
375
|
+
if not check_version("skorch", min_version="0.10.1"):
|
|
376
|
+
yp = net.evaluation_step(batch_X, training=False)
|
|
377
|
+
# X, y unpacking has been pushed downstream in skorch 0.10
|
|
378
|
+
else:
|
|
379
|
+
yp = net.evaluation_step(batch, training=False)
|
|
374
380
|
yp = yp.to(device="cpu")
|
|
375
381
|
y_test.append(self.target_extractor(batch_y))
|
|
376
382
|
y_preds.append(yp)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "1.2.0.dev169062562"
|
|
@@ -6,13 +6,8 @@ import numpy as np
|
|
|
6
6
|
import torch
|
|
7
7
|
from skorch.utils import to_numpy, to_tensor
|
|
8
8
|
|
|
9
|
-
from braindecode.util import set_random_seeds
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
def compute_amplitude_gradients(model, dataset, batch_size, seed=20240205):
|
|
13
|
-
"""Compute amplitude gradients after seeding for reproducibility."""
|
|
14
|
-
cuda = next(model.parameters()).is_cuda
|
|
15
|
-
set_random_seeds(seed=seed, cuda=cuda)
|
|
10
|
+
def compute_amplitude_gradients(model, dataset, batch_size):
|
|
16
11
|
loader = torch.utils.data.DataLoader(
|
|
17
12
|
dataset, batch_size=batch_size, drop_last=False, shuffle=False
|
|
18
13
|
)
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562/braindecode.egg-info}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: braindecode
|
|
3
|
-
Version: 1.2.0.
|
|
3
|
+
Version: 1.2.0.dev169062562
|
|
4
4
|
Summary: Deep learning software to decode EEG, ECG or MEG signals
|
|
5
5
|
Author-email: Robin Tibor Schirrmeister <robintibor@gmail.com>
|
|
6
6
|
Maintainer-email: Alexandre Gramfort <agramfort@meta.com>, Bruno Aristimunha Pinto <b.aristimunha@gmail.com>, Robin Tibor Schirrmeister <robintibor@gmail.com>
|
|
@@ -22,13 +22,6 @@ Current 1.2 (dev)
|
|
|
22
22
|
|
|
23
23
|
Enhancements
|
|
24
24
|
~~~~~~~~~~~~
|
|
25
|
-
- Improving the docstring for :class:`braindecode.models.EEGNetv4` (:gh:`768` by `Bruno Aristimunha`_)
|
|
26
|
-
- Improving the docstring for :class:`braindecode.models.EEGConformer` (:gh:`769` by `Bruno Aristimunha`_)
|
|
27
|
-
- Improving the docstring for :class:`braindecode.models.ATCNet` (:gh:`771` by `Bruno Aristimunha`_)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
API changes
|
|
31
|
-
~~~~~~~~~~~
|
|
32
25
|
|
|
33
26
|
Bugs
|
|
34
27
|
~~~~
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "1.2.0.dev168908090"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/augmentation/base.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/datasets/__init__.py
RENAMED
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/datasets/base.py
RENAMED
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/datasets/bbci.py
RENAMED
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/datasets/bcicomp.py
RENAMED
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/datasets/bids.py
RENAMED
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/datasets/mne.py
RENAMED
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/datasets/moabb.py
RENAMED
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/datasets/nmt.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/datasets/tuh.py
RENAMED
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/datasets/xy.py
RENAMED
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/datautil/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/datautil/util.py
RENAMED
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/eegneuralnet.py
RENAMED
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/functional/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/base.py
RENAMED
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/biot.py
RENAMED
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/contrawr.py
RENAMED
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/ctnet.py
RENAMED
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/deep4.py
RENAMED
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/deepsleepnet.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/eegitnet.py
RENAMED
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/eegminer.py
RENAMED
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/eegnex.py
RENAMED
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/eegresnet.py
RENAMED
|
File without changes
|
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/eegtcnet.py
RENAMED
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/fbcnet.py
RENAMED
|
File without changes
|
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/fbmsnet.py
RENAMED
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/hybrid.py
RENAMED
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/ifnet.py
RENAMED
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/labram.py
RENAMED
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/msvtnet.py
RENAMED
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/sccnet.py
RENAMED
|
File without changes
|
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/signal_jepa.py
RENAMED
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/sinc_shallow.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/sparcnet.py
RENAMED
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/summary.csv
RENAMED
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/syncnet.py
RENAMED
|
File without changes
|
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/tidnet.py
RENAMED
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/tsinception.py
RENAMED
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/usleep.py
RENAMED
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/models/util.py
RENAMED
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/modules/__init__.py
RENAMED
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/modules/activation.py
RENAMED
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/modules/blocks.py
RENAMED
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/modules/layers.py
RENAMED
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/modules/linear.py
RENAMED
|
File without changes
|
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/modules/stats.py
RENAMED
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/modules/util.py
RENAMED
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/modules/wrapper.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/samplers/__init__.py
RENAMED
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/samplers/base.py
RENAMED
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/samplers/ssl.py
RENAMED
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/training/__init__.py
RENAMED
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/training/callbacks.py
RENAMED
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode/training/losses.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode.egg-info/requires.txt
RENAMED
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/braindecode.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/docs/install/install_pip.rst
RENAMED
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/docs/install/install_source.rst
RENAMED
|
File without changes
|
|
File without changes
|
{braindecode-1.2.0.dev168908090 → braindecode-1.2.0.dev169062562}/docs/sg_execution_times.rst
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|