braindecode 1.3.0.dev175955015__py3-none-any.whl → 1.3.0.dev177509039__py3-none-any.whl
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.
Potentially problematic release.
This version of braindecode might be problematic. Click here for more details.
- braindecode/datasets/base.py +17 -16
- braindecode/datasets/bcicomp.py +1 -1
- braindecode/functional/functions.py +6 -2
- braindecode/functional/initialization.py +2 -3
- braindecode/models/__init__.py +2 -0
- braindecode/models/atcnet.py +25 -26
- braindecode/models/attentionbasenet.py +37 -32
- braindecode/models/base.py +2 -2
- braindecode/models/bendr.py +469 -0
- braindecode/models/biot.py +2 -0
- braindecode/models/ctnet.py +6 -3
- braindecode/models/deepsleepnet.py +27 -18
- braindecode/models/eegconformer.py +2 -2
- braindecode/models/eeginception_erp.py +31 -25
- braindecode/models/eegnet.py +1 -1
- braindecode/models/labram.py +28 -23
- braindecode/models/signal_jepa.py +6 -0
- braindecode/models/sinc_shallow.py +10 -9
- braindecode/models/sstdpn.py +11 -11
- braindecode/models/summary.csv +1 -0
- braindecode/models/usleep.py +26 -21
- braindecode/models/util.py +1 -0
- braindecode/modules/attention.py +10 -10
- braindecode/modules/blocks.py +3 -3
- braindecode/modules/filter.py +2 -3
- braindecode/modules/layers.py +18 -17
- braindecode/preprocessing/windowers.py +2 -2
- braindecode/samplers/base.py +8 -8
- braindecode/version.py +1 -1
- {braindecode-1.3.0.dev175955015.dist-info → braindecode-1.3.0.dev177509039.dist-info}/METADATA +1 -1
- {braindecode-1.3.0.dev175955015.dist-info → braindecode-1.3.0.dev177509039.dist-info}/RECORD +35 -34
- {braindecode-1.3.0.dev175955015.dist-info → braindecode-1.3.0.dev177509039.dist-info}/WHEEL +0 -0
- {braindecode-1.3.0.dev175955015.dist-info → braindecode-1.3.0.dev177509039.dist-info}/licenses/LICENSE.txt +0 -0
- {braindecode-1.3.0.dev175955015.dist-info → braindecode-1.3.0.dev177509039.dist-info}/licenses/NOTICE.txt +0 -0
- {braindecode-1.3.0.dev175955015.dist-info → braindecode-1.3.0.dev177509039.dist-info}/top_level.txt +0 -0
|
@@ -35,51 +35,57 @@ class EEGInceptionERP(EEGModuleMixin, nn.Sequential):
|
|
|
35
35
|
- :class:`_InceptionModule1` **(multi-scale temporal + spatial mixing)**
|
|
36
36
|
|
|
37
37
|
- *Operations.*
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
38
|
+
|
|
39
|
+
- `EEGInceptionERP.c1`: :class:`torch.nn.Conv2d` ``k=(64,1)``, stride ``(1,1)``, *same* pad on input reshaped to ``(B,1,128,8)`` → BN → activation → dropout.
|
|
40
|
+
- `EEGInceptionERP.d1`: :class:`torch.nn.Conv2d` (depthwise) ``k=(1,8)``, *valid* pad over channels → BN → activation → dropout.
|
|
41
|
+
- `EEGInceptionERP.c2`: :class:`torch.nn.Conv2d` ``k=(32,1)`` → BN → activation → dropout; then `EEGInceptionERP.d2` depthwise ``k=(1,8)`` → BN → activation → dropout.
|
|
42
|
+
- `EEGInceptionERP.c3`: :class:`torch.nn.Conv2d` ``k=(16,1)`` → BN → activation → dropout; then `EEGInceptionERP.d3` depthwise ``k=(1,8)`` → BN → activation → dropout.
|
|
43
|
+
- `EEGInceptionERP.n1`: :class:`torch.nn.Concat` over branch features.
|
|
44
|
+
- `EEGInceptionERP.a1`: :class:`torch.nn.AvgPool2d` ``pool=(4,1)``, stride ``(4,1)`` for temporal downsampling.
|
|
44
45
|
|
|
45
46
|
*Interpretability/robustness.* Depthwise `1 x n_chans` layers act as learnable montage-wide spatial filters per temporal scale; pooling stabilizes against jitter.
|
|
46
47
|
|
|
47
48
|
- :class:`_InceptionModule2` **(refinement at coarser timebase)**
|
|
48
49
|
|
|
49
50
|
- *Operations.*
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
51
|
+
|
|
52
|
+
- `EEGInceptionERP.c4`: :class:`torch.nn.Conv2d` ``k=(16,1)`` → BN → activation → dropout.
|
|
53
|
+
- `EEGInceptionERP.c5`: :class:`torch.nn.Conv2d` ``k=(8,1)`` → BN → activation → dropout.
|
|
54
|
+
- `EEGInceptionERP.c6`: :class:`torch.nn.Conv2d` ``k=(4,1)`` → BN → activation → dropout.
|
|
55
|
+
- `EEGInceptionERP.n2`: :class:`torch.nn.Concat` (merge C4-C6 outputs).
|
|
56
|
+
- `EEGInceptionERP.a2`: :class:`torch.nn.AvgPool2d` ``pool=(2,1)``, stride ``(2,1)``.
|
|
57
|
+
- `EEGInceptionERP.c7`: :class:`torch.nn.Conv2d` ``k=(8,1)`` → BN → activation → dropout; then `EEGInceptionERP.a3`: :class:`torch.nn.AvgPool2d` ``pool=(2,1)``.
|
|
58
|
+
- `EEGInceptionERP.c8`: :class:`torch.nn.Conv2d` ``k=(4,1)`` → BN → activation → dropout; then `EEGInceptionERP.a4`: :class:`torch.nn.AvgPool2d` ``pool=(2,1)``.
|
|
57
59
|
|
|
58
60
|
*Role.* Adds higher-level, shorter-window evidence while progressively compressing temporal dimension.
|
|
59
61
|
|
|
60
62
|
- :class:`_OutputModule` **(aggregation + readout)**
|
|
61
63
|
|
|
62
64
|
- *Operations.*
|
|
63
|
-
|
|
64
|
-
|
|
65
|
+
|
|
66
|
+
- :class:`torch.nn.Flatten`
|
|
67
|
+
- :class:`torch.nn.Linear` ``(features → 2)``
|
|
65
68
|
|
|
66
69
|
.. rubric:: Convolutional Details
|
|
67
70
|
|
|
68
71
|
- **Temporal (where time-domain patterns are learned).**
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
72
|
+
|
|
73
|
+
First module uses 1D temporal kernels along the 128-sample axis: ``64``, ``32``, ``16``
|
|
74
|
+
(≈500, 250, 125 ms at 128 Hz). After ``pool=(4,1)``, the second module applies ``16``,
|
|
75
|
+
``8``, ``4`` (≈125, 62.5, 31.25 ms at the pooled rate). All strides are ``1`` in convs;
|
|
76
|
+
temporal resolution changes only via average pooling.
|
|
73
77
|
|
|
74
78
|
- **Spatial (how electrodes are processed).**
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
79
|
+
|
|
80
|
+
Depthwise convs with ``k=(1,8)`` span all channels and are applied **per temporal branch**,
|
|
81
|
+
yielding scale-specific channel projections (no cross-branch mixing until concatenation).
|
|
82
|
+
There is no full 2D mixing kernel; spatial mixing is factorized and lightweight.
|
|
78
83
|
|
|
79
84
|
- **Spectral (how frequency information is captured).**
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
85
|
+
|
|
86
|
+
No explicit transform; multiple temporal kernels form a *learned filter bank* over
|
|
87
|
+
ERP-relevant bands. Successive pooling acts as low-pass integration to emphasize sustained
|
|
88
|
+
post-stimulus components.
|
|
83
89
|
|
|
84
90
|
.. rubric:: Additional Mechanisms
|
|
85
91
|
|
braindecode/models/eegnet.py
CHANGED
|
@@ -57,7 +57,7 @@ class EEGNet(EEGModuleMixin, nn.Sequential):
|
|
|
57
57
|
|
|
58
58
|
- **Temporal.** The initial temporal convs serve as a *learned filter bank*:
|
|
59
59
|
long 1-D kernels (implemented as 2-D with singleton spatial extent) emphasize oscillatory bands and transients.
|
|
60
|
-
Because this stage is linear prior to BN/ELU, kernels can be analyzed as FIR filters to reveal each feature
|
|
60
|
+
Because this stage is linear prior to BN/ELU, kernels can be analyzed as FIR filters to reveal each feature's spectrum [Lawhern2018]_.
|
|
61
61
|
|
|
62
62
|
- **Spatial.** The depthwise spatial conv spans the full channel axis (kernel height = #electrodes; temporal size = 1).
|
|
63
63
|
With ``groups = F1``, each temporal filter learns its own set of ``D`` spatial projections—akin to CSP, learned end-to-end and
|
braindecode/models/labram.py
CHANGED
|
@@ -22,6 +22,8 @@ from braindecode.modules import MLP, DropPath
|
|
|
22
22
|
class Labram(EEGModuleMixin, nn.Module):
|
|
23
23
|
"""Labram from Jiang, W B et al (2024) [Jiang2024]_.
|
|
24
24
|
|
|
25
|
+
:bdg-danger:`Large Brain Model`
|
|
26
|
+
|
|
25
27
|
.. figure:: https://arxiv.org/html/2405.18765v1/x1.png
|
|
26
28
|
:align: center
|
|
27
29
|
:alt: Labram Architecture.
|
|
@@ -43,33 +45,36 @@ class Labram(EEGModuleMixin, nn.Module):
|
|
|
43
45
|
equals True. The original implementation uses (batch, n_chans, n_patches,
|
|
44
46
|
patch_size) as input with static segmentation of the input data.
|
|
45
47
|
|
|
46
|
-
The models have the following sequence of steps
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
48
|
+
The models have the following sequence of steps::
|
|
49
|
+
|
|
50
|
+
if neural tokenizer:
|
|
51
|
+
- SegmentPatch: Segment the input data in patches;
|
|
52
|
+
- TemporalConv: Apply a temporal convolution to the segmented data;
|
|
53
|
+
- Residual adding cls, temporal and position embeddings (optional);
|
|
54
|
+
- WindowsAttentionBlock: Apply a windows attention block to the data;
|
|
55
|
+
- LayerNorm: Apply layer normalization to the data;
|
|
56
|
+
- Linear: An head linear layer to transformer the data into classes.
|
|
57
|
+
|
|
58
|
+
else:
|
|
59
|
+
- PatchEmbed: Apply a patch embedding to the input data;
|
|
60
|
+
- Residual adding cls, temporal and position embeddings (optional);
|
|
61
|
+
- WindowsAttentionBlock: Apply a windows attention block to the data;
|
|
62
|
+
- LayerNorm: Apply layer normalization to the data;
|
|
63
|
+
- Linear: An head linear layer to transformer the data into classes.
|
|
61
64
|
|
|
62
65
|
.. versionadded:: 0.9
|
|
63
66
|
|
|
64
67
|
|
|
65
|
-
Examples
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
68
|
+
Examples
|
|
69
|
+
--------
|
|
70
|
+
Load pre-trained weights::
|
|
71
|
+
|
|
72
|
+
>>> import torch
|
|
73
|
+
>>> from braindecode.models import Labram
|
|
74
|
+
>>> model = Labram(n_times=1600, n_chans=64, n_outputs=4)
|
|
75
|
+
>>> url = "https://huggingface.co/braindecode/Labram-Braindecode/blob/main/braindecode_labram_base.pt"
|
|
76
|
+
>>> state = torch.hub.load_state_dict_from_url(url, progress=True)
|
|
77
|
+
>>> model.load_state_dict(state)
|
|
73
78
|
|
|
74
79
|
|
|
75
80
|
Parameters
|
|
@@ -146,6 +146,8 @@ class _BaseSignalJEPA(EEGModuleMixin, nn.Module):
|
|
|
146
146
|
class SignalJEPA(_BaseSignalJEPA):
|
|
147
147
|
"""Architecture introduced in signal-JEPA for self-supervised pre-training, Guetschel, P et al (2024) [1]_
|
|
148
148
|
|
|
149
|
+
:bdg-danger:`Large Brain Model`
|
|
150
|
+
|
|
149
151
|
This model is not meant for classification but for SSL pre-training.
|
|
150
152
|
Its output shape depends on the input shape.
|
|
151
153
|
For classification purposes, three variants of this model are available:
|
|
@@ -232,6 +234,8 @@ class SignalJEPA(_BaseSignalJEPA):
|
|
|
232
234
|
class SignalJEPA_Contextual(_BaseSignalJEPA):
|
|
233
235
|
"""Contextual downstream architecture introduced in signal-JEPA Guetschel, P et al (2024) [1]_.
|
|
234
236
|
|
|
237
|
+
:bdg-danger:`Large Brain Model`
|
|
238
|
+
|
|
235
239
|
This architecture is one of the variants of :class:`SignalJEPA`
|
|
236
240
|
that can be used for classification purposes.
|
|
237
241
|
|
|
@@ -403,6 +407,8 @@ class SignalJEPA_Contextual(_BaseSignalJEPA):
|
|
|
403
407
|
class SignalJEPA_PostLocal(_BaseSignalJEPA):
|
|
404
408
|
"""Post-local downstream architecture introduced in signal-JEPA Guetschel, P et al (2024) [1]_.
|
|
405
409
|
|
|
410
|
+
:bdg-danger:`Large Brain Model`
|
|
411
|
+
|
|
406
412
|
This architecture is one of the variants of :class:`SignalJEPA`
|
|
407
413
|
that can be used for classification purposes.
|
|
408
414
|
|
|
@@ -19,23 +19,24 @@ class SincShallowNet(EEGModuleMixin, nn.Module):
|
|
|
19
19
|
The Sinc-ShallowNet architecture has these fundamental blocks:
|
|
20
20
|
|
|
21
21
|
1. **Block 1: Spectral and Spatial Feature Extraction**
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
- *Batch Normalization*
|
|
22
|
+
|
|
23
|
+
- *Temporal Sinc-Convolutional Layer*: Uses parametrized sinc functions to learn band-pass filters,
|
|
24
|
+
significantly reducing the number of trainable parameters by only
|
|
25
|
+
learning the lower and upper cutoff frequencies for each filter.
|
|
26
|
+
- *Spatial Depthwise Convolutional Layer*: Applies depthwise convolutions to learn spatial filters for
|
|
27
|
+
each temporal feature map independently, further reducing
|
|
28
|
+
parameters and enhancing interpretability.
|
|
29
|
+
- *Batch Normalization*
|
|
31
30
|
|
|
32
31
|
2. **Block 2: Temporal Aggregation**
|
|
32
|
+
|
|
33
33
|
- *Activation Function*: ELU
|
|
34
34
|
- *Average Pooling Layer*: Aggregation by averaging spatial dim
|
|
35
35
|
- *Dropout Layer*
|
|
36
36
|
- *Flatten Layer*
|
|
37
37
|
|
|
38
38
|
3. **Block 3: Classification**
|
|
39
|
+
|
|
39
40
|
- *Fully Connected Layer*: Maps the feature vector to n_outputs.
|
|
40
41
|
|
|
41
42
|
**Implementation Notes:**
|
braindecode/models/sstdpn.py
CHANGED
|
@@ -24,7 +24,7 @@ class SSTDPN(EEGModuleMixin, nn.Module):
|
|
|
24
24
|
:alt: SSTDPN Architecture
|
|
25
25
|
:width: 1000px
|
|
26
26
|
|
|
27
|
-
The **Spatial
|
|
27
|
+
The **Spatial-Spectral** and **Temporal - Dual Prototype Network** (SST-DPN)
|
|
28
28
|
is an end-to-end 1D convolutional architecture designed for motor imagery (MI) EEG decoding,
|
|
29
29
|
aiming to address challenges related to discriminative feature extraction and
|
|
30
30
|
small-sample sizes [Han2025]_.
|
|
@@ -37,9 +37,9 @@ class SSTDPN(EEGModuleMixin, nn.Module):
|
|
|
37
37
|
SST-DPN consists of a feature extractor (_SSTEncoder, comprising Adaptive Spatial-Spectral
|
|
38
38
|
Fusion and Multi-scale Variance Pooling) followed by Dual Prototype Learning classification [Han2025]_.
|
|
39
39
|
|
|
40
|
-
1. **Adaptive Spatial
|
|
41
|
-
multi-channel spatial
|
|
42
|
-
(Spatial-Spectral Attention) to model relationships and highlight key spatial
|
|
40
|
+
1. **Adaptive Spatial-Spectral Fusion (ASSF)**: Uses :class:`_DepthwiseTemporalConv1d` to generate a
|
|
41
|
+
multi-channel spatial-spectral representation, followed by :class:`_SpatSpectralAttn`
|
|
42
|
+
(Spatial-Spectral Attention) to model relationships and highlight key spatial-spectral
|
|
43
43
|
channels [Han2025]_.
|
|
44
44
|
|
|
45
45
|
2. **Multi-scale Variance Pooling (MVP)**: Applies :class:`_MultiScaleVarPooler` with variance pooling
|
|
@@ -57,7 +57,7 @@ class SSTDPN(EEGModuleMixin, nn.Module):
|
|
|
57
57
|
|
|
58
58
|
- `SSTDPN.encoder` **(Feature Extractor)**
|
|
59
59
|
|
|
60
|
-
- *Operations.* Combines Adaptive Spatial
|
|
60
|
+
- *Operations.* Combines Adaptive Spatial-Spectral Fusion and Multi-scale Variance Pooling
|
|
61
61
|
via an internal :class:`_SSTEncoder`.
|
|
62
62
|
- *Role.* Maps the raw MI-EEG trial :math:`X_i \in \mathbb{R}^{C \times T}` to the
|
|
63
63
|
feature space :math:`z_i \in \mathbb{R}^d`.
|
|
@@ -69,11 +69,11 @@ class SSTDPN(EEGModuleMixin, nn.Module):
|
|
|
69
69
|
depth multiplier `n_spectral_filters_temporal` (equivalent to :math:`F_1` in the paper).
|
|
70
70
|
- *Role.* Extracts multiple distinct spectral bands from each EEG channel independently.
|
|
71
71
|
|
|
72
|
-
- `_SSTEncoder.spt_attn` **(Spatial
|
|
72
|
+
- `_SSTEncoder.spt_attn` **(Spatial-Spectral Attention for Channel Gating)**
|
|
73
73
|
|
|
74
74
|
- *Operations.* Internal :class:`_SpatSpectralAttn` module using Global Context Embedding
|
|
75
75
|
via variance-based pooling, followed by adaptive channel normalization and gating.
|
|
76
|
-
- *Role.* Reweights channels in the spatial
|
|
76
|
+
- *Role.* Reweights channels in the spatial-spectral dimension to extract efficient and
|
|
77
77
|
discriminative features by emphasizing task-relevant regions and frequency bands.
|
|
78
78
|
|
|
79
79
|
- `_SSTEncoder.chan_conv` **(Pointwise Fusion across Channels)**
|
|
@@ -81,7 +81,7 @@ class SSTDPN(EEGModuleMixin, nn.Module):
|
|
|
81
81
|
- *Operations.* A 1D pointwise convolution with `n_fused_filters` output channels
|
|
82
82
|
(equivalent to :math:`F_2` in the paper), followed by BatchNorm and the specified
|
|
83
83
|
`activation` function (default: ELU).
|
|
84
|
-
- *Role.* Fuses the weighted spatial
|
|
84
|
+
- *Role.* Fuses the weighted spatial-spectral features across all electrodes to produce
|
|
85
85
|
a fused representation :math:`X_{fused} \in \mathbb{R}^{F_2 \times T}`.
|
|
86
86
|
|
|
87
87
|
- `_SSTEncoder.mvp` **(Multi-scale Variance Pooling for Temporal Extraction)**
|
|
@@ -109,11 +109,11 @@ class SSTDPN(EEGModuleMixin, nn.Module):
|
|
|
109
109
|
* **Spatial.**
|
|
110
110
|
The initial convolution at the classes :class:`_DepthwiseTemporalConv1d` groups parameter :math:`h=1`,
|
|
111
111
|
meaning :math:`F_1` temporal filters are shared across channels. The Spatial-Spectral Attention
|
|
112
|
-
mechanism explicitly models the relationships among these channels in the spatial
|
|
112
|
+
mechanism explicitly models the relationships among these channels in the spatial-spectral
|
|
113
113
|
dimension, allowing for finer-grained spatial feature modeling compared to conventional
|
|
114
114
|
GCNs according to the authors [Han2025]_.
|
|
115
115
|
In other words, all electrode channels share :math:`F_1` temporal filters
|
|
116
|
-
independently to produce the spatial
|
|
116
|
+
independently to produce the spatial-spectral representation.
|
|
117
117
|
|
|
118
118
|
* **Spectral.**
|
|
119
119
|
Spectral information is implicitly extracted via the :math:`F_1` filters in :class:`_DepthwiseTemporalConv1d`.
|
|
@@ -123,7 +123,7 @@ class SSTDPN(EEGModuleMixin, nn.Module):
|
|
|
123
123
|
|
|
124
124
|
.. rubric:: Additional Mechanisms
|
|
125
125
|
|
|
126
|
-
- **Attention.** A lightweight Spatial-Spectral Attention mechanism models spatial
|
|
126
|
+
- **Attention.** A lightweight Spatial-Spectral Attention mechanism models spatial-spectral relationships
|
|
127
127
|
at the channel level, distinct from applying attention to deep feature dimensions,
|
|
128
128
|
which is common in comparison methods like :class:`ATCNet`.
|
|
129
129
|
- **Regularization.** Dual Prototype Learning acts as a regularization technique
|
braindecode/models/summary.csv
CHANGED
|
@@ -39,3 +39,4 @@ FBLightConvNet,Motor Imagery,Classification,250,"n_chans, n_outputs, n_times, sf
|
|
|
39
39
|
IFNet,Motor Imagery,Classification,250,"n_chans, n_outputs, n_times, sfreq",9860,"IFNet(n_chans=22, n_outputs=4, n_times=1000, sfreq=250)","Convolution,FilterBank"
|
|
40
40
|
PBT,General,Classification,250,"n_chans, n_outputs, n_times",818948,"PBT(n_chans=22, n_outputs=4, n_times=1000, sfreq=250)","Large Brain Model"
|
|
41
41
|
SSTDPN,Motor Imagery,Classification,250,"n_chans, n_outputs, n_times",19502,"SSTDPN(n_chans=22, n_outputs=4, n_times=1000)","Convolution,Small Attention"
|
|
42
|
+
BENDR,General,"Classification,Embedding",250,"n_chans, n_times, n_outputs",157141049,"BENDR(n_chans=22, n_outputs=4, n_times=1000)","Large Brain Model,Convolution"
|
braindecode/models/usleep.py
CHANGED
|
@@ -62,43 +62,48 @@ class USleep(EEGModuleMixin, nn.Module):
|
|
|
62
62
|
- Decoder :class:`_DecoderBlock` **(progressive upsampling + skip fusion to high-frequency map, 12 blocks; upsampling x2 per block)**
|
|
63
63
|
|
|
64
64
|
- *Operations.*
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
65
|
+
|
|
66
|
+
- **Nearest-neighbor upsample**, :class:`nn.Upsample` (x2)
|
|
67
|
+
- **Convolution2d** (k=2), :class:`torch.nn.Conv2d`
|
|
68
|
+
- ELU, :class:`torch.nn.ELU`
|
|
69
|
+
- Batch Norm, :class:`torch.nn.BatchNorm2d`
|
|
70
|
+
- **Concatenate** with the encoder skip at the same temporal scale, ``torch.cat``
|
|
71
|
+
- **Convolution**, :class:`torch.nn.Conv2d`
|
|
72
|
+
- ELU, :class:`torch.nn.ELU`
|
|
73
|
+
- Batch Norm, :class:`torch.nn.BatchNorm2d`.
|
|
73
74
|
|
|
74
75
|
**Output**: A multi-class, **high-frequency** per-sample representation aligned to the input rate (128 Hz).
|
|
75
76
|
|
|
76
77
|
- **Segment Classifier incorporate into :class:`braindecode.models.USleep` (aggregation to fixed epochs)**
|
|
77
78
|
|
|
78
79
|
- *Operations.*
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
|
|
81
|
+
- **Mean-pool**, :class:`torch.nn.AvgPool2d` per class with kernel = epoch length *i* and stride *i*
|
|
82
|
+
- **1x1 conv**, :class:`torch.nn.Conv2d`
|
|
83
|
+
- ELU, :class:`torch.nn.ELU`
|
|
84
|
+
- **1x1 conv**, :class:`torch.nn.Conv2d` with ``(T, K)`` (epochs x stages).
|
|
83
85
|
|
|
84
86
|
**Role**: Learns a **non-linear** weighted combination over each 30-s window (unlike U-Time's linear combiner).
|
|
85
87
|
|
|
86
88
|
.. rubric:: Convolutional Details
|
|
87
89
|
|
|
88
90
|
- **Temporal (where time-domain patterns are learned).**
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
91
|
+
|
|
92
|
+
All convolutions are **1-D along time**; depth (12 levels) plus pooling yields an extensive receptive field
|
|
93
|
+
(reported sensitivity to ±6.75 min around each epoch; theoretical field ≈ 9.6 min at the deepest layer).
|
|
94
|
+
The decoder restores sample-level resolution before epoch aggregation.
|
|
92
95
|
|
|
93
96
|
- **Spatial (how channels are processed).**
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
+
|
|
98
|
+
Convolutions mix across the *channel* dimension jointly with time (no separate spatial operator). The system
|
|
99
|
+
is **montage-agnostic** (any reasonable EEG/EOG pair) and was trained across diverse cohorts/protocols,
|
|
100
|
+
supporting robustness to channel placement and hardware differences.
|
|
97
101
|
|
|
98
102
|
- **Spectral (how frequency content is captured).**
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
103
|
+
|
|
104
|
+
No explicit Fourier/wavelet transform is used; the **stack of temporal convolutions** acts as a learned
|
|
105
|
+
filter bank whose effective bandwidth grows with depth. The high-frequency decoder output (128 Hz)
|
|
106
|
+
retains fine temporal detail for the segment classifier.
|
|
102
107
|
|
|
103
108
|
|
|
104
109
|
.. rubric:: Attention / Sequential Modules
|
braindecode/models/util.py
CHANGED
|
@@ -97,6 +97,7 @@ models_mandatory_parameters = [
|
|
|
97
97
|
("IFNet", ["n_chans", "n_outputs", "n_times", "sfreq"], dict(sfreq=200.0)),
|
|
98
98
|
("PBT", ["n_chans", "n_outputs", "n_times"], None),
|
|
99
99
|
("SSTDPN", ["n_chans", "n_outputs", "n_times", "sfreq"], None),
|
|
100
|
+
("BENDR", ["n_chans", "n_outputs", "n_times"], None),
|
|
100
101
|
]
|
|
101
102
|
|
|
102
103
|
################################################################
|
braindecode/modules/attention.py
CHANGED
|
@@ -38,7 +38,7 @@ class SqueezeAndExcitation(nn.Module):
|
|
|
38
38
|
References
|
|
39
39
|
----------
|
|
40
40
|
.. [Hu2018] Hu, J., Albanie, S., Sun, G., Wu, E., 2018.
|
|
41
|
-
|
|
41
|
+
Squeeze-and-Excitation Networks. CVPR 2018.
|
|
42
42
|
"""
|
|
43
43
|
|
|
44
44
|
def __init__(self, in_channels: int, reduction_rate: int, bias: bool = False):
|
|
@@ -93,7 +93,7 @@ class GSoP(nn.Module):
|
|
|
93
93
|
References
|
|
94
94
|
----------
|
|
95
95
|
.. [Gao2018] Gao, Z., Jiangtao, X., Wang, Q., Li, P., 2018.
|
|
96
|
-
|
|
96
|
+
Global Second-order Pooling Convolutional Networks. CVPR 2018.
|
|
97
97
|
"""
|
|
98
98
|
|
|
99
99
|
def __init__(self, in_channels: int, reduction_rate: int, bias: bool = True):
|
|
@@ -149,7 +149,7 @@ class FCA(nn.Module):
|
|
|
149
149
|
References
|
|
150
150
|
----------
|
|
151
151
|
.. [Qin2021] Qin, Z., Zhang, P., Wu, F., Li, X., 2021.
|
|
152
|
-
|
|
152
|
+
FcaNet: Frequency Channel Attention Networks. ICCV 2021.
|
|
153
153
|
"""
|
|
154
154
|
|
|
155
155
|
def __init__(
|
|
@@ -233,7 +233,7 @@ class EncNet(nn.Module):
|
|
|
233
233
|
References
|
|
234
234
|
----------
|
|
235
235
|
.. [Zhang2018] Zhang, H. et al. 2018.
|
|
236
|
-
|
|
236
|
+
Context Encoding for Semantic Segmentation. CVPR 2018.
|
|
237
237
|
"""
|
|
238
238
|
|
|
239
239
|
def __init__(self, in_channels: int, n_codewords: int):
|
|
@@ -290,7 +290,7 @@ class ECA(nn.Module):
|
|
|
290
290
|
References
|
|
291
291
|
----------
|
|
292
292
|
.. [Wang2021] Wang, Q. et al., 2021. ECA-Net: Efficient Channel Attention
|
|
293
|
-
|
|
293
|
+
for Deep Convolutional Neural Networks. CVPR 2021.
|
|
294
294
|
"""
|
|
295
295
|
|
|
296
296
|
def __init__(self, in_channels: int, kernel_size: int):
|
|
@@ -341,8 +341,8 @@ class GatherExcite(nn.Module):
|
|
|
341
341
|
References
|
|
342
342
|
----------
|
|
343
343
|
.. [Hu2018b] Hu, J., Albanie, S., Sun, G., Vedaldi, A., 2018.
|
|
344
|
-
|
|
345
|
-
|
|
344
|
+
Gather-Excite: Exploiting Feature Context in Convolutional Neural Networks.
|
|
345
|
+
NeurIPS 2018.
|
|
346
346
|
"""
|
|
347
347
|
|
|
348
348
|
def __init__(
|
|
@@ -410,7 +410,7 @@ class GCT(nn.Module):
|
|
|
410
410
|
References
|
|
411
411
|
----------
|
|
412
412
|
.. [Yang2020] Yang, Z. Linchao, Z., Wu, Y., Yang, Y., 2020.
|
|
413
|
-
|
|
413
|
+
Gated Channel Transformation for Visual Recognition. CVPR 2020.
|
|
414
414
|
"""
|
|
415
415
|
|
|
416
416
|
def __init__(self, in_channels: int):
|
|
@@ -455,7 +455,7 @@ class SRM(nn.Module):
|
|
|
455
455
|
References
|
|
456
456
|
----------
|
|
457
457
|
.. [Lee2019] Lee, H., Kim, H., Nam, H., 2019. SRM: A Style-based
|
|
458
|
-
|
|
458
|
+
Recalibration Module for Convolutional Neural Networks. ICCV 2019.
|
|
459
459
|
"""
|
|
460
460
|
|
|
461
461
|
def __init__(
|
|
@@ -520,7 +520,7 @@ class CBAM(nn.Module):
|
|
|
520
520
|
References
|
|
521
521
|
----------
|
|
522
522
|
.. [Woo2018] Woo, S., Park, J., Lee, J., Kweon, I., 2018.
|
|
523
|
-
|
|
523
|
+
CBAM: Convolutional Block Attention Module. ECCV 2018.
|
|
524
524
|
"""
|
|
525
525
|
|
|
526
526
|
def __init__(self, in_channels: int, reduction_rate: int, kernel_size: int):
|
braindecode/modules/blocks.py
CHANGED
|
@@ -37,8 +37,8 @@ class MLP(nn.Sequential):
|
|
|
37
37
|
:math:`a_i` are called activation functions. The trainable parameters of an
|
|
38
38
|
MLP are its weights and biases :math:`\\phi = \{W_i, b_i | i = 1, \dots, L\}`.
|
|
39
39
|
|
|
40
|
-
Parameters
|
|
41
|
-
|
|
40
|
+
Parameters
|
|
41
|
+
----------
|
|
42
42
|
in_features: int
|
|
43
43
|
Number of input features.
|
|
44
44
|
hidden_features: Sequential[int] (default=None)
|
|
@@ -49,7 +49,7 @@ class MLP(nn.Sequential):
|
|
|
49
49
|
out_features: int (default=None)
|
|
50
50
|
Number of output features, if None, set to in_features.
|
|
51
51
|
act_layer: nn.GELU (default)
|
|
52
|
-
The activation function constructor. If
|
|
52
|
+
The activation function constructor. If ``None``, use
|
|
53
53
|
:class:`torch.nn.GELU` instead.
|
|
54
54
|
drop: float (default=0.0)
|
|
55
55
|
Dropout rate.
|
braindecode/modules/filter.py
CHANGED
|
@@ -17,9 +17,8 @@ class FilterBankLayer(nn.Module):
|
|
|
17
17
|
It uses MNE's `create_filter` function to create the band-specific filters and
|
|
18
18
|
applies them to multi-channel time-series data. Each filter in the bank corresponds to a
|
|
19
19
|
specific frequency band and is applied to all channels of the input data. The filtering is
|
|
20
|
-
performed using FFT-based convolution via the
|
|
21
|
-
|
|
22
|
-
:func:`torchaudio.functional if the method is IIR.
|
|
20
|
+
performed using FFT-based convolution via the ``torchaudio.functional`` if the method is FIR,
|
|
21
|
+
and ``torchaudio.functional`` if the method is IIR.
|
|
23
22
|
|
|
24
23
|
The default configuration creates 9 non-overlapping frequency bands with a 4 Hz bandwidth,
|
|
25
24
|
spanning from 4 Hz to 40 Hz (i.e., 4-8 Hz, 8-12 Hz, ..., 36-40 Hz). This setup is based on the
|
braindecode/modules/layers.py
CHANGED
|
@@ -70,26 +70,27 @@ class TimeDistributed(nn.Module):
|
|
|
70
70
|
class DropPath(nn.Module):
|
|
71
71
|
"""Drop paths, also known as Stochastic Depth, per sample.
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
When applied in main path of residual blocks.
|
|
74
74
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
75
|
+
Parameters
|
|
76
|
+
----------
|
|
77
|
+
drop_prob: float (default=None)
|
|
78
|
+
Drop path probability (should be in range 0-1).
|
|
79
79
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
Notes
|
|
81
|
+
-----
|
|
82
|
+
Code copied and modified from VISSL facebookresearch:
|
|
83
83
|
https://github.com/facebookresearch/vissl/blob/0b5d6a94437bc00baed112ca90c9d78c6ccfbafb/vissl/models/model_helpers.py#L676
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
84
|
+
|
|
85
|
+
All rights reserved.
|
|
86
|
+
|
|
87
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
88
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
89
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
90
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
91
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
92
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
93
|
+
SOFTWARE.
|
|
93
94
|
"""
|
|
94
95
|
|
|
95
96
|
def __init__(self, drop_prob=None):
|
|
@@ -268,7 +268,7 @@ def create_windows_from_events(
|
|
|
268
268
|
rejection based on flatness is done. See mne.Epochs.
|
|
269
269
|
on_missing: str
|
|
270
270
|
What to do if one or several event ids are not found in the recording.
|
|
271
|
-
Valid keys are ‘error
|
|
271
|
+
Valid keys are ‘error' | ‘warning' | ‘ignore'. See mne.Epochs.
|
|
272
272
|
accepted_bads_ratio: float, optional
|
|
273
273
|
Acceptable proportion of trials with inconsistent length in a raw. If
|
|
274
274
|
the number of trials whose length is exceeded by the window size is
|
|
@@ -398,7 +398,7 @@ def create_fixed_length_windows(
|
|
|
398
398
|
by using the _LazyDataFrame (experimental).
|
|
399
399
|
on_missing: str
|
|
400
400
|
What to do if one or several event ids are not found in the recording.
|
|
401
|
-
Valid keys are ‘error
|
|
401
|
+
Valid keys are ‘error' | ‘warning' | ‘ignore'. See mne.Epochs.
|
|
402
402
|
n_jobs: int
|
|
403
403
|
Number of jobs to use to parallelize the windowing.
|
|
404
404
|
verbose: bool | str | int | None
|
braindecode/samplers/base.py
CHANGED
|
@@ -122,14 +122,14 @@ class DistributedRecordingSampler(DistributedSampler):
|
|
|
122
122
|
DataFrame with at least one of {subject, session, run} columns for each
|
|
123
123
|
window in the BaseConcatDataset to sample examples from. Normally
|
|
124
124
|
obtained with `BaseConcatDataset.get_metadata()`. For instance,
|
|
125
|
-
`metadata.head()` might look like this
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
125
|
+
`metadata.head()` might look like this::
|
|
126
|
+
|
|
127
|
+
i_window_in_trial i_start_in_trial i_stop_in_trial target subject session run
|
|
128
|
+
0 0 0 500 -1 4 session_T run_0
|
|
129
|
+
1 1 500 1000 -1 4 session_T run_0
|
|
130
|
+
2 2 1000 1500 -1 4 session_T run_0
|
|
131
|
+
3 3 1500 2000 -1 4 session_T run_0
|
|
132
|
+
4 4 2000 2500 -1 4 session_T run_0
|
|
133
133
|
|
|
134
134
|
random_state : np.RandomState | int | None
|
|
135
135
|
Random state.
|
braindecode/version.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "1.3.0.
|
|
1
|
+
__version__ = "1.3.0.dev177509039"
|
{braindecode-1.3.0.dev175955015.dist-info → braindecode-1.3.0.dev177509039.dist-info}/METADATA
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: braindecode
|
|
3
|
-
Version: 1.3.0.
|
|
3
|
+
Version: 1.3.0.dev177509039
|
|
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>
|