braindecode 1.3.0.dev180329405__py3-none-any.whl → 1.3.0.dev182330353__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.
- braindecode/augmentation/base.py +1 -1
- braindecode/datasets/__init__.py +12 -4
- braindecode/datasets/base.py +115 -151
- braindecode/datasets/bcicomp.py +4 -4
- braindecode/datasets/bids.py +3 -3
- braindecode/datasets/experimental.py +2 -2
- braindecode/datasets/mne.py +3 -5
- braindecode/datasets/moabb.py +17 -7
- braindecode/datasets/nmt.py +2 -2
- braindecode/datasets/sleep_physio_challe_18.py +2 -2
- braindecode/datasets/sleep_physionet.py +2 -2
- braindecode/datasets/tuh.py +2 -2
- braindecode/datasets/xy.py +2 -2
- braindecode/datautil/__init__.py +11 -1
- braindecode/datautil/channel_utils.py +114 -0
- braindecode/datautil/serialization.py +7 -7
- braindecode/functional/functions.py +6 -2
- braindecode/functional/initialization.py +2 -3
- braindecode/models/__init__.py +6 -0
- braindecode/models/atcnet.py +26 -27
- braindecode/models/attentionbasenet.py +37 -32
- braindecode/models/attn_sleep.py +2 -0
- braindecode/models/base.py +280 -2
- braindecode/models/bendr.py +469 -0
- braindecode/models/biot.py +2 -0
- braindecode/models/contrawr.py +2 -0
- braindecode/models/ctnet.py +8 -3
- braindecode/models/deepsleepnet.py +28 -19
- braindecode/models/eegconformer.py +2 -2
- braindecode/models/eeginception_erp.py +31 -25
- braindecode/models/eegitnet.py +2 -0
- braindecode/models/eegminer.py +2 -0
- braindecode/models/eegnet.py +1 -1
- braindecode/models/eegsym.py +917 -0
- braindecode/models/eegtcnet.py +2 -0
- braindecode/models/fbcnet.py +5 -1
- braindecode/models/fblightconvnet.py +2 -0
- braindecode/models/fbmsnet.py +20 -6
- braindecode/models/ifnet.py +2 -0
- braindecode/models/labram.py +33 -26
- braindecode/models/medformer.py +758 -0
- braindecode/models/msvtnet.py +2 -0
- braindecode/models/patchedtransformer.py +1 -1
- braindecode/models/signal_jepa.py +111 -27
- braindecode/models/sinc_shallow.py +12 -9
- braindecode/models/sstdpn.py +11 -11
- braindecode/models/summary.csv +3 -0
- braindecode/models/syncnet.py +2 -0
- braindecode/models/tcn.py +2 -0
- braindecode/models/usleep.py +26 -21
- braindecode/models/util.py +3 -0
- braindecode/modules/attention.py +10 -10
- braindecode/modules/blocks.py +3 -3
- braindecode/modules/filter.py +2 -9
- braindecode/modules/layers.py +18 -17
- braindecode/preprocessing/__init__.py +232 -3
- braindecode/preprocessing/eegprep_preprocess.py +1202 -0
- braindecode/preprocessing/mne_preprocess.py +142 -10
- braindecode/preprocessing/preprocess.py +28 -18
- braindecode/preprocessing/util.py +166 -0
- braindecode/preprocessing/windowers.py +26 -20
- braindecode/samplers/base.py +8 -8
- braindecode/version.py +1 -1
- {braindecode-1.3.0.dev180329405.dist-info → braindecode-1.3.0.dev182330353.dist-info}/METADATA +6 -2
- braindecode-1.3.0.dev182330353.dist-info/RECORD +109 -0
- braindecode-1.3.0.dev180329405.dist-info/RECORD +0 -103
- {braindecode-1.3.0.dev180329405.dist-info → braindecode-1.3.0.dev182330353.dist-info}/WHEEL +0 -0
- {braindecode-1.3.0.dev180329405.dist-info → braindecode-1.3.0.dev182330353.dist-info}/licenses/LICENSE.txt +0 -0
- {braindecode-1.3.0.dev180329405.dist-info → braindecode-1.3.0.dev182330353.dist-info}/licenses/NOTICE.txt +0 -0
- {braindecode-1.3.0.dev180329405.dist-info → braindecode-1.3.0.dev182330353.dist-info}/top_level.txt +0 -0
braindecode/models/msvtnet.py
CHANGED
|
@@ -13,6 +13,8 @@ from braindecode.models.base import EEGModuleMixin
|
|
|
13
13
|
class MSVTNet(EEGModuleMixin, nn.Module):
|
|
14
14
|
"""MSVTNet model from Liu K et al (2024) from [msvt2024]_.
|
|
15
15
|
|
|
16
|
+
:bdg-success:`Convolution` :bdg-secondary:`Recurrent` :bdg-info:`Small Attention`
|
|
17
|
+
|
|
16
18
|
This model implements a multi-scale convolutional transformer network
|
|
17
19
|
for EEG signal classification, as described in [msvt2024]_.
|
|
18
20
|
|
|
@@ -16,7 +16,7 @@ from braindecode.models.base import EEGModuleMixin
|
|
|
16
16
|
class PBT(EEGModuleMixin, nn.Module):
|
|
17
17
|
r"""Patched Brain Transformer (PBT) model from Klein et al. (2025) [pbt]_.
|
|
18
18
|
|
|
19
|
-
:bdg-danger:`Large Brain
|
|
19
|
+
:bdg-danger:`Large Brain Model`
|
|
20
20
|
|
|
21
21
|
This implementation was based in https://github.com/timonkl/PatchedBrainTransformer/
|
|
22
22
|
|
|
@@ -5,7 +5,8 @@ from __future__ import annotations
|
|
|
5
5
|
|
|
6
6
|
import math
|
|
7
7
|
from copy import deepcopy
|
|
8
|
-
from
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import Any, Optional, Sequence
|
|
9
10
|
|
|
10
11
|
import torch
|
|
11
12
|
from einops.layers.torch import Rearrange
|
|
@@ -145,6 +146,8 @@ class _BaseSignalJEPA(EEGModuleMixin, nn.Module):
|
|
|
145
146
|
class SignalJEPA(_BaseSignalJEPA):
|
|
146
147
|
"""Architecture introduced in signal-JEPA for self-supervised pre-training, Guetschel, P et al (2024) [1]_
|
|
147
148
|
|
|
149
|
+
:bdg-success:`Convolution` :bdg-dark-line:`Channel` :bdg-danger:`Large Brain Model`
|
|
150
|
+
|
|
148
151
|
This model is not meant for classification but for SSL pre-training.
|
|
149
152
|
Its output shape depends on the input shape.
|
|
150
153
|
For classification purposes, three variants of this model are available:
|
|
@@ -231,6 +234,8 @@ class SignalJEPA(_BaseSignalJEPA):
|
|
|
231
234
|
class SignalJEPA_Contextual(_BaseSignalJEPA):
|
|
232
235
|
"""Contextual downstream architecture introduced in signal-JEPA Guetschel, P et al (2024) [1]_.
|
|
233
236
|
|
|
237
|
+
:bdg-success:`Convolution` :bdg-dark-line:`Channel` :bdg-danger:`Large Brain Model`
|
|
238
|
+
|
|
234
239
|
This architecture is one of the variants of :class:`SignalJEPA`
|
|
235
240
|
that can be used for classification purposes.
|
|
236
241
|
|
|
@@ -319,25 +324,50 @@ class SignalJEPA_Contextual(_BaseSignalJEPA):
|
|
|
319
324
|
@classmethod
|
|
320
325
|
def from_pretrained(
|
|
321
326
|
cls,
|
|
322
|
-
model: SignalJEPA,
|
|
323
|
-
n_outputs: int,
|
|
327
|
+
model: Optional[SignalJEPA | str | Path] = None, # type: ignore
|
|
328
|
+
n_outputs: Optional[int] = None, # type: ignore
|
|
324
329
|
n_spat_filters: int = 4,
|
|
325
|
-
chs_info: list[dict[str, Any]]
|
|
330
|
+
chs_info: Optional[list[dict[str, Any]]] = None, # type: ignore
|
|
331
|
+
**kwargs,
|
|
326
332
|
):
|
|
327
|
-
"""Instantiate a new model from a pre-trained :class:`SignalJEPA` model.
|
|
333
|
+
"""Instantiate a new model from a pre-trained :class:`SignalJEPA` model or from Hub.
|
|
328
334
|
|
|
329
335
|
Parameters
|
|
330
336
|
----------
|
|
331
|
-
model: SignalJEPA
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
337
|
+
model: SignalJEPA, str, Path, or None
|
|
338
|
+
Either a pre-trained :class:`SignalJEPA` model, a string/Path to a local directory
|
|
339
|
+
(for Hub-style loading), or None (for Hub loading via kwargs).
|
|
340
|
+
n_outputs: int or None
|
|
341
|
+
Number of classes for the new model. Required when loading from a SignalJEPA model,
|
|
342
|
+
optional when loading from Hub (will be read from config).
|
|
335
343
|
n_spat_filters: int
|
|
336
344
|
Number of spatial filters.
|
|
337
345
|
chs_info: list of dict | None
|
|
338
346
|
Information about each individual EEG channel. This should be filled with
|
|
339
347
|
``info["chs"]``. Refer to :class:`mne.Info` for more details.
|
|
348
|
+
**kwargs
|
|
349
|
+
Additional keyword arguments passed to the parent class for Hub loading.
|
|
340
350
|
"""
|
|
351
|
+
# Check if this is a Hub-style load (from a directory path)
|
|
352
|
+
if isinstance(model, (str, Path)) or (model is None and kwargs):
|
|
353
|
+
# This is a Hub load, delegate to parent class
|
|
354
|
+
if isinstance(model, (str, Path)):
|
|
355
|
+
# model is actually the repo_id or directory path
|
|
356
|
+
return super().from_pretrained(model, **kwargs)
|
|
357
|
+
else:
|
|
358
|
+
# model is None, treat as hub-style load
|
|
359
|
+
return super().from_pretrained(**kwargs)
|
|
360
|
+
|
|
361
|
+
# This is the original SignalJEPA transfer learning case
|
|
362
|
+
if not isinstance(model, SignalJEPA):
|
|
363
|
+
raise TypeError(
|
|
364
|
+
f"model must be a SignalJEPA instance, a path string, or Path object, got {type(model)}"
|
|
365
|
+
)
|
|
366
|
+
if n_outputs is None:
|
|
367
|
+
raise ValueError(
|
|
368
|
+
"n_outputs must be provided when loading from a SignalJEPA model"
|
|
369
|
+
)
|
|
370
|
+
|
|
341
371
|
feature_encoder = model.feature_encoder
|
|
342
372
|
pos_encoder = model.pos_encoder
|
|
343
373
|
transformer = model.transformer
|
|
@@ -377,6 +407,8 @@ class SignalJEPA_Contextual(_BaseSignalJEPA):
|
|
|
377
407
|
class SignalJEPA_PostLocal(_BaseSignalJEPA):
|
|
378
408
|
"""Post-local downstream architecture introduced in signal-JEPA Guetschel, P et al (2024) [1]_.
|
|
379
409
|
|
|
410
|
+
:bdg-success:`Convolution` :bdg-dark-line:`Channel` :bdg-danger:`Large Brain Model`
|
|
411
|
+
|
|
380
412
|
This architecture is one of the variants of :class:`SignalJEPA`
|
|
381
413
|
that can be used for classification purposes.
|
|
382
414
|
|
|
@@ -463,22 +495,47 @@ class SignalJEPA_PostLocal(_BaseSignalJEPA):
|
|
|
463
495
|
|
|
464
496
|
@classmethod
|
|
465
497
|
def from_pretrained(
|
|
466
|
-
cls,
|
|
498
|
+
cls,
|
|
499
|
+
model: SignalJEPA | str | Path = None, # type: ignore
|
|
500
|
+
n_outputs: int = None, # type: ignore
|
|
501
|
+
n_spat_filters: int = 4,
|
|
502
|
+
**kwargs,
|
|
467
503
|
):
|
|
468
|
-
"""Instantiate a new model from a pre-trained :class:`SignalJEPA` model.
|
|
504
|
+
"""Instantiate a new model from a pre-trained :class:`SignalJEPA` model or from Hub.
|
|
469
505
|
|
|
470
506
|
Parameters
|
|
471
507
|
----------
|
|
472
|
-
model: SignalJEPA
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
508
|
+
model: SignalJEPA, str, Path, or None
|
|
509
|
+
Either a pre-trained :class:`SignalJEPA` model, a string/Path to a local directory
|
|
510
|
+
(for Hub-style loading), or None (for Hub loading via kwargs).
|
|
511
|
+
n_outputs: int or None
|
|
512
|
+
Number of classes for the new model. Required when loading from a SignalJEPA model,
|
|
513
|
+
optional when loading from Hub (will be read from config).
|
|
476
514
|
n_spat_filters: int
|
|
477
515
|
Number of spatial filters.
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
``info["chs"]``. Refer to :class:`mne.Info` for more details.
|
|
516
|
+
**kwargs
|
|
517
|
+
Additional keyword arguments passed to the parent class for Hub loading.
|
|
481
518
|
"""
|
|
519
|
+
# Check if this is a Hub-style load (from a directory path)
|
|
520
|
+
if isinstance(model, (str, Path)) or (model is None and kwargs):
|
|
521
|
+
# This is a Hub load, delegate to parent class
|
|
522
|
+
if isinstance(model, (str, Path)):
|
|
523
|
+
# model is actually the repo_id or directory path
|
|
524
|
+
return super().from_pretrained(model, **kwargs)
|
|
525
|
+
else:
|
|
526
|
+
# model is None, treat as hub-style load
|
|
527
|
+
return super().from_pretrained(**kwargs)
|
|
528
|
+
|
|
529
|
+
# This is the original SignalJEPA transfer learning case
|
|
530
|
+
if not isinstance(model, SignalJEPA):
|
|
531
|
+
raise TypeError(
|
|
532
|
+
f"model must be a SignalJEPA instance, a path string, or Path object, got {type(model)}"
|
|
533
|
+
)
|
|
534
|
+
if n_outputs is None:
|
|
535
|
+
raise ValueError(
|
|
536
|
+
"n_outputs must be provided when loading from a SignalJEPA model"
|
|
537
|
+
)
|
|
538
|
+
|
|
482
539
|
feature_encoder = model.feature_encoder
|
|
483
540
|
assert feature_encoder is not None
|
|
484
541
|
new_model = cls(
|
|
@@ -501,6 +558,8 @@ class SignalJEPA_PostLocal(_BaseSignalJEPA):
|
|
|
501
558
|
class SignalJEPA_PreLocal(_BaseSignalJEPA):
|
|
502
559
|
"""Pre-local downstream architecture introduced in signal-JEPA Guetschel, P et al (2024) [1]_.
|
|
503
560
|
|
|
561
|
+
:bdg-success:`Convolution` :bdg-dark-line:`Channel` :bdg-danger:`Large Brain Model`
|
|
562
|
+
|
|
504
563
|
This architecture is one of the variants of :class:`SignalJEPA`
|
|
505
564
|
that can be used for classification purposes.
|
|
506
565
|
|
|
@@ -597,22 +656,47 @@ class SignalJEPA_PreLocal(_BaseSignalJEPA):
|
|
|
597
656
|
|
|
598
657
|
@classmethod
|
|
599
658
|
def from_pretrained(
|
|
600
|
-
cls,
|
|
659
|
+
cls,
|
|
660
|
+
model: SignalJEPA | str | Path = None, # type: ignore
|
|
661
|
+
n_outputs: int = None, # type: ignore
|
|
662
|
+
n_spat_filters: int = 4,
|
|
663
|
+
**kwargs,
|
|
601
664
|
):
|
|
602
|
-
"""Instantiate a new model from a pre-trained :class:`SignalJEPA` model.
|
|
665
|
+
"""Instantiate a new model from a pre-trained :class:`SignalJEPA` model or from Hub.
|
|
603
666
|
|
|
604
667
|
Parameters
|
|
605
668
|
----------
|
|
606
|
-
model: SignalJEPA
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
669
|
+
model: SignalJEPA, str, Path, or None
|
|
670
|
+
Either a pre-trained :class:`SignalJEPA` model, a string/Path to a local directory
|
|
671
|
+
(for Hub-style loading), or None (for Hub loading via kwargs).
|
|
672
|
+
n_outputs: int or None
|
|
673
|
+
Number of classes for the new model. Required when loading from a SignalJEPA model,
|
|
674
|
+
optional when loading from Hub (will be read from config).
|
|
610
675
|
n_spat_filters: int
|
|
611
676
|
Number of spatial filters.
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
``info["chs"]``. Refer to :class:`mne.Info` for more details.
|
|
677
|
+
**kwargs
|
|
678
|
+
Additional keyword arguments passed to the parent class for Hub loading.
|
|
615
679
|
"""
|
|
680
|
+
# Check if this is a Hub-style load (from a directory path)
|
|
681
|
+
if isinstance(model, (str, Path)) or (model is None and kwargs):
|
|
682
|
+
# This is a Hub load, delegate to parent class
|
|
683
|
+
if isinstance(model, (str, Path)):
|
|
684
|
+
# model is actually the repo_id or directory path
|
|
685
|
+
return super().from_pretrained(model, **kwargs)
|
|
686
|
+
else:
|
|
687
|
+
# model is None, treat as hub-style load
|
|
688
|
+
return super().from_pretrained(**kwargs)
|
|
689
|
+
|
|
690
|
+
# This is the original SignalJEPA transfer learning case
|
|
691
|
+
if not isinstance(model, SignalJEPA):
|
|
692
|
+
raise TypeError(
|
|
693
|
+
f"model must be a SignalJEPA instance, a path string, or Path object, got {type(model)}"
|
|
694
|
+
)
|
|
695
|
+
if n_outputs is None:
|
|
696
|
+
raise ValueError(
|
|
697
|
+
"n_outputs must be provided when loading from a SignalJEPA model"
|
|
698
|
+
)
|
|
699
|
+
|
|
616
700
|
feature_encoder = model.feature_encoder
|
|
617
701
|
assert feature_encoder is not None
|
|
618
702
|
new_model = cls(
|
|
@@ -12,6 +12,8 @@ from braindecode.models.base import EEGModuleMixin
|
|
|
12
12
|
class SincShallowNet(EEGModuleMixin, nn.Module):
|
|
13
13
|
"""Sinc-ShallowNet from Borra, D et al (2020) [borra2020]_.
|
|
14
14
|
|
|
15
|
+
:bdg-success:`Convolution` :bdg-warning:`Interpretability`
|
|
16
|
+
|
|
15
17
|
.. figure:: https://ars.els-cdn.com/content/image/1-s2.0-S0893608020302021-gr2_lrg.jpg
|
|
16
18
|
:align: center
|
|
17
19
|
:alt: SincShallowNet Architecture
|
|
@@ -19,23 +21,24 @@ class SincShallowNet(EEGModuleMixin, nn.Module):
|
|
|
19
21
|
The Sinc-ShallowNet architecture has these fundamental blocks:
|
|
20
22
|
|
|
21
23
|
1. **Block 1: Spectral and Spatial Feature Extraction**
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
- *Batch Normalization*
|
|
24
|
+
|
|
25
|
+
- *Temporal Sinc-Convolutional Layer*: Uses parametrized sinc functions to learn band-pass filters,
|
|
26
|
+
significantly reducing the number of trainable parameters by only
|
|
27
|
+
learning the lower and upper cutoff frequencies for each filter.
|
|
28
|
+
- *Spatial Depthwise Convolutional Layer*: Applies depthwise convolutions to learn spatial filters for
|
|
29
|
+
each temporal feature map independently, further reducing
|
|
30
|
+
parameters and enhancing interpretability.
|
|
31
|
+
- *Batch Normalization*
|
|
31
32
|
|
|
32
33
|
2. **Block 2: Temporal Aggregation**
|
|
34
|
+
|
|
33
35
|
- *Activation Function*: ELU
|
|
34
36
|
- *Average Pooling Layer*: Aggregation by averaging spatial dim
|
|
35
37
|
- *Dropout Layer*
|
|
36
38
|
- *Flatten Layer*
|
|
37
39
|
|
|
38
40
|
3. **Block 3: Classification**
|
|
41
|
+
|
|
39
42
|
- *Fully Connected Layer*: Maps the feature vector to n_outputs.
|
|
40
43
|
|
|
41
44
|
**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
|
@@ -13,6 +13,7 @@ EEGInceptionMI,Motor Imagery,Classification,250,"n_chans, n_outputs, n_times",55
|
|
|
13
13
|
EEGITNet,Motor Imagery,Classification,125,"n_chans, n_outputs, n_times",5212,"EEGITNet(n_chans=22, n_outputs=4, n_times=500)","Convolution,Recurrent"
|
|
14
14
|
EEGNet,General,Classification,128,"n_chans, n_outputs, n_times",2484,"EEGNet(n_chans=22, n_outputs=4, n_times=512)","Convolution"
|
|
15
15
|
EEGNeX,Motor Imagery,Classification,125,"n_chans, n_outputs, n_times",55940,"EEGNeX(n_chans=22, n_outputs=4, n_times=500)","Convolution"
|
|
16
|
+
EEGSym,Motor Imagery,Classification,250,"n_chans, n_outputs, n_times, sfreq",299218,"EEGSym(n_chans=22, n_outputs=4, n_times=1000, sfreq=250)","Convolution,Channel"
|
|
16
17
|
EEGMiner,Emotion Recognition,Classification,128,"n_chans, n_outputs, n_times, sfreq",7572,"EEGMiner(n_chans=62, n_outputs=2, n_times=2560, sfreq=128)","Convolution,Interpretability"
|
|
17
18
|
EEGSimpleConv,Motor Imagery,Classification,80,"n_chans, n_outputs, sfreq",730404,"EEGSimpleConv(n_chans=22, n_outputs=4, n_times=320, sfreq=80)","Convolution"
|
|
18
19
|
EEGTCNet,Motor Imagery,Classification,250,"n_chans, n_outputs",4516,"EEGTCNet(n_chans=22, n_outputs=4, n_times=1000, kern_length=32)","Convolution,Recurrent"
|
|
@@ -39,3 +40,5 @@ FBLightConvNet,Motor Imagery,Classification,250,"n_chans, n_outputs, n_times, sf
|
|
|
39
40
|
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
41
|
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
42
|
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"
|
|
43
|
+
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"
|
|
44
|
+
MEDFormer,General,Classification,250,"n_chans, n_outputs, n_times",5313924,"MEDFormer(n_chans=22, n_outputs=4, n_times=1000)","Large Brain Model,Convolution"
|
braindecode/models/syncnet.py
CHANGED
|
@@ -10,6 +10,8 @@ from braindecode.models.base import EEGModuleMixin
|
|
|
10
10
|
class SyncNet(EEGModuleMixin, nn.Module):
|
|
11
11
|
"""Synchronization Network (SyncNet) from Li, Y et al (2017) [Li2017]_.
|
|
12
12
|
|
|
13
|
+
:bdg-warning:`Interpretability`
|
|
14
|
+
|
|
13
15
|
.. figure:: https://braindecode.org/dev/_static/model/SyncNet.png
|
|
14
16
|
:align: center
|
|
15
17
|
:alt: SyncNet Architecture
|
braindecode/models/tcn.py
CHANGED
|
@@ -14,6 +14,8 @@ from braindecode.modules import Chomp1d, Ensure4d, SqueezeFinalOutput
|
|
|
14
14
|
class BDTCN(EEGModuleMixin, nn.Module):
|
|
15
15
|
"""Braindecode TCN from Gemein, L et al (2020) [gemein2020]_.
|
|
16
16
|
|
|
17
|
+
:bdg-success:`Convolution` :bdg-secondary:`Recurrent`
|
|
18
|
+
|
|
17
19
|
.. figure:: https://ars.els-cdn.com/content/image/1-s2.0-S1053811920305073-gr3_lrg.jpg
|
|
18
20
|
:align: center
|
|
19
21
|
:alt: Braindecode TCN Architecture
|
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
|
@@ -79,6 +79,7 @@ models_mandatory_parameters = [
|
|
|
79
79
|
("SPARCNet", ["n_chans", "n_outputs", "n_times"], None),
|
|
80
80
|
("ContraWR", ["n_chans", "n_outputs", "sfreq", "n_times"], dict(sfreq=200.0)),
|
|
81
81
|
("EEGNeX", ["n_chans", "n_outputs", "n_times"], None),
|
|
82
|
+
("EEGSym", ["chs_info", "n_chans", "n_outputs", "n_times", "sfreq"], None),
|
|
82
83
|
("TSception", ["n_chans", "n_outputs", "n_times", "sfreq"], dict(sfreq=200.0)),
|
|
83
84
|
("EEGTCNet", ["n_chans", "n_outputs", "n_times"], None),
|
|
84
85
|
("SyncNet", ["n_chans", "n_outputs", "n_times"], None),
|
|
@@ -97,6 +98,8 @@ models_mandatory_parameters = [
|
|
|
97
98
|
("IFNet", ["n_chans", "n_outputs", "n_times", "sfreq"], dict(sfreq=200.0)),
|
|
98
99
|
("PBT", ["n_chans", "n_outputs", "n_times"], None),
|
|
99
100
|
("SSTDPN", ["n_chans", "n_outputs", "n_times", "sfreq"], None),
|
|
101
|
+
("BENDR", ["n_chans", "n_outputs", "n_times"], None),
|
|
102
|
+
("MEDFormer", ["n_chans", "n_outputs", "n_times"], None),
|
|
100
103
|
]
|
|
101
104
|
|
|
102
105
|
################################################################
|
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
|
|
@@ -110,11 +109,6 @@ class FilterBankLayer(nn.Module):
|
|
|
110
109
|
or "firwin2" to use :func:`scipy.signal.firwin2`. "firwin" uses
|
|
111
110
|
a time-domain design technique that generally gives improved
|
|
112
111
|
attenuation using fewer samples than "firwin2".
|
|
113
|
-
pad : str, default='reflect_limited'
|
|
114
|
-
The type of padding to use. Supports all func:`numpy.pad()` mode options.
|
|
115
|
-
Can also be "reflect_limited", which pads with a reflected version of
|
|
116
|
-
each vector mirrored on the first and last values of the vector,
|
|
117
|
-
followed by zeros. Only used for ``method='fir'``.
|
|
118
112
|
verbose: bool | str | int | None, default=True
|
|
119
113
|
Control verbosity of the logging output. If ``None``, use the default
|
|
120
114
|
verbosity level. See the func:`mne.verbose` for details.
|
|
@@ -184,7 +178,6 @@ class FilterBankLayer(nn.Module):
|
|
|
184
178
|
"The band_filters items should be splitable in 2 values."
|
|
185
179
|
)
|
|
186
180
|
|
|
187
|
-
# and we accepted as
|
|
188
181
|
self.band_filters = band_filters
|
|
189
182
|
self.n_bands = len(band_filters)
|
|
190
183
|
self.phase = phase
|