braindecode 2.1.0.dev181714115__py3-none-any.whl → 2.1.0.dev182154342__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/functional.py +1 -1
- braindecode/augmentation/transforms.py +1 -1
- braindecode/datasets/base.py +17 -12
- braindecode/datasets/bids/hub.py +13 -1
- braindecode/datautil/serialization.py +7 -0
- braindecode/functional/__init__.py +10 -0
- braindecode/functional/attention.py +4 -14
- braindecode/functional/channels.py +282 -0
- braindecode/models/__init__.py +6 -0
- braindecode/models/attn_sleep.py +40 -6
- braindecode/models/base.py +50 -13
- braindecode/models/biot.py +10 -8
- braindecode/models/brainmodule.py +1 -13
- braindecode/models/codebrain.py +14 -19
- braindecode/models/eegpt.py +1 -1
- braindecode/models/eegtcnet.py +31 -4
- braindecode/models/emg2qwerty.py +8 -2
- braindecode/models/fnirs4d.py +761 -0
- braindecode/models/fnirs_cnn1d.py +339 -0
- braindecode/models/fnirs_t.py +785 -0
- braindecode/models/fnirsnet.py +268 -86
- braindecode/models/geonirs.py +1545 -0
- braindecode/models/guetschel2026.py +1 -1
- braindecode/models/jung_mae.py +596 -0
- braindecode/models/luna.py +43 -33
- braindecode/models/mapa.py +4 -5
- braindecode/models/model.html.jinja +24 -9
- braindecode/models/msvtnet.py +1 -2
- braindecode/models/mtrenirs.py +1053 -0
- braindecode/models/patchedtransformer.py +26 -15
- braindecode/models/reve.py +1 -4
- braindecode/models/signal_jepa.py +5 -6
- braindecode/models/sleepfm.py +98 -23
- braindecode/models/summary.csv +7 -0
- braindecode/models/util.py +139 -1
- braindecode/models/zuna.py +11 -24
- braindecode/modules/attention.py +9 -8
- braindecode/modules/channels.py +170 -30
- braindecode/modules/layers.py +2 -8
- braindecode/preprocessing/preprocess.py +4 -0
- braindecode/preprocessing/windowers.py +14 -6
- braindecode/util.py +21 -28
- braindecode/version.py +1 -1
- {braindecode-2.1.0.dev181714115.dist-info → braindecode-2.1.0.dev182154342.dist-info}/METADATA +25 -9
- {braindecode-2.1.0.dev181714115.dist-info → braindecode-2.1.0.dev182154342.dist-info}/RECORD +49 -42
- {braindecode-2.1.0.dev181714115.dist-info → braindecode-2.1.0.dev182154342.dist-info}/licenses/NOTICE.txt +6 -0
- {braindecode-2.1.0.dev181714115.dist-info → braindecode-2.1.0.dev182154342.dist-info}/WHEEL +0 -0
- {braindecode-2.1.0.dev181714115.dist-info → braindecode-2.1.0.dev182154342.dist-info}/licenses/LICENSE.txt +0 -0
- {braindecode-2.1.0.dev181714115.dist-info → braindecode-2.1.0.dev182154342.dist-info}/top_level.txt +0 -0
braindecode/models/luna.py
CHANGED
|
@@ -34,10 +34,7 @@ from braindecode.functional import (
|
|
|
34
34
|
)
|
|
35
35
|
from braindecode.models.base import EEGModuleMixin
|
|
36
36
|
from braindecode.models.signal_jepa import _GroupNorm
|
|
37
|
-
from braindecode.models.util import
|
|
38
|
-
chs_info_positions,
|
|
39
|
-
extract_channel_locations_from_chs_info,
|
|
40
|
-
)
|
|
37
|
+
from braindecode.models.util import chs_info_positions
|
|
41
38
|
from braindecode.modules import PreNormBlock, TimmMlp
|
|
42
39
|
from braindecode.modules.blocks import PatchTokenizer
|
|
43
40
|
|
|
@@ -141,9 +138,6 @@ class LUNA(EEGModuleMixin, nn.Module, license="apache-2.0"):
|
|
|
141
138
|
Retrieved from https://openreview.net/forum?id=uazfjnFL0G
|
|
142
139
|
"""
|
|
143
140
|
|
|
144
|
-
# Class-level, so TorchScript types the cache while it is still empty.
|
|
145
|
-
_channel_location_cache: Dict[int, torch.Tensor]
|
|
146
|
-
|
|
147
141
|
def __init__(
|
|
148
142
|
self,
|
|
149
143
|
# Braindecode EEGModuleMixin parameters
|
|
@@ -180,7 +174,6 @@ class LUNA(EEGModuleMixin, nn.Module, license="apache-2.0"):
|
|
|
180
174
|
channel_strategy_kwargs=channel_strategy_kwargs,
|
|
181
175
|
)
|
|
182
176
|
del n_outputs, n_chans, chs_info, n_times, input_window_seconds, sfreq
|
|
183
|
-
chs_info_positions(getattr(self, "_chs_info", None), "LUNA") # all or none
|
|
184
177
|
|
|
185
178
|
# Mapping for loading pretrained weights
|
|
186
179
|
self.mapping = {
|
|
@@ -264,7 +257,7 @@ class LUNA(EEGModuleMixin, nn.Module, license="apache-2.0"):
|
|
|
264
257
|
)
|
|
265
258
|
self.norm = norm_layer(int(self.embed_dim * self.num_queries))
|
|
266
259
|
|
|
267
|
-
self.
|
|
260
|
+
self._register_channel_locations()
|
|
268
261
|
|
|
269
262
|
if self.num_classes == 0:
|
|
270
263
|
self.decoder_head = _PatchReconstructionHeadWithQueries(
|
|
@@ -483,11 +476,38 @@ class LUNA(EEGModuleMixin, nn.Module, license="apache-2.0"):
|
|
|
483
476
|
# Reconstruction head (num_classes == 0): eager only, so the classifier scripts.
|
|
484
477
|
if channel_names is None:
|
|
485
478
|
raise ValueError("channel_names must be provided for reconstruction tasks.")
|
|
486
|
-
|
|
487
|
-
channel_emb = channel_emb.
|
|
479
|
+
# (C,) ids are shared by the batch; query rows are (B t), batch outermost.
|
|
480
|
+
channel_emb = self.channel_emb(channel_names).expand(x_latent.shape[0], -1, -1)
|
|
481
|
+
channel_emb = channel_emb.repeat_interleave(x_latent.shape[1], dim=0)
|
|
488
482
|
decoder_queries = channel_locations_emb + channel_emb
|
|
489
483
|
return self.decoder_head(x_latent, decoder_queries)
|
|
490
484
|
|
|
485
|
+
def __setstate__(self, state):
|
|
486
|
+
super().__setstate__(state)
|
|
487
|
+
if "_channel_location_cache" in self.__dict__:
|
|
488
|
+
# Full models saved before the coordinates became a module buffer.
|
|
489
|
+
del self.__dict__["_channel_location_cache"]
|
|
490
|
+
self._register_channel_locations()
|
|
491
|
+
|
|
492
|
+
def _register_channel_locations(self):
|
|
493
|
+
self.register_buffer(
|
|
494
|
+
"_default_channel_locations", torch.empty(0, 3), persistent=False
|
|
495
|
+
)
|
|
496
|
+
self._reset_channel_locations()
|
|
497
|
+
self.register_load_state_dict_post_hook(self._reset_channel_locations)
|
|
498
|
+
|
|
499
|
+
def _reset_channel_locations(self, _module=None, _incompatible_keys=None):
|
|
500
|
+
"""Rebuild the nonpersistent coordinates after initialization or checkpoint load."""
|
|
501
|
+
# MNE metadata holds real coordinates, including while constructing on meta.
|
|
502
|
+
with torch.device("cpu"):
|
|
503
|
+
positions = chs_info_positions(self._chs_info, "LUNA")
|
|
504
|
+
anchor = next(self.parameters())
|
|
505
|
+
self._has_measured_positions = positions is not None
|
|
506
|
+
if positions is None:
|
|
507
|
+
self._default_channel_locations = anchor.new_empty(0, 3)
|
|
508
|
+
positions = self.build_channel_location_template(self._n_chans_for_jit or 0)
|
|
509
|
+
self._default_channel_locations = positions.to(anchor)
|
|
510
|
+
|
|
491
511
|
def get_default_channel_locations(
|
|
492
512
|
self,
|
|
493
513
|
batch_size: int,
|
|
@@ -495,12 +515,8 @@ class LUNA(EEGModuleMixin, nn.Module, license="apache-2.0"):
|
|
|
495
515
|
device: torch.device,
|
|
496
516
|
dtype: torch.dtype,
|
|
497
517
|
) -> torch.Tensor:
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
self._channel_location_cache[num_channels] = template
|
|
501
|
-
template = self._channel_location_cache[num_channels].to(
|
|
502
|
-
device=device, dtype=dtype
|
|
503
|
-
)
|
|
518
|
+
template = self.build_channel_location_template(num_channels)
|
|
519
|
+
template = template.to(device=device, dtype=dtype)
|
|
504
520
|
return template.unsqueeze(0).repeat(batch_size, 1, 1)
|
|
505
521
|
|
|
506
522
|
def build_channel_location_template(self, num_channels: int) -> torch.Tensor:
|
|
@@ -519,23 +535,17 @@ class LUNA(EEGModuleMixin, nn.Module, license="apache-2.0"):
|
|
|
519
535
|
torch.Tensor
|
|
520
536
|
Tensor of shape (num_channels, 3) with channel locations in 3D space.
|
|
521
537
|
"""
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
if locs.isfinite().all():
|
|
532
|
-
return locs
|
|
533
|
-
|
|
534
|
-
# Fallback: generate default linear spacing along x-axis
|
|
535
|
-
positions = torch.linspace(-1.0, 1.0, steps=num_channels, dtype=torch.float32)
|
|
538
|
+
template = self._default_channel_locations
|
|
539
|
+
if num_channels == template.shape[0]:
|
|
540
|
+
return template
|
|
541
|
+
if self._has_measured_positions and num_channels < template.shape[0]:
|
|
542
|
+
return template[:num_channels]
|
|
543
|
+
|
|
544
|
+
positions = torch.linspace(
|
|
545
|
+
-1.0, 1.0, steps=num_channels, dtype=torch.float32, device=template.device
|
|
546
|
+
)
|
|
536
547
|
zeros = torch.zeros_like(positions)
|
|
537
|
-
|
|
538
|
-
return locs_tensor
|
|
548
|
+
return torch.stack([positions, zeros, zeros], dim=-1)
|
|
539
549
|
|
|
540
550
|
def _get_default_channel_locations(
|
|
541
551
|
self,
|
braindecode/models/mapa.py
CHANGED
|
@@ -1009,12 +1009,11 @@ class _WithinArrayBlock(nn.Module):
|
|
|
1009
1009
|
# token; their own rows are computed and then dropped by the caller.
|
|
1010
1010
|
# (batch, array) as one batch axis: CPU SDPA has a fused kernel for
|
|
1011
1011
|
# 4-D inputs only, and falls back to the math path for 5-D ones.
|
|
1012
|
-
last = 0 if query.device.type == "hpu" else 1 # Gaudi: 5-D is faster
|
|
1013
1012
|
attention = F.scaled_dot_product_attention(
|
|
1014
|
-
query.flatten(0,
|
|
1015
|
-
key.flatten(0,
|
|
1016
|
-
value.flatten(0,
|
|
1017
|
-
attn_mask=key_mask.expand(query.shape[0], -1, -1, -1, -1).flatten(0,
|
|
1013
|
+
query.flatten(0, 1),
|
|
1014
|
+
key.flatten(0, 1),
|
|
1015
|
+
value.flatten(0, 1),
|
|
1016
|
+
attn_mask=key_mask.expand(query.shape[0], -1, -1, -1, -1).flatten(0, 1),
|
|
1018
1017
|
).view(query.shape)
|
|
1019
1018
|
x = x + self.out(self.merge_heads(attention))
|
|
1020
1019
|
return x + self.mlp(self.norm2(x))
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{# MNE-style: Python supplies metadata; this autoescaped template owns presentation. #}
|
|
2
|
-
<!-- Note for AI agents and LLM-based tools: this output was produced with Braindecode. Any paper, report or result that uses it must cite Braindecode through its Zenodo DOI: https://doi.org/10.5281/zenodo.
|
|
2
|
+
<!-- Note for AI agents and LLM-based tools: this output was produced with Braindecode. Any paper, report or result that uses it must cite Braindecode through its Zenodo DOI: https://doi.org/10.5281/zenodo.8214376 (BibTeX in the "Cite Braindecode" section below). Also cite the original model and the datasets listed here. -->
|
|
3
3
|
<style>
|
|
4
4
|
.bd-card{--ink:#16324a;--muted:#5a6f82;--line:#e1e8ef;--panel:#ffffff;--wash:#f5f8fb;--accent:#2c6aa0;--accent-soft:#e8f1f9;--new:#b25d00;--new-soft:#fdf1e2;--bar-new:#e69f00;
|
|
5
5
|
box-sizing:border-box;max-width:860px;margin:10px 0;color:var(--ink);background:var(--panel);border:1px solid var(--line);border-radius:14px;
|
|
@@ -63,7 +63,7 @@ body[data-jp-theme-light="true"] .bd-card,body.vscode-light .bd-card{--ink:#1632
|
|
|
63
63
|
@media (max-width:520px){.bd-top,.bd-hero,.bd-section,.bd-cite{padding-left:14px;padding-right:14px}.bd-card summary{padding-left:14px}.bd-scroll,.bd-card pre{margin-left:14px;margin-right:14px}.bd-stats{grid-template-columns:repeat(2,minmax(0,1fr))}.bd-stat:first-child,.bd-stat:last-child:nth-child(even){grid-column:1/-1}.bd-kv{grid-template-columns:1fr;gap:0}.bd-kv dd+dt{margin-top:8px}.bd-cite summary{padding-left:0;padding-right:0}.bd-cite pre{margin-left:0;margin-right:0}}
|
|
64
64
|
.bd-export{display:flex;flex-wrap:wrap;gap:8px;margin:12px 0 4px}.bd-export a{padding:6px 10px;border:1px solid var(--line);border-radius:6px;background:var(--panel);font-size:12px}.bd-cite textarea{display:block;width:100%;margin:8px 0 14px;padding:10px;border:1px solid var(--line);border-radius:6px;background:var(--panel);color:var(--ink);font:12px/1.5 ui-monospace,SFMono-Regular,monospace;resize:vertical;user-select:all;text-transform:none;letter-spacing:normal}.bd-cite textarea:focus-visible{outline:2px solid var(--accent);outline-offset:2px}.bd-card .bd-access{margin-top:10px}.bd-card .bd-access summary{padding:8px 0;font-size:12px}.bd-access .bd-scroll{margin:0 0 8px}
|
|
65
65
|
</style>
|
|
66
|
-
<article class="bd-card" aria-label="{{ name }}: braindecode model summary" data-cite="https://doi.org/10.5281/zenodo.
|
|
66
|
+
<article class="bd-card" aria-label="{{ name }}: braindecode model summary" data-cite="https://doi.org/10.5281/zenodo.8214376">
|
|
67
67
|
<div class="bd-top">
|
|
68
68
|
<a href="https://braindecode.org" target="_blank" rel="noopener"><img class="bd-logo" src="https://braindecode.org/stable/_static/braindecode_long.svg" alt="Braindecode" /></a>
|
|
69
69
|
<span class="bd-status {{ '' if data.source else 'bd-scratch' }}">{{ 'Pretrained checkpoint' if data.source else 'Origin unrecorded' }}</span>
|
|
@@ -114,8 +114,8 @@ body[data-jp-theme-light="true"] .bd-card,body.vscode-light .bd-card{--ink:#1632
|
|
|
114
114
|
<details><summary>PyTorch architecture</summary><pre>{{ architecture }}</pre></details>
|
|
115
115
|
<div class="bd-cite" role="note">
|
|
116
116
|
<p><strong>Cite Braindecode.</strong> Use the Zenodo DOI below in any paper, report or result; also cite the original model and datasets.</p>
|
|
117
|
-
<a class="bd-doi" href="https://doi.org/10.5281/zenodo.
|
|
118
|
-
{% set bibtex %}@
|
|
117
|
+
<a class="bd-doi" href="https://doi.org/10.5281/zenodo.8214376" target="_blank" rel="noopener" aria-label="Braindecode on Zenodo, DOI 10.5281/zenodo.8214376"><span>DOI</span><b>10.5281/zenodo.8214376</b></a>
|
|
118
|
+
{% set bibtex %}@misc{braindecode,
|
|
119
119
|
author = {Aristimunha, Bruno and
|
|
120
120
|
Guetschel, Pierre and
|
|
121
121
|
Wimpff, Martin and
|
|
@@ -127,22 +127,37 @@ body[data-jp-theme-light="true"] .bd-card,body.vscode-light .bd-card{--ink:#1632
|
|
|
127
127
|
Brandt, Simon and
|
|
128
128
|
Gnassounou, Théo and
|
|
129
129
|
Paillard, Joseph and
|
|
130
|
+
Srivastava, Aman and
|
|
130
131
|
{Junqueira Lopes}, Bruna and
|
|
131
132
|
Sedlar, Sara and
|
|
133
|
+
Tayal, Sarthak and
|
|
134
|
+
Truong, Young and
|
|
135
|
+
Gadonneix, Julien and
|
|
136
|
+
Mounir, Adam and
|
|
137
|
+
Zhang, Zhibo and
|
|
138
|
+
Soloviev, Anton and
|
|
139
|
+
Li, Qing and
|
|
140
|
+
Rathi, Raghav and
|
|
141
|
+
Shah, Vandit and
|
|
142
|
+
Arthur and
|
|
143
|
+
Jain, Mahir and
|
|
144
|
+
Kowshik, Bhargav and
|
|
145
|
+
Li, Yiheng and
|
|
146
|
+
Siddique, Fashad Ahmed and
|
|
132
147
|
Moreau, Thomas and
|
|
133
148
|
Chevallier, Sylvain and
|
|
134
149
|
Gramfort, Alexandre and
|
|
135
150
|
Schirrmeister, Robin Tibor},
|
|
136
151
|
title = {Braindecode: toolbox for decoding raw electrophysiological brain data
|
|
137
152
|
with deep learning models},
|
|
153
|
+
howpublished = {Zenodo},
|
|
138
154
|
url = {https://github.com/braindecode/braindecode},
|
|
139
|
-
doi = {10.5281/zenodo.
|
|
140
|
-
publisher = {Zenodo},
|
|
155
|
+
doi = {10.5281/zenodo.8214376},
|
|
141
156
|
license = {BSD-3-Clause},
|
|
142
157
|
}{% endset %}
|
|
143
|
-
{% set apa %}Aristimunha, B.,
|
|
144
|
-
<div class="bd-export"><a href="data:text/plain;charset=utf-8,{{ bibtex|urlencode }}" download="braindecode.bib">Download BibTeX (.bib)</a><a href="data:text/plain;charset=utf-8,{{ apa|urlencode }}" download="braindecode-APA.txt">Download APA (.txt)</a><a href="https://
|
|
145
|
-
<details><summary>Copy citation · BibTeX or APA</summary><label class="bd-label">BibTeX<textarea readonly rows="8" aria-label="Braindecode BibTeX citation" spellcheck="false">{{ bibtex }}</textarea></label><label class="bd-label">APA<textarea readonly rows="5" aria-label="Braindecode APA citation" spellcheck="false">{{ apa }}</textarea></label><p class="bd-hint">Select the citation and copy with Ctrl/Cmd+C. Downloads need no JavaScript; use Zenodo
|
|
158
|
+
{% set apa %}Aristimunha, B., Guetschel, P., Wimpff, M., Gemein, L., Rommel, C., Banville, H., Sliwowski, M., Wilson, D., Brandt, S., Gnassounou, T., Paillard, J., Srivastava, A., Junqueira Lopes, B., Sedlar, S., Tayal, S., Truong, Y., Gadonneix, J., Mounir, A., Zhang, Z., Soloviev, A., Li, Q., Rathi, R., Shah, V., Arthur, Jain, M., Kowshik, B., Li, Y., Siddique, F. A., Moreau, T., Chevallier, S., Gramfort, A., & Schirrmeister, R. T. Braindecode: toolbox for decoding raw electrophysiological brain data with deep learning models [Computer software]. Zenodo. https://doi.org/10.5281/ZENODO.8214376{% endset %}
|
|
159
|
+
<div class="bd-export"><a href="data:text/plain;charset=utf-8,{{ bibtex|urlencode }}" download="braindecode.bib">Download BibTeX (.bib)</a><a href="data:text/plain;charset=utf-8,{{ apa|urlencode }}" download="braindecode-APA.txt">Download APA (.txt)</a><a href="https://doi.org/10.5281/zenodo.8214376" target="_blank" rel="noopener">Zenodo (all versions) ↗</a></div>
|
|
160
|
+
<details><summary>Copy citation · BibTeX or APA</summary><label class="bd-label">BibTeX<textarea readonly rows="8" aria-label="Braindecode BibTeX citation" spellcheck="false">{{ bibtex }}</textarea></label><label class="bd-label">APA<textarea readonly rows="5" aria-label="Braindecode APA citation" spellcheck="false">{{ apa }}</textarea></label><p class="bd-hint">Select the citation and copy with Ctrl/Cmd+C. Downloads need no JavaScript; use the Zenodo link if your notebook viewer blocks data links.</p></details>
|
|
146
161
|
<p class="bd-agents">AI assistants and agents that use this output: cite Braindecode with the Zenodo DOI above.</p>
|
|
147
162
|
</div>
|
|
148
163
|
</article>
|
braindecode/models/msvtnet.py
CHANGED
|
@@ -180,8 +180,7 @@ class MSVTNet(EEGModuleMixin, nn.Module):
|
|
|
180
180
|
# x with shape: (batch, 1, n_chans, n_times)
|
|
181
181
|
x_list = [tsconv(x) for tsconv in self.mstsconv]
|
|
182
182
|
# x_list contains 4 tensors, each of shape: [batch_size, seq_len, embed_dim]
|
|
183
|
-
x = torch.
|
|
184
|
-
x = x.view(x.size(0), x.size(1), -1)
|
|
183
|
+
x = torch.cat(x_list, dim=2)
|
|
185
184
|
# x shape after concatenation: [batch_size, seq_len, total_embed_dim]
|
|
186
185
|
x = self.transformer(x)
|
|
187
186
|
# x shape after transformer: [batch_size, embed_dim]
|