bruAristimunha commited on
Commit
15510f7
·
verified ·
1 Parent(s): 80445ab

Add architecture-only model card

Browse files
Files changed (1) hide show
  1. README.md +217 -0
README.md ADDED
@@ -0,0 +1,217 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ # Deep4Net
15
+
16
+ Deep ConvNet model from Schirrmeister et al (2017) .
17
+
18
+ > **Architecture-only repository.** This repo documents the
19
+ > `braindecode.models.Deep4Net` 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 Deep4Net
32
+
33
+ model = Deep4Net(
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.Deep4Net.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/deep4.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>Deep ConvNet model from Schirrmeister et al (2017) [Schirrmeister2017]_.</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>
60
+
61
+
62
+
63
+ .. figure:: https://onlinelibrary.wiley.com/cms/asset/fc200ccc-d8c4-45b4-8577-56ce4d15999a/hbm23730-fig-0001-m.jpg
64
+ :align: center
65
+ :alt: Deep4Net Architecture
66
+ :width: 600px
67
+
68
+
69
+ Model described in [Schirrmeister2017]_.
70
+
71
+ Parameters
72
+ ----------
73
+ final_conv_length: int | str
74
+ Length of the final convolution layer.
75
+ If set to "auto", n_times must not be None. Default: "auto".
76
+ n_filters_time: int
77
+ Number of temporal filters.
78
+ n_filters_spat: int
79
+ Number of spatial filters.
80
+ filter_time_length: int
81
+ Length of the temporal filter in layer 1.
82
+ pool_time_length: int
83
+ Length of temporal pooling filter.
84
+ pool_time_stride: int
85
+ Length of stride between temporal pooling filters.
86
+ n_filters_2: int
87
+ Number of temporal filters in layer 2.
88
+ filter_length_2: int
89
+ Length of the temporal filter in layer 2.
90
+ n_filters_3: int
91
+ Number of temporal filters in layer 3.
92
+ filter_length_3: int
93
+ Length of the temporal filter in layer 3.
94
+ n_filters_4: int
95
+ Number of temporal filters in layer 4.
96
+ filter_length_4: int
97
+ Length of the temporal filter in layer 4.
98
+ activation_first_conv_nonlin: nn.Module, default is nn.ELU
99
+ Non-linear activation function to be used after convolution in layer 1.
100
+ first_pool_mode: str
101
+ Pooling mode in layer 1. "max" or "mean".
102
+ first_pool_nonlin: callable
103
+ Non-linear activation function to be used after pooling in layer 1.
104
+ activation_later_conv_nonlin: nn.Module, default is nn.ELU
105
+ Non-linear activation function to be used after convolution in later layers.
106
+ later_pool_mode: str
107
+ Pooling mode in later layers. "max" or "mean".
108
+ later_pool_nonlin: callable
109
+ Non-linear activation function to be used after pooling in later layers.
110
+ drop_prob: float
111
+ Dropout probability.
112
+ split_first_layer: bool
113
+ Split first layer into temporal and spatial layers (True) or just use temporal (False).
114
+ There would be no non-linearity between the split layers.
115
+ batch_norm: bool
116
+ Whether to use batch normalisation.
117
+ batch_norm_alpha: float
118
+ Momentum for BatchNorm2d.
119
+ stride_before_pool: bool
120
+ Stride before pooling.
121
+
122
+
123
+ References
124
+ ----------
125
+ .. [Schirrmeister2017] Schirrmeister, R. T., Springenberg, J. T., Fiederer,
126
+ L. D. J., Glasstetter, M., Eggensperger, K., Tangermann, M., Hutter, F.
127
+ & Ball, T. (2017).
128
+ Deep learning with convolutional neural networks for EEG decoding and
129
+ visualization.
130
+ Human Brain Mapping , Aug. 2017.
131
+ Online: http://dx.doi.org/10.1002/hbm.23730
132
+
133
+ .. rubric:: Hugging Face Hub integration
134
+
135
+ When the optional ``huggingface_hub`` package is installed, all models
136
+ automatically gain the ability to be pushed to and loaded from the
137
+ Hugging Face Hub. Install with::
138
+
139
+ pip install braindecode[hub]
140
+
141
+ **Pushing a model to the Hub:**
142
+
143
+ .. code::
144
+ from braindecode.models import Deep4Net
145
+
146
+ # Train your model
147
+ model = Deep4Net(n_chans=22, n_outputs=4, n_times=1000)
148
+ # ... training code ...
149
+
150
+ # Push to the Hub
151
+ model.push_to_hub(
152
+ repo_id="username/my-deep4net-model",
153
+ commit_message="Initial model upload",
154
+ )
155
+
156
+ **Loading a model from the Hub:**
157
+
158
+ .. code::
159
+ from braindecode.models import Deep4Net
160
+
161
+ # Load pretrained model
162
+ model = Deep4Net.from_pretrained("username/my-deep4net-model")
163
+
164
+ # Load with a different number of outputs (head is rebuilt automatically)
165
+ model = Deep4Net.from_pretrained("username/my-deep4net-model", n_outputs=4)
166
+
167
+ **Extracting features and replacing the head:**
168
+
169
+ .. code::
170
+ import torch
171
+
172
+ x = torch.randn(1, model.n_chans, model.n_times)
173
+ # Extract encoder features (consistent dict across all models)
174
+ out = model(x, return_features=True)
175
+ features = out["features"]
176
+
177
+ # Replace the classification head
178
+ model.reset_head(n_outputs=10)
179
+
180
+ **Saving and restoring full configuration:**
181
+
182
+ .. code::
183
+ import json
184
+
185
+ config = model.get_config() # all __init__ params
186
+ with open("config.json", "w") as f:
187
+ json.dump(config, f)
188
+
189
+ model2 = Deep4Net.from_config(config) # reconstruct (no weights)
190
+
191
+ All model parameters (both EEG-specific and model-specific such as
192
+ dropout rates, activation functions, number of filters) are automatically
193
+ saved to the Hub and restored when loading.
194
+
195
+ See :ref:`load-pretrained-models` for a complete tutorial.</main>
196
+ </div>
197
+
198
+ ## Citation
199
+
200
+ Please cite both the original paper for this architecture (see the
201
+ *References* section above) and braindecode:
202
+
203
+ ```bibtex
204
+ @article{aristimunha2025braindecode,
205
+ title = {Braindecode: a deep learning library for raw electrophysiological data},
206
+ author = {Aristimunha, Bruno and others},
207
+ journal = {Zenodo},
208
+ year = {2025},
209
+ doi = {10.5281/zenodo.17699192},
210
+ }
211
+ ```
212
+
213
+ ## License
214
+
215
+ BSD-3-Clause for the model code (matching braindecode).
216
+ Pretraining-derived weights, if you fine-tune from a checkpoint,
217
+ inherit the licence of that checkpoint and its training corpus.