bruAristimunha commited on
Commit
244e720
·
verified ·
1 Parent(s): c18c388

Add architecture-only model card

Browse files
Files changed (1) hide show
  1. README.md +190 -0
README.md ADDED
@@ -0,0 +1,190 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ - sleep-staging
13
+ ---
14
+
15
+ # SleepStagerBlanco2020
16
+
17
+ Sleep staging architecture from Blanco et al (2020) from
18
+
19
+ > **Architecture-only repository.** This repo documents the
20
+ > `braindecode.models.SleepStagerBlanco2020` 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 SleepStagerBlanco2020
33
+
34
+ model = SleepStagerBlanco2020(
35
+ n_chans=2,
36
+ sfreq=100,
37
+ input_window_seconds=30.0,
38
+ n_outputs=5,
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.SleepStagerBlanco2020.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/sleep_stager_blanco_2020.py#L11>
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>Sleep staging architecture from Blanco et al (2020) from [Blanco2020]_</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>
61
+
62
+
63
+
64
+ .. figure:: https://media.springernature.com/full/springer-static/image/art%3A10.1007%2Fs00500-019-04174-1/MediaObjects/500_2019_4174_Fig2_HTML.png
65
+ :align: center
66
+ :alt: SleepStagerBlanco2020 Architecture
67
+
68
+ Convolutional neural network for sleep staging described in [Blanco2020]_.
69
+ A series of seven convolutional layers with kernel sizes running down from 7 to 3,
70
+ in an attempt to extract more general features at the beginning, while more specific
71
+ and complex features were extracted in the final stages.
72
+
73
+ Parameters
74
+ ----------
75
+ n_conv_chans : int
76
+ Number of convolutional channels. Set to 20 in [Blanco2020]_.
77
+ n_groups : int
78
+ Number of groups for the convolution. Set to 2 in [Blanco2020]_ for 2 Channel EEG.
79
+ controls the connections between inputs and outputs. n_channels and n_conv_chans must be
80
+ divisible by n_groups.
81
+ drop_prob : float
82
+ Dropout rate before the output dense layer.
83
+ apply_batch_norm : bool
84
+ If True, apply batch normalization after both temporal convolutional
85
+ layers.
86
+ return_feats : bool
87
+ If True, return the features, i.e. the output of the feature extractor
88
+ (before the final linear layer). If False, pass the features through
89
+ the final linear layer.
90
+ n_channels : int
91
+ Alias for `n_chans`.
92
+ n_classes : int
93
+ Alias for `n_outputs`.
94
+ input_size_s : float
95
+ Alias for `input_window_seconds`.
96
+ activation: nn.Module, default=nn.ReLU
97
+ Activation function class to apply. Should be a PyTorch activation
98
+ module class like ``nn.ReLU`` or ``nn.ELU``. Default is ``nn.ReLU``.
99
+
100
+ References
101
+ ----------
102
+ .. [Blanco2020] Fernandez-Blanco, E., Rivero, D. & Pazos, A. Convolutional
103
+ neural networks for sleep stage scoring on a two-channel EEG signal.
104
+ Soft Comput 24, 4067–4079 (2020). https://doi.org/10.1007/s00500-019-04174-1
105
+
106
+ .. rubric:: Hugging Face Hub integration
107
+
108
+ When the optional ``huggingface_hub`` package is installed, all models
109
+ automatically gain the ability to be pushed to and loaded from the
110
+ Hugging Face Hub. Install with::
111
+
112
+ pip install braindecode[hub]
113
+
114
+ **Pushing a model to the Hub:**
115
+
116
+ .. code::
117
+ from braindecode.models import SleepStagerBlanco2020
118
+
119
+ # Train your model
120
+ model = SleepStagerBlanco2020(n_chans=22, n_outputs=4, n_times=1000)
121
+ # ... training code ...
122
+
123
+ # Push to the Hub
124
+ model.push_to_hub(
125
+ repo_id="username/my-sleepstagerblanco2020-model",
126
+ commit_message="Initial model upload",
127
+ )
128
+
129
+ **Loading a model from the Hub:**
130
+
131
+ .. code::
132
+ from braindecode.models import SleepStagerBlanco2020
133
+
134
+ # Load pretrained model
135
+ model = SleepStagerBlanco2020.from_pretrained("username/my-sleepstagerblanco2020-model")
136
+
137
+ # Load with a different number of outputs (head is rebuilt automatically)
138
+ model = SleepStagerBlanco2020.from_pretrained("username/my-sleepstagerblanco2020-model", n_outputs=4)
139
+
140
+ **Extracting features and replacing the head:**
141
+
142
+ .. code::
143
+ import torch
144
+
145
+ x = torch.randn(1, model.n_chans, model.n_times)
146
+ # Extract encoder features (consistent dict across all models)
147
+ out = model(x, return_features=True)
148
+ features = out["features"]
149
+
150
+ # Replace the classification head
151
+ model.reset_head(n_outputs=10)
152
+
153
+ **Saving and restoring full configuration:**
154
+
155
+ .. code::
156
+ import json
157
+
158
+ config = model.get_config() # all __init__ params
159
+ with open("config.json", "w") as f:
160
+ json.dump(config, f)
161
+
162
+ model2 = SleepStagerBlanco2020.from_config(config) # reconstruct (no weights)
163
+
164
+ All model parameters (both EEG-specific and model-specific such as
165
+ dropout rates, activation functions, number of filters) are automatically
166
+ saved to the Hub and restored when loading.
167
+
168
+ See :ref:`load-pretrained-models` for a complete tutorial.</main>
169
+ </div>
170
+
171
+ ## Citation
172
+
173
+ Please cite both the original paper for this architecture (see the
174
+ *References* section above) and braindecode:
175
+
176
+ ```bibtex
177
+ @article{aristimunha2025braindecode,
178
+ title = {Braindecode: a deep learning library for raw electrophysiological data},
179
+ author = {Aristimunha, Bruno and others},
180
+ journal = {Zenodo},
181
+ year = {2025},
182
+ doi = {10.5281/zenodo.17699192},
183
+ }
184
+ ```
185
+
186
+ ## License
187
+
188
+ BSD-3-Clause for the model code (matching braindecode).
189
+ Pretraining-derived weights, if you fine-tune from a checkpoint,
190
+ inherit the licence of that checkpoint and its training corpus.