bruAristimunha commited on
Commit
a5b33b2
·
verified ·
1 Parent(s): 40f62cd

Add architecture-only model card

Browse files
Files changed (1) hide show
  1. README.md +219 -0
README.md ADDED
@@ -0,0 +1,219 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ ---
13
+
14
+ # FBMSNet
15
+
16
+ FBMSNet from Liu et al (2022) .
17
+
18
+ > **Architecture-only repository.** This repo documents the
19
+ > `braindecode.models.FBMSNet` class. **No pretrained weights are
20
+ > distributed here** — instantiate the model and train it on your own
21
+ > data, or fine-tune from a published foundation-model checkpoint
22
+ > separately.
23
+
24
+ ## Quick start
25
+
26
+ ```bash
27
+ pip install braindecode
28
+ ```
29
+
30
+ ```python
31
+ from braindecode.models import FBMSNet
32
+
33
+ model = FBMSNet(
34
+ n_chans=22,
35
+ sfreq=250,
36
+ input_window_seconds=4.0,
37
+ n_outputs=4,
38
+ )
39
+ ```
40
+
41
+ The signal-shape arguments above are example defaults — adjust them
42
+ to match your recording.
43
+
44
+ ## Documentation
45
+
46
+ - Full API reference (parameters, references, architecture figure):
47
+ <https://braindecode.org/stable/generated/braindecode.models.FBMSNet.html>
48
+ - Interactive browser with live instantiation:
49
+ <https://huggingface.co/spaces/braindecode/model-explorer>
50
+ - Source on GitHub: <https://github.com/braindecode/braindecode/blob/master/braindecode/models/fbmsnet.py#L19>
51
+
52
+ ## Architecture description
53
+
54
+ The block below is the rendered class docstring (parameters,
55
+ references, architecture figure where available).
56
+
57
+ <div class='bd-doc'><main>
58
+ <p>FBMSNet from Liu et al (2022) [fbmsnet]_.</p>
59
+ <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:#0072B2;color:white;font-size:11px;font-weight:600;margin-right:4px;">Filterbank</span>
60
+
61
+
62
+
63
+ .. figure:: https://raw.githubusercontent.com/Want2Vanish/FBMSNet/refs/heads/main/FBMSNet.png
64
+ :align: center
65
+ :alt: FBMSNet Architecture
66
+
67
+ 0. **FilterBank Layer**: Applying filterbank to transform the input.
68
+
69
+ 1. **Temporal Convolution Block**: Utilizes mixed depthwise convolution
70
+ (MixConv) to extract multiscale temporal features from multiview EEG
71
+ representations. The input is split into groups corresponding to different
72
+ views each convolved with kernels of varying sizes.
73
+ Kernel sizes are set relative to the EEG
74
+ sampling rate, with ratio coefficients [0.5, 0.25, 0.125, 0.0625],
75
+ dividing the input into four groups.
76
+
77
+ 2. **Spatial Convolution Block**: Applies depthwise convolution with a kernel
78
+ size of (n_chans, 1) to span all EEG channels, effectively learning spatial
79
+ filters. This is followed by batch normalization and the Swish activation
80
+ function. A maximum norm constraint of 2 is imposed on the convolution
81
+ weights to regularize the model.
82
+
83
+ 3. **Temporal Log-Variance Block**: Computes the log-variance.
84
+
85
+ 4. **Classification Layer**: A fully connected with weight constraint.
86
+
87
+ Notes
88
+ -----
89
+ This implementation is not guaranteed to be correct and has not been checked
90
+ by the original authors; it has only been reimplemented from the paper
91
+ description and source code [fbmsnetcode]_. There is an extra layer here to
92
+ compute the filterbank during bash time and not on data time. This avoids
93
+ data-leak, and allows the model to follow the braindecode convention.
94
+
95
+ Parameters
96
+ ----------
97
+ n_bands : int, default=9
98
+ Number of input channels (e.g., number of frequency bands).
99
+ n_filters_spat : int, default=36
100
+ Number of output channels from the MixedConv2d layer.
101
+ temporal_layer : str, default='LogVarLayer'
102
+ Temporal aggregation layer to use.
103
+ n_dim: int, default=3
104
+ Dimension of the temporal reduction layer.
105
+ stride_factor : int, default=4
106
+ Stride factor for temporal segmentation.
107
+ dilatability : int, default=8
108
+ Expansion factor for the spatial convolution block.
109
+ activation : nn.Module, default=nn.SiLU
110
+ Activation function class to apply.
111
+ kernels_weights : Sequence[int], default=(15, 31, 63, 125)
112
+ Kernel sizes for the MixedConv2d layer.
113
+ cnn_max_norm : float, default=2
114
+ Maximum norm constraint for the convolutional layers.
115
+ linear_max_norm : float, default=0.5
116
+ Maximum norm constraint for the linear layers.
117
+ filter_parameters : dict, default=None
118
+ Dictionary of parameters to use for the FilterBankLayer.
119
+ If None, a default Chebyshev Type II filter with transition bandwidth of
120
+ 2 Hz and stop-band ripple of 30 dB will be used.
121
+ verbose: bool, default False
122
+ Verbose parameter to create the filter using mne.
123
+
124
+ References
125
+ ----------
126
+ .. [fbmsnet] Liu, K., Yang, M., Yu, Z., Wang, G., & Wu, W. (2022).
127
+ FBMSNet: A filter-bank multi-scale convolutional neural network for
128
+ EEG-based motor imagery decoding. IEEE Transactions on Biomedical
129
+ Engineering, 70(2), 436-445.
130
+ .. [fbmsnetcode] Liu, K., Yang, M., Yu, Z., Wang, G., & Wu, W. (2022).
131
+ FBMSNet: A filter-bank multi-scale convolutional neural network for
132
+ EEG-based motor imagery decoding.
133
+ https://github.com/Want2Vanish/FBMSNet
134
+
135
+ .. rubric:: Hugging Face Hub integration
136
+
137
+ When the optional ``huggingface_hub`` package is installed, all models
138
+ automatically gain the ability to be pushed to and loaded from the
139
+ Hugging Face Hub. Install with::
140
+
141
+ pip install braindecode[hub]
142
+
143
+ **Pushing a model to the Hub:**
144
+
145
+ .. code::
146
+ from braindecode.models import FBMSNet
147
+
148
+ # Train your model
149
+ model = FBMSNet(n_chans=22, n_outputs=4, n_times=1000)
150
+ # ... training code ...
151
+
152
+ # Push to the Hub
153
+ model.push_to_hub(
154
+ repo_id="username/my-fbmsnet-model",
155
+ commit_message="Initial model upload",
156
+ )
157
+
158
+ **Loading a model from the Hub:**
159
+
160
+ .. code::
161
+ from braindecode.models import FBMSNet
162
+
163
+ # Load pretrained model
164
+ model = FBMSNet.from_pretrained("username/my-fbmsnet-model")
165
+
166
+ # Load with a different number of outputs (head is rebuilt automatically)
167
+ model = FBMSNet.from_pretrained("username/my-fbmsnet-model", n_outputs=4)
168
+
169
+ **Extracting features and replacing the head:**
170
+
171
+ .. code::
172
+ import torch
173
+
174
+ x = torch.randn(1, model.n_chans, model.n_times)
175
+ # Extract encoder features (consistent dict across all models)
176
+ out = model(x, return_features=True)
177
+ features = out["features"]
178
+
179
+ # Replace the classification head
180
+ model.reset_head(n_outputs=10)
181
+
182
+ **Saving and restoring full configuration:**
183
+
184
+ .. code::
185
+ import json
186
+
187
+ config = model.get_config() # all __init__ params
188
+ with open("config.json", "w") as f:
189
+ json.dump(config, f)
190
+
191
+ model2 = FBMSNet.from_config(config) # reconstruct (no weights)
192
+
193
+ All model parameters (both EEG-specific and model-specific such as
194
+ dropout rates, activation functions, number of filters) are automatically
195
+ saved to the Hub and restored when loading.
196
+
197
+ See :ref:`load-pretrained-models` for a complete tutorial.</main>
198
+ </div>
199
+
200
+ ## Citation
201
+
202
+ Please cite both the original paper for this architecture (see the
203
+ *References* section above) and braindecode:
204
+
205
+ ```bibtex
206
+ @article{aristimunha2025braindecode,
207
+ title = {Braindecode: a deep learning library for raw electrophysiological data},
208
+ author = {Aristimunha, Bruno and others},
209
+ journal = {Zenodo},
210
+ year = {2025},
211
+ doi = {10.5281/zenodo.17699192},
212
+ }
213
+ ```
214
+
215
+ ## License
216
+
217
+ BSD-3-Clause for the model code (matching braindecode).
218
+ Pretraining-derived weights, if you fine-tune from a checkpoint,
219
+ inherit the licence of that checkpoint and its training corpus.