--- license: bsd-3-clause library_name: braindecode pipeline_tag: feature-extraction tags: - eeg - biosignal - pytorch - neuroscience - braindecode - convolutional --- # FBMSNet FBMSNet from Liu et al (2022) . > **Architecture-only repository.** This repo documents the > `braindecode.models.FBMSNet` class. **No pretrained weights are > distributed here** — instantiate the model and train it on your own > data, or fine-tune from a published foundation-model checkpoint > separately. ## Quick start ```bash pip install braindecode ``` ```python from braindecode.models import FBMSNet model = FBMSNet( n_chans=22, sfreq=250, input_window_seconds=4.0, n_outputs=4, ) ``` The signal-shape arguments above are example defaults — adjust them to match your recording. ## Documentation - Full API reference (parameters, references, architecture figure): - Interactive browser with live instantiation: - Source on GitHub: ## Architecture description The block below is the rendered class docstring (parameters, references, architecture figure where available).

FBMSNet from Liu et al (2022) [fbmsnet]_.

ConvolutionFilterbank .. figure:: https://raw.githubusercontent.com/Want2Vanish/FBMSNet/refs/heads/main/FBMSNet.png :align: center :alt: FBMSNet Architecture 0. **FilterBank Layer**: Applying filterbank to transform the input. 1. **Temporal Convolution Block**: Utilizes mixed depthwise convolution (MixConv) to extract multiscale temporal features from multiview EEG representations. The input is split into groups corresponding to different views each convolved with kernels of varying sizes. Kernel sizes are set relative to the EEG sampling rate, with ratio coefficients [0.5, 0.25, 0.125, 0.0625], dividing the input into four groups. 2. **Spatial Convolution Block**: Applies depthwise convolution with a kernel size of (n_chans, 1) to span all EEG channels, effectively learning spatial filters. This is followed by batch normalization and the Swish activation function. A maximum norm constraint of 2 is imposed on the convolution weights to regularize the model. 3. **Temporal Log-Variance Block**: Computes the log-variance. 4. **Classification Layer**: A fully connected with weight constraint. Notes ----- This implementation is not guaranteed to be correct and has not been checked by the original authors; it has only been reimplemented from the paper description and source code [fbmsnetcode]_. There is an extra layer here to compute the filterbank during bash time and not on data time. This avoids data-leak, and allows the model to follow the braindecode convention. Parameters ---------- n_bands : int, default=9 Number of input channels (e.g., number of frequency bands). n_filters_spat : int, default=36 Number of output channels from the MixedConv2d layer. temporal_layer : str, default='LogVarLayer' Temporal aggregation layer to use. n_dim: int, default=3 Dimension of the temporal reduction layer. stride_factor : int, default=4 Stride factor for temporal segmentation. dilatability : int, default=8 Expansion factor for the spatial convolution block. activation : nn.Module, default=nn.SiLU Activation function class to apply. kernels_weights : Sequence[int], default=(15, 31, 63, 125) Kernel sizes for the MixedConv2d layer. cnn_max_norm : float, default=2 Maximum norm constraint for the convolutional layers. linear_max_norm : float, default=0.5 Maximum norm constraint for the linear layers. filter_parameters : dict, default=None Dictionary of parameters to use for the FilterBankLayer. If None, a default Chebyshev Type II filter with transition bandwidth of 2 Hz and stop-band ripple of 30 dB will be used. verbose: bool, default False Verbose parameter to create the filter using mne. References ---------- .. [fbmsnet] Liu, K., Yang, M., Yu, Z., Wang, G., & Wu, W. (2022). FBMSNet: A filter-bank multi-scale convolutional neural network for EEG-based motor imagery decoding. IEEE Transactions on Biomedical Engineering, 70(2), 436-445. .. [fbmsnetcode] Liu, K., Yang, M., Yu, Z., Wang, G., & Wu, W. (2022). FBMSNet: A filter-bank multi-scale convolutional neural network for EEG-based motor imagery decoding. https://github.com/Want2Vanish/FBMSNet .. rubric:: Hugging Face Hub integration When the optional ``huggingface_hub`` package is installed, all models automatically gain the ability to be pushed to and loaded from the Hugging Face Hub. Install with:: pip install braindecode[hub] **Pushing a model to the Hub:** .. code:: from braindecode.models import FBMSNet # Train your model model = FBMSNet(n_chans=22, n_outputs=4, n_times=1000) # ... training code ... # Push to the Hub model.push_to_hub( repo_id="username/my-fbmsnet-model", commit_message="Initial model upload", ) **Loading a model from the Hub:** .. code:: from braindecode.models import FBMSNet # Load pretrained model model = FBMSNet.from_pretrained("username/my-fbmsnet-model") # Load with a different number of outputs (head is rebuilt automatically) model = FBMSNet.from_pretrained("username/my-fbmsnet-model", n_outputs=4) **Extracting features and replacing the head:** .. code:: import torch x = torch.randn(1, model.n_chans, model.n_times) # Extract encoder features (consistent dict across all models) out = model(x, return_features=True) features = out["features"] # Replace the classification head model.reset_head(n_outputs=10) **Saving and restoring full configuration:** .. code:: import json config = model.get_config() # all __init__ params with open("config.json", "w") as f: json.dump(config, f) model2 = FBMSNet.from_config(config) # reconstruct (no weights) All model parameters (both EEG-specific and model-specific such as dropout rates, activation functions, number of filters) are automatically saved to the Hub and restored when loading. See :ref:`load-pretrained-models` for a complete tutorial.
## Citation Please cite both the original paper for this architecture (see the *References* section above) and braindecode: ```bibtex @article{aristimunha2025braindecode, title = {Braindecode: a deep learning library for raw electrophysiological data}, author = {Aristimunha, Bruno and others}, journal = {Zenodo}, year = {2025}, doi = {10.5281/zenodo.17699192}, } ``` ## License BSD-3-Clause for the model code (matching braindecode). Pretraining-derived weights, if you fine-tune from a checkpoint, inherit the licence of that checkpoint and its training corpus.