braindecode 1.2.0.dev168908090__py3-none-any.whl → 1.2.0.dev175337561__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/models/attentionbasenet.py +140 -18
- braindecode/version.py +1 -1
- {braindecode-1.2.0.dev168908090.dist-info → braindecode-1.2.0.dev175337561.dist-info}/METADATA +1 -1
- {braindecode-1.2.0.dev168908090.dist-info → braindecode-1.2.0.dev175337561.dist-info}/RECORD +8 -8
- {braindecode-1.2.0.dev168908090.dist-info → braindecode-1.2.0.dev175337561.dist-info}/WHEEL +0 -0
- {braindecode-1.2.0.dev168908090.dist-info → braindecode-1.2.0.dev175337561.dist-info}/licenses/LICENSE.txt +0 -0
- {braindecode-1.2.0.dev168908090.dist-info → braindecode-1.2.0.dev175337561.dist-info}/licenses/NOTICE.txt +0 -0
- {braindecode-1.2.0.dev168908090.dist-info → braindecode-1.2.0.dev175337561.dist-info}/top_level.txt +0 -0
|
@@ -24,26 +24,148 @@ from braindecode.modules.attention import (
|
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
class AttentionBaseNet(EEGModuleMixin, nn.Module):
|
|
27
|
-
"""
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
:bdg-success:`Convolution` :bdg-info:`Small Attention`
|
|
28
30
|
|
|
29
31
|
.. figure:: https://content.cld.iop.org/journals/1741-2552/21/3/036020/revision2/jnead48b9f2_hr.jpg
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
convolution
|
|
43
|
-
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
32
|
+
:align: center
|
|
33
|
+
:alt: AttentionBaseNet Architecture
|
|
34
|
+
:width: 640px
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
.. rubric:: Architectural Overview
|
|
38
|
+
|
|
39
|
+
AttentionBaseNet is a *convolution-first* network with a *channel-attention* stage.
|
|
40
|
+
The end-to-end flow is:
|
|
41
|
+
|
|
42
|
+
- (i) :class:`_FeatureExtractor` learns a temporal filter bank and per-filter spatial
|
|
43
|
+
projections (depthwise across electrodes), then condenses time by pooling;
|
|
44
|
+
- (ii) **Channel Expansion** uses a ``1x1`` convolution to set the feature width;
|
|
45
|
+
- (iii) :class:`_ChannelAttentionBlock` refines features via depthwise–pointwise temporal
|
|
46
|
+
convs and an optional channel-attention module (SE/CBAM/ECA/…);
|
|
47
|
+
- (iv) **Classifier** flattens the sequence and applies a linear readout.
|
|
48
|
+
|
|
49
|
+
This design mirrors shallow CNN pipelines (EEGNet-style stem) but inserts a pluggable
|
|
50
|
+
attention unit that *re-weights channels* (and optionally temporal positions) before
|
|
51
|
+
classification.
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
.. rubric:: Macro Components
|
|
55
|
+
|
|
56
|
+
- :class:`_FeatureExtractor` **(Shallow conv stem → condensed feature map)**
|
|
57
|
+
|
|
58
|
+
- *Operations.*
|
|
59
|
+
- **Temporal conv** (:class:`torch.nn.Conv2d`) with kernel ``(1, L_t)`` creates a learned
|
|
60
|
+
FIR-like filter bank with ``n_temporal_filters`` maps.
|
|
61
|
+
- **Depthwise spatial conv** (:class:`torch.nn.Conv2d`, ``groups=n_temporal_filters``)
|
|
62
|
+
with kernel ``(n_chans, 1)`` learns per-filter spatial projections over the full montage.
|
|
63
|
+
- **BatchNorm → ELU → AvgPool → Dropout** stabilize and downsample time.
|
|
64
|
+
- Output shape: ``(B, F2, 1, T₁)`` with ``F2 = n_temporal_filters x spatial_expansion``.
|
|
65
|
+
|
|
66
|
+
*Interpretability/robustness.* Temporal kernels behave as analyzable FIR filters; the
|
|
67
|
+
depthwise spatial step yields rhythm-specific topographies. Pooling acts as a local
|
|
68
|
+
integrator that reduces variance on short EEG windows.
|
|
69
|
+
|
|
70
|
+
- **Channel Expansion**
|
|
71
|
+
|
|
72
|
+
- *Operations.*
|
|
73
|
+
- A ``1x1`` conv → BN → activation maps ``F2 → ch_dim`` without changing
|
|
74
|
+
the temporal length ``T₁`` (shape: ``(B, ch_dim, 1, T₁)``).
|
|
75
|
+
This sets the embedding width for the attention block.
|
|
76
|
+
|
|
77
|
+
- :class:`_ChannelAttentionBlock` **(temporal refinement + channel attention)**
|
|
78
|
+
|
|
79
|
+
- *Operations.*
|
|
80
|
+
- **Depthwise temporal conv** ``(1, L_a)`` (groups=``ch_dim``) + **pointwise ``1x1``**,
|
|
81
|
+
BN and activation → preserves shape ``(B, ch_dim, 1, T₁)`` while refining timing.
|
|
82
|
+
- **Optional attention module** (see *Additional Mechanisms*) applies channel reweighting
|
|
83
|
+
(some variants also apply temporal gating).
|
|
84
|
+
- **AvgPool (1, P₂)** with stride ``(1, S₂)`` and **Dropout** → outputs
|
|
85
|
+
``(B, ch_dim, 1, T₂)``.
|
|
86
|
+
|
|
87
|
+
*Role.* Emphasizes informative channels (and, in certain modes, salient time steps)
|
|
88
|
+
before the classifier; complements the convolutional priors with adaptive re-weighting.
|
|
89
|
+
|
|
90
|
+
- **Classifier (aggregation + readout)**
|
|
91
|
+
|
|
92
|
+
*Operations.* :class:`torch.nn.Flatten` → :class:`torch.nn.Linear` from
|
|
93
|
+
``(B, ch_dim·T₂)`` to classes.
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
.. rubric:: Convolutional Details
|
|
97
|
+
|
|
98
|
+
- **Temporal (where time-domain patterns are learned).**
|
|
99
|
+
Wide kernels in the stem (``(1, L_t)``) act as a learned filter bank for oscillatory
|
|
100
|
+
bands/transients; the attention block’s depthwise temporal conv (``(1, L_a)``) sharpens
|
|
101
|
+
short-term dynamics after downsampling. Pool sizes/strides (``P₁,S₁`` then ``P₂,S₂``)
|
|
102
|
+
set the token rate and effective temporal resolution.
|
|
103
|
+
|
|
104
|
+
- **Spatial (how electrodes are processed).**
|
|
105
|
+
A depthwise spatial conv with kernel ``(n_chans, 1)`` spans the full montage to
|
|
106
|
+
learn *per-temporal-filter* spatial projections (no cross-filter mixing at this step),
|
|
107
|
+
mirroring the interpretable spatial stage in shallow CNNs.
|
|
108
|
+
|
|
109
|
+
- **Spectral (how frequency content is captured).**
|
|
110
|
+
No explicit Fourier/wavelet transform is used in the stem—spectral selectivity
|
|
111
|
+
emerges from learned temporal kernels. When ``attention_mode="fca"``, a frequency
|
|
112
|
+
channel attention (DCT-based) summarizes frequencies to drive channel weights.
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
.. rubric:: Attention / Sequential Modules
|
|
116
|
+
|
|
117
|
+
- **Type.** Channel attention chosen by ``attention_mode`` (SE, ECA, CBAM, CAT, GSoP,
|
|
118
|
+
EncNet, GE, GCT, SRM, CATLite). Most operate purely on channels; CBAM/CAT additionally
|
|
119
|
+
include temporal attention.
|
|
120
|
+
- **Shapes.** Input/Output around attention: ``(B, ch_dim, 1, T₁)``. Re-arrangements
|
|
121
|
+
(if any) are internal to the module; the block returns the same shape before pooling.
|
|
122
|
+
- **Role.** Re-weights channels (and optionally time) to highlight informative sources
|
|
123
|
+
and suppress distractors, improving SNR ahead of the linear head.
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
.. rubric:: Additional Mechanisms
|
|
127
|
+
|
|
128
|
+
- **Attention variants at a glance.**
|
|
129
|
+
- ``"se"``: Squeeze-and-Excitation (global pooling → bottleneck → gates).
|
|
130
|
+
- ``"gsop"``: Global second-order pooling (covariance-aware channel weights).
|
|
131
|
+
- ``"fca"``: Frequency Channel Attention (DCT summary; uses ``seq_len`` and ``freq_idx``).
|
|
132
|
+
- ``"encnet"``: EncNet with learned codewords (uses ``n_codewords``).
|
|
133
|
+
- ``"eca"``: Efficient Channel Attention (local 1-D conv over channel descriptor; uses ``kernel_size``).
|
|
134
|
+
- ``"ge"``: Gather–Excite (context pooling with optional MLP; can use ``extra_params``).
|
|
135
|
+
- ``"gct"``: Gated Channel Transformation (global context normalization + gating).
|
|
136
|
+
- ``"srm"``: Style-based recalibration (mean–std descriptors; optional MLP).
|
|
137
|
+
- ``"cbam"``: Channel then temporal attention (uses ``kernel_size``).
|
|
138
|
+
- ``"cat"`` / ``"catlite"``: Collaborative (channel ± temporal) attention; *lite* omits temporal.
|
|
139
|
+
- **Auto-compatibility on short inputs.**
|
|
140
|
+
|
|
141
|
+
If the input duration is too short for the configured kernels/pools, the implementation
|
|
142
|
+
**automatically rescales** temporal lengths/strides downward (with a warning) to keep
|
|
143
|
+
shapes valid and preserve the pipeline semantics.
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
.. rubric:: Usage and Configuration
|
|
147
|
+
|
|
148
|
+
- ``n_temporal_filters``, ``temporal_filter_length`` and ``spatial_expansion``:
|
|
149
|
+
control the capacity and the number of spatial projections in the stem.
|
|
150
|
+
- ``pool_length_inp``, ``pool_stride_inp`` then ``pool_length``, ``pool_stride``:
|
|
151
|
+
trade temporal resolution for compute; they determine the final sequence length ``T₂``.
|
|
152
|
+
- ``ch_dim``: width after the ``1x1`` expansion and the effective embedding size for attention.
|
|
153
|
+
- ``attention_mode`` + its specific hyperparameters (``reduction_rate``,
|
|
154
|
+
``kernel_size``, ``seq_len``, ``freq_idx``, ``n_codewords``, ``use_mlp``):
|
|
155
|
+
select and tune the reweighting mechanism.
|
|
156
|
+
- ``drop_prob_inp`` and ``drop_prob_attn``: regularize stem and attention stages.
|
|
157
|
+
- **Training tips.**
|
|
158
|
+
|
|
159
|
+
Start with moderate pooling (e.g., ``P₁=75,S₁=15``) and ELU activations; enable attention
|
|
160
|
+
only after the stem learns stable filters. For small datasets, prefer simpler modes
|
|
161
|
+
(``"se"``, ``"eca"``) before heavier ones (``"gsop"``, ``"encnet"``).
|
|
162
|
+
|
|
163
|
+
Notes
|
|
164
|
+
-----
|
|
165
|
+
- Sequence length after each stage is computed internally; the final classifier expects
|
|
166
|
+
a flattened ``ch_dim x T₂`` vector.
|
|
167
|
+
- Attention operates on *channel* dimension by design; temporal gating exists only in
|
|
168
|
+
specific variants (CBAM/CAT).
|
|
47
169
|
|
|
48
170
|
.. versionadded:: 0.9
|
|
49
171
|
|
braindecode/version.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "1.2.0.
|
|
1
|
+
__version__ = "1.2.0.dev175337561"
|
{braindecode-1.2.0.dev168908090.dist-info → braindecode-1.2.0.dev175337561.dist-info}/METADATA
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.dev175337561
|
|
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.dist-info → braindecode-1.2.0.dev175337561.dist-info}/RECORD
RENAMED
|
@@ -3,7 +3,7 @@ braindecode/classifier.py,sha256=k9vSCtfQbld0YVleDi5rrrmk6k_k5JYEPPBYcNxYjZ8,980
|
|
|
3
3
|
braindecode/eegneuralnet.py,sha256=dz8k_-2jV7WqkaX4bQG-dmr-vRT7ZtOwJqomXyC9PTw,15287
|
|
4
4
|
braindecode/regressor.py,sha256=VLfrpiXklwI4onkwue3QmzlBWcvspu0tlrLo9RT1Oiw,9375
|
|
5
5
|
braindecode/util.py,sha256=J-tBcDJNlMTIFW2mfOy6Ko0nsgdP4obRoEVDeg2rFH0,12686
|
|
6
|
-
braindecode/version.py,sha256=
|
|
6
|
+
braindecode/version.py,sha256=3Qa8hXZGNQHDb0ML-Uc2XpGnkUoLzPs7R6mgvIjDB60,35
|
|
7
7
|
braindecode/augmentation/__init__.py,sha256=LG7ONqCufYAF9NZt8POIp10lYXb8iSueYkF-CWGK2Ls,1001
|
|
8
8
|
braindecode/augmentation/base.py,sha256=gg7wYsVfa9jfqBddtE03B5ZrPHFFmPl2sa3LOrRnGfo,7325
|
|
9
9
|
braindecode/augmentation/functional.py,sha256=ygkMNEFHaUdRQfk7meMML19FnM406Uf34h-ztKXdJwM,37978
|
|
@@ -28,7 +28,7 @@ braindecode/functional/functions.py,sha256=CoEweM6YLhigx0tNmmz6yAc8iQ078sTFY2GeC
|
|
|
28
28
|
braindecode/functional/initialization.py,sha256=BUSC7y2TMsfShpMYBVwm3xg3ODFqWp-STH7yD4sn8zk,1388
|
|
29
29
|
braindecode/models/__init__.py,sha256=xv1QPELZxocPgbc_mz-eYM5w08ZDNOsDV4pOnIFhUww,2551
|
|
30
30
|
braindecode/models/atcnet.py,sha256=Pn5KzQjv7YxSNDr_CY6O_Yg9K4m9XJ7btCIqyzkcPxc,32102
|
|
31
|
-
braindecode/models/attentionbasenet.py,sha256=
|
|
31
|
+
braindecode/models/attentionbasenet.py,sha256=ZThyvhiSikSjv7mv3C5QuIF4df1QxEojzhJskmXcviU,30120
|
|
32
32
|
braindecode/models/base.py,sha256=9icrWNZBGbh_VLyB9m8g_K1QyK7s3mh8X-hJ29gEbWs,10802
|
|
33
33
|
braindecode/models/biot.py,sha256=T4PymX3penMJcrdfb5Nq6B3P-jyP2laAIu_R9o3uCXo,17512
|
|
34
34
|
braindecode/models/contrawr.py,sha256=eeR_ik4gNZ3rJLM6Mw9gJ2gTMkZ8CU8C4rN_GQMQTAE,10044
|
|
@@ -93,9 +93,9 @@ braindecode/training/scoring.py,sha256=WRkwqbitA3m_dzRnGp2ZIZPge5Nhx9gAEQhIHzeH4
|
|
|
93
93
|
braindecode/visualization/__init__.py,sha256=4EER_xHqZIDzEvmgUEm7K1bgNKpyZAIClR9ZCkMuY4M,240
|
|
94
94
|
braindecode/visualization/confusion_matrices.py,sha256=qIWMLEHow5CJ7PhGggD8mnD55Le6xhma9HSzt4R33fc,9509
|
|
95
95
|
braindecode/visualization/gradients.py,sha256=KZo-GA0uwiwty2_94j2IjmCR2SKcfPb1Bi3sQq7vpTk,2170
|
|
96
|
-
braindecode-1.2.0.
|
|
97
|
-
braindecode-1.2.0.
|
|
98
|
-
braindecode-1.2.0.
|
|
99
|
-
braindecode-1.2.0.
|
|
100
|
-
braindecode-1.2.0.
|
|
101
|
-
braindecode-1.2.0.
|
|
96
|
+
braindecode-1.2.0.dev175337561.dist-info/licenses/LICENSE.txt,sha256=7rg7k6hyj8m9whQ7dpKbqnCssoOEx_Mbtqb4uSOjljE,1525
|
|
97
|
+
braindecode-1.2.0.dev175337561.dist-info/licenses/NOTICE.txt,sha256=sOxuTbalPxTM8H6VqtvGbXCt_BoOF7JevEYG_knqbm4,620
|
|
98
|
+
braindecode-1.2.0.dev175337561.dist-info/METADATA,sha256=KaA8oZvJ4p7v61Sc1ZGTouHhzfOXZI9Yed7BhfHS0eo,6883
|
|
99
|
+
braindecode-1.2.0.dev175337561.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
100
|
+
braindecode-1.2.0.dev175337561.dist-info/top_level.txt,sha256=pHsWQmSy0uhIez62-HA9j0iaXKvSbUL39ifFRkFnChA,12
|
|
101
|
+
braindecode-1.2.0.dev175337561.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{braindecode-1.2.0.dev168908090.dist-info → braindecode-1.2.0.dev175337561.dist-info}/top_level.txt
RENAMED
|
File without changes
|