bruAristimunha commited on
Commit
b59537e
Β·
verified Β·
1 Parent(s): 15510f7

Replace with clean markdown card

Browse files
Files changed (1) hide show
  1. README.md +48 -158
README.md CHANGED
@@ -13,13 +13,12 @@ tags:
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
 
@@ -38,167 +37,58 @@ model = Deep4Net(
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,
 
13
 
14
  # Deep4Net
15
 
16
+ Deep ConvNet model from Schirrmeister et al (2017) [Schirrmeister2017].
17
 
18
+ > **Architecture-only repository.** 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.
 
22
 
23
  ## Quick start
24
 
 
37
  )
38
  ```
39
 
40
+ The signal-shape arguments above are illustrative defaults β€” adjust to
41
+ match your recording.
42
 
43
  ## Documentation
44
+ - Full API reference: <https://braindecode.org/stable/generated/braindecode.models.Deep4Net.html>
45
+ - Interactive browser (live instantiation, parameter counts):
 
 
46
  <https://huggingface.co/spaces/braindecode/model-explorer>
47
  - Source on GitHub: <https://github.com/braindecode/braindecode/blob/master/braindecode/models/deep4.py#L19>
48
 
49
+
50
+ ## Architecture
51
+
52
+ ![Deep4Net architecture](https://onlinelibrary.wiley.com/cms/asset/fc200ccc-d8c4-45b4-8577-56ce4d15999a/hbm23730-fig-0001-m.jpg)
53
+
54
+
55
+ ## Parameters
56
+
57
+ | Parameter | Type | Description |
58
+ |---|---|---|
59
+ | `final_conv_length: int | str` | β€” | Length of the final convolution layer. If set to "auto", n_times must not be None. Default: "auto". |
60
+ | `n_filters_time: int` | β€” | Number of temporal filters. |
61
+ | `n_filters_spat: int` | β€” | Number of spatial filters. |
62
+ | `filter_time_length: int` | β€” | Length of the temporal filter in layer 1. |
63
+ | `pool_time_length: int` | β€” | Length of temporal pooling filter. |
64
+ | `pool_time_stride: int` | β€” | Length of stride between temporal pooling filters. |
65
+ | `n_filters_2: int` | β€” | Number of temporal filters in layer 2. |
66
+ | `filter_length_2: int` | β€” | Length of the temporal filter in layer 2. |
67
+ | `n_filters_3: int` | β€” | Number of temporal filters in layer 3. |
68
+ | `filter_length_3: int` | β€” | Length of the temporal filter in layer 3. |
69
+ | `n_filters_4: int` | β€” | Number of temporal filters in layer 4. |
70
+ | `filter_length_4: int` | β€” | Length of the temporal filter in layer 4. |
71
+ | `activation_first_conv_nonlin: nn.Module, default is nn.ELU` | β€” | Non-linear activation function to be used after convolution in layer 1. |
72
+ | `first_pool_mode: str` | β€” | Pooling mode in layer 1. "max" or "mean". |
73
+ | `first_pool_nonlin: callable` | β€” | Non-linear activation function to be used after pooling in layer 1. |
74
+ | `activation_later_conv_nonlin: nn.Module, default is nn.ELU` | β€” | Non-linear activation function to be used after convolution in later layers. |
75
+ | `later_pool_mode: str` | β€” | Pooling mode in later layers. "max" or "mean". |
76
+ | `later_pool_nonlin: callable` | β€” | Non-linear activation function to be used after pooling in later layers. |
77
+ | `drop_prob: float` | β€” | Dropout probability. |
78
+ | `split_first_layer: bool` | β€” | Split first layer into temporal and spatial layers (True) or just use temporal (False). There would be no non-linearity between the split layers. |
79
+ | `batch_norm: bool` | β€” | Whether to use batch normalisation. |
80
+ | `batch_norm_alpha: float` | β€” | Momentum for BatchNorm2d. |
81
+ | `stride_before_pool: bool` | β€” | Stride before pooling. |
82
+
83
+
84
+ ## References
85
+
86
+ 1. Schirrmeister, R. T., Springenberg, J. T., Fiederer, L. D. J., Glasstetter, M., Eggensperger, K., Tangermann, M., Hutter, F. & Ball, T. (2017). Deep learning with convolutional neural networks for EEG decoding and visualization. Human Brain Mapping , Aug. 2017. Online: http://dx.doi.org/10.1002/hbm.23730
87
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
 
89
  ## Citation
90
 
91
+ Cite the original architecture paper (see *References* above) and braindecode:
 
92
 
93
  ```bibtex
94
  @article{aristimunha2025braindecode,