Replace with clean markdown card
Browse files
README.md
CHANGED
|
@@ -14,13 +14,12 @@ tags:
|
|
| 14 |
|
| 15 |
# MSVTNet
|
| 16 |
|
| 17 |
-
MSVTNet model from Liu K et al (2024) from .
|
| 18 |
|
| 19 |
-
> **Architecture-only repository.**
|
| 20 |
> `braindecode.models.MSVTNet` class. **No pretrained weights are
|
| 21 |
-
> distributed here**
|
| 22 |
-
> data
|
| 23 |
-
> separately.
|
| 24 |
|
| 25 |
## Quick start
|
| 26 |
|
|
@@ -39,148 +38,49 @@ model = MSVTNet(
|
|
| 39 |
)
|
| 40 |
```
|
| 41 |
|
| 42 |
-
The signal-shape arguments above are
|
| 43 |
-
|
| 44 |
|
| 45 |
## Documentation
|
| 46 |
-
|
| 47 |
-
-
|
| 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 |
-
|
| 133 |
-
model.push_to_hub(
|
| 134 |
-
repo_id="username/my-msvtnet-model",
|
| 135 |
-
commit_message="Initial model upload",
|
| 136 |
-
)
|
| 137 |
|
| 138 |
-
|
| 139 |
|
| 140 |
-
.. code::
|
| 141 |
-
from braindecode.models import MSVTNet
|
| 142 |
|
| 143 |
-
|
| 144 |
-
model = MSVTNet.from_pretrained("username/my-msvtnet-model")
|
| 145 |
|
| 146 |
-
|
| 147 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
|
| 149 |
-
**Extracting features and replacing the head:**
|
| 150 |
|
| 151 |
-
|
| 152 |
-
import torch
|
| 153 |
|
| 154 |
-
|
| 155 |
-
|
| 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 |
-
|
| 183 |
-
*References* section above) and braindecode:
|
| 184 |
|
| 185 |
```bibtex
|
| 186 |
@article{aristimunha2025braindecode,
|
|
|
|
| 14 |
|
| 15 |
# MSVTNet
|
| 16 |
|
| 17 |
+
MSVTNet model from Liu K et al (2024) from [msvt2024].
|
| 18 |
|
| 19 |
+
> **Architecture-only repository.** 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.
|
|
|
|
| 23 |
|
| 24 |
## Quick start
|
| 25 |
|
|
|
|
| 38 |
)
|
| 39 |
```
|
| 40 |
|
| 41 |
+
The signal-shape arguments above are illustrative defaults — adjust to
|
| 42 |
+
match your recording.
|
| 43 |
|
| 44 |
## Documentation
|
| 45 |
+
- Full API reference: <https://braindecode.org/stable/generated/braindecode.models.MSVTNet.html>
|
| 46 |
+
- Interactive browser (live instantiation, parameter counts):
|
|
|
|
|
|
|
| 47 |
<https://huggingface.co/spaces/braindecode/model-explorer>
|
| 48 |
- Source on GitHub: <https://github.com/braindecode/braindecode/blob/master/braindecode/models/msvtnet.py#L13>
|
| 49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
+
## Architecture
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
+

|
| 54 |
|
|
|
|
|
|
|
| 55 |
|
| 56 |
+
## Parameters
|
|
|
|
| 57 |
|
| 58 |
+
| Parameter | Type | Description |
|
| 59 |
+
|---|---|---|
|
| 60 |
+
| `n_filters_list` | list[int], optional | List of filter numbers for each TSConv block, by default (9, 9, 9, 9). |
|
| 61 |
+
| `conv1_kernels_size` | list[int], optional | List of kernel sizes for the first convolution in each TSConv block, by default (15, 31, 63, 125). |
|
| 62 |
+
| `conv2_kernel_size` | int, optional | Kernel size for the second convolution in TSConv blocks, by default 15. |
|
| 63 |
+
| `depth_multiplier` | int, optional | Depth multiplier for depthwise convolution, by default 2. |
|
| 64 |
+
| `pool1_size` | int, optional | Pooling size for the first pooling layer in TSConv blocks, by default 8. |
|
| 65 |
+
| `pool2_size` | int, optional | Pooling size for the second pooling layer in TSConv blocks, by default 7. |
|
| 66 |
+
| `drop_prob` | float, optional | Dropout probability for convolutional layers, by default 0.3. |
|
| 67 |
+
| `num_heads` | int, optional | Number of attention heads in the transformer encoder, by default 8. |
|
| 68 |
+
| `ffn_expansion_factor` | float, optional | Ratio to compute feedforward dimension in the transformer, by default 1. |
|
| 69 |
+
| `att_drop_prob` | float, optional | Dropout probability for the transformer, by default 0.5. |
|
| 70 |
+
| `num_layers` | int, optional | Number of transformer encoder layers, by default 2. |
|
| 71 |
+
| `activation` | Type[nn.Module], optional | Activation function class to use, by default nn.ELU. |
|
| 72 |
+
| `return_features` | bool, optional | Whether to return predictions from branch classifiers, by default False. |
|
| 73 |
|
|
|
|
| 74 |
|
| 75 |
+
## References
|
|
|
|
| 76 |
|
| 77 |
+
1. Liu, K., et al. (2024). MSVTNet: Multi-Scale Vision Transformer Neural Network for EEG-Based Motor Imagery Decoding. IEEE Journal of Biomedical an Health Informatics.
|
| 78 |
+
2. Liu, K., et al. (2024). MSVTNet: Multi-Scale Vision Transformer Neural Network for EEG-Based Motor Imagery Decoding. Source Code: https://github.com/SheepTAO/MSVTNet
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
## Citation
|
| 82 |
|
| 83 |
+
Cite the original architecture paper (see *References* above) and braindecode:
|
|
|
|
| 84 |
|
| 85 |
```bibtex
|
| 86 |
@article{aristimunha2025braindecode,
|