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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: bsd-3-clause
|
| 3 |
+
library_name: braindecode
|
| 4 |
+
pipeline_tag: feature-extraction
|
| 5 |
+
tags:
|
| 6 |
+
- eeg
|
| 7 |
+
- biosignal
|
| 8 |
+
- pytorch
|
| 9 |
+
- neuroscience
|
| 10 |
+
- braindecode
|
| 11 |
+
- convolutional
|
| 12 |
+
- transformer
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
# MSVTNet
|
| 16 |
+
|
| 17 |
+
MSVTNet model from Liu K et al (2024) from .
|
| 18 |
+
|
| 19 |
+
> **Architecture-only repository.** This repo documents the
|
| 20 |
+
> `braindecode.models.MSVTNet` class. **No pretrained weights are
|
| 21 |
+
> distributed here** — instantiate the model and train it on your own
|
| 22 |
+
> data, or fine-tune from a published foundation-model checkpoint
|
| 23 |
+
> separately.
|
| 24 |
+
|
| 25 |
+
## Quick start
|
| 26 |
+
|
| 27 |
+
```bash
|
| 28 |
+
pip install braindecode
|
| 29 |
+
```
|
| 30 |
+
|
| 31 |
+
```python
|
| 32 |
+
from braindecode.models import MSVTNet
|
| 33 |
+
|
| 34 |
+
model = MSVTNet(
|
| 35 |
+
n_chans=22,
|
| 36 |
+
sfreq=250,
|
| 37 |
+
input_window_seconds=4.0,
|
| 38 |
+
n_outputs=4,
|
| 39 |
+
)
|
| 40 |
+
```
|
| 41 |
+
|
| 42 |
+
The signal-shape arguments above are example defaults — adjust them
|
| 43 |
+
to match your recording.
|
| 44 |
+
|
| 45 |
+
## Documentation
|
| 46 |
+
|
| 47 |
+
- Full API reference (parameters, references, architecture figure):
|
| 48 |
+
<https://braindecode.org/stable/generated/braindecode.models.MSVTNet.html>
|
| 49 |
+
- Interactive browser with live instantiation:
|
| 50 |
+
<https://huggingface.co/spaces/braindecode/model-explorer>
|
| 51 |
+
- Source on GitHub: <https://github.com/braindecode/braindecode/blob/master/braindecode/models/msvtnet.py#L13>
|
| 52 |
+
|
| 53 |
+
## Architecture description
|
| 54 |
+
|
| 55 |
+
The block below is the rendered class docstring (parameters,
|
| 56 |
+
references, architecture figure where available).
|
| 57 |
+
|
| 58 |
+
<div class='bd-doc'><main>
|
| 59 |
+
<p>MSVTNet model from Liu K et al (2024) from [msvt2024]_.</p>
|
| 60 |
+
<span style="display:inline-block;padding:2px 8px;border-radius:4px;background:#5cb85c;color:white;font-size:11px;font-weight:600;margin-right:4px;">Convolution</span><span style="display:inline-block;padding:2px 8px;border-radius:4px;background:#6c757d;color:white;font-size:11px;font-weight:600;margin-right:4px;">Recurrent</span><span style="display:inline-block;padding:2px 8px;border-radius:4px;background:#56B4E9;color:white;font-size:11px;font-weight:600;margin-right:4px;">Attention/Transformer</span>
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
This model implements a multi-scale convolutional transformer network
|
| 65 |
+
for EEG signal classification, as described in [msvt2024]_.
|
| 66 |
+
|
| 67 |
+
.. figure:: https://raw.githubusercontent.com/SheepTAO/MSVTNet/refs/heads/main/MSVTNet_Arch.png
|
| 68 |
+
:align: center
|
| 69 |
+
:alt: MSVTNet Architecture
|
| 70 |
+
|
| 71 |
+
Parameters
|
| 72 |
+
----------
|
| 73 |
+
n_filters_list : list[int], optional
|
| 74 |
+
List of filter numbers for each TSConv block, by default (9, 9, 9, 9).
|
| 75 |
+
conv1_kernels_size : list[int], optional
|
| 76 |
+
List of kernel sizes for the first convolution in each TSConv block,
|
| 77 |
+
by default (15, 31, 63, 125).
|
| 78 |
+
conv2_kernel_size : int, optional
|
| 79 |
+
Kernel size for the second convolution in TSConv blocks, by default 15.
|
| 80 |
+
depth_multiplier : int, optional
|
| 81 |
+
Depth multiplier for depthwise convolution, by default 2.
|
| 82 |
+
pool1_size : int, optional
|
| 83 |
+
Pooling size for the first pooling layer in TSConv blocks, by default 8.
|
| 84 |
+
pool2_size : int, optional
|
| 85 |
+
Pooling size for the second pooling layer in TSConv blocks, by default 7.
|
| 86 |
+
drop_prob : float, optional
|
| 87 |
+
Dropout probability for convolutional layers, by default 0.3.
|
| 88 |
+
num_heads : int, optional
|
| 89 |
+
Number of attention heads in the transformer encoder, by default 8.
|
| 90 |
+
ffn_expansion_factor : float, optional
|
| 91 |
+
Ratio to compute feedforward dimension in the transformer, by default 1.
|
| 92 |
+
att_drop_prob : float, optional
|
| 93 |
+
Dropout probability for the transformer, by default 0.5.
|
| 94 |
+
num_layers : int, optional
|
| 95 |
+
Number of transformer encoder layers, by default 2.
|
| 96 |
+
activation : Type[nn.Module], optional
|
| 97 |
+
Activation function class to use, by default nn.ELU.
|
| 98 |
+
return_features : bool, optional
|
| 99 |
+
Whether to return predictions from branch classifiers, by default False.
|
| 100 |
+
|
| 101 |
+
Notes
|
| 102 |
+
-----
|
| 103 |
+
This implementation is not guaranteed to be correct, has not been checked
|
| 104 |
+
by original authors, only reimplemented based on the original code [msvt2024code]_.
|
| 105 |
+
|
| 106 |
+
References
|
| 107 |
+
----------
|
| 108 |
+
.. [msvt2024] Liu, K., et al. (2024). MSVTNet: Multi-Scale Vision
|
| 109 |
+
Transformer Neural Network for EEG-Based Motor Imagery Decoding.
|
| 110 |
+
IEEE Journal of Biomedical an Health Informatics.
|
| 111 |
+
.. [msvt2024code] Liu, K., et al. (2024). MSVTNet: Multi-Scale Vision
|
| 112 |
+
Transformer Neural Network for EEG-Based Motor Imagery Decoding.
|
| 113 |
+
Source Code: https://github.com/SheepTAO/MSVTNet
|
| 114 |
+
|
| 115 |
+
.. rubric:: Hugging Face Hub integration
|
| 116 |
+
|
| 117 |
+
When the optional ``huggingface_hub`` package is installed, all models
|
| 118 |
+
automatically gain the ability to be pushed to and loaded from the
|
| 119 |
+
Hugging Face Hub. Install with::
|
| 120 |
+
|
| 121 |
+
pip install braindecode[hub]
|
| 122 |
+
|
| 123 |
+
**Pushing a model to the Hub:**
|
| 124 |
+
|
| 125 |
+
.. code::
|
| 126 |
+
from braindecode.models import MSVTNet
|
| 127 |
+
|
| 128 |
+
# Train your model
|
| 129 |
+
model = MSVTNet(n_chans=22, n_outputs=4, n_times=1000)
|
| 130 |
+
# ... training code ...
|
| 131 |
+
|
| 132 |
+
# Push to the Hub
|
| 133 |
+
model.push_to_hub(
|
| 134 |
+
repo_id="username/my-msvtnet-model",
|
| 135 |
+
commit_message="Initial model upload",
|
| 136 |
+
)
|
| 137 |
+
|
| 138 |
+
**Loading a model from the Hub:**
|
| 139 |
+
|
| 140 |
+
.. code::
|
| 141 |
+
from braindecode.models import MSVTNet
|
| 142 |
+
|
| 143 |
+
# Load pretrained model
|
| 144 |
+
model = MSVTNet.from_pretrained("username/my-msvtnet-model")
|
| 145 |
+
|
| 146 |
+
# Load with a different number of outputs (head is rebuilt automatically)
|
| 147 |
+
model = MSVTNet.from_pretrained("username/my-msvtnet-model", n_outputs=4)
|
| 148 |
+
|
| 149 |
+
**Extracting features and replacing the head:**
|
| 150 |
+
|
| 151 |
+
.. code::
|
| 152 |
+
import torch
|
| 153 |
+
|
| 154 |
+
x = torch.randn(1, model.n_chans, model.n_times)
|
| 155 |
+
# Extract encoder features (consistent dict across all models)
|
| 156 |
+
out = model(x, return_features=True)
|
| 157 |
+
features = out["features"]
|
| 158 |
+
|
| 159 |
+
# Replace the classification head
|
| 160 |
+
model.reset_head(n_outputs=10)
|
| 161 |
+
|
| 162 |
+
**Saving and restoring full configuration:**
|
| 163 |
+
|
| 164 |
+
.. code::
|
| 165 |
+
import json
|
| 166 |
+
|
| 167 |
+
config = model.get_config() # all __init__ params
|
| 168 |
+
with open("config.json", "w") as f:
|
| 169 |
+
json.dump(config, f)
|
| 170 |
+
|
| 171 |
+
model2 = MSVTNet.from_config(config) # reconstruct (no weights)
|
| 172 |
+
|
| 173 |
+
All model parameters (both EEG-specific and model-specific such as
|
| 174 |
+
dropout rates, activation functions, number of filters) are automatically
|
| 175 |
+
saved to the Hub and restored when loading.
|
| 176 |
+
|
| 177 |
+
See :ref:`load-pretrained-models` for a complete tutorial.</main>
|
| 178 |
+
</div>
|
| 179 |
+
|
| 180 |
+
## Citation
|
| 181 |
+
|
| 182 |
+
Please cite both the original paper for this architecture (see the
|
| 183 |
+
*References* section above) and braindecode:
|
| 184 |
+
|
| 185 |
+
```bibtex
|
| 186 |
+
@article{aristimunha2025braindecode,
|
| 187 |
+
title = {Braindecode: a deep learning library for raw electrophysiological data},
|
| 188 |
+
author = {Aristimunha, Bruno and others},
|
| 189 |
+
journal = {Zenodo},
|
| 190 |
+
year = {2025},
|
| 191 |
+
doi = {10.5281/zenodo.17699192},
|
| 192 |
+
}
|
| 193 |
+
```
|
| 194 |
+
|
| 195 |
+
## License
|
| 196 |
+
|
| 197 |
+
BSD-3-Clause for the model code (matching braindecode).
|
| 198 |
+
Pretraining-derived weights, if you fine-tune from a checkpoint,
|
| 199 |
+
inherit the licence of that checkpoint and its training corpus.
|