bruAristimunha commited on
Commit
89c7753
·
verified ·
1 Parent(s): c5787b4

Add architecture-only model card

Browse files
Files changed (1) hide show
  1. README.md +173 -0
README.md ADDED
@@ -0,0 +1,173 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ # BDTCN
15
+
16
+ Braindecode TCN from Gemein, L et al (2020) .
17
+
18
+ > **Architecture-only repository.** This repo documents the
19
+ > `braindecode.models.BDTCN` 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 BDTCN
32
+
33
+ model = BDTCN(
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.BDTCN.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/tcn.py#L14>
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>Braindecode TCN from Gemein, L et al (2020) [gemein2020]_.</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:#6c757d;color:white;font-size:11px;font-weight:600;margin-right:4px;">Recurrent</span>
60
+
61
+
62
+
63
+ .. figure:: https://ars.els-cdn.com/content/image/1-s2.0-S1053811920305073-gr3_lrg.jpg
64
+ :align: center
65
+ :alt: Braindecode TCN Architecture
66
+
67
+ See [gemein2020]_ for details.
68
+
69
+ Parameters
70
+ ----------
71
+ n_filters: int
72
+ number of output filters of each convolution
73
+ n_blocks: int
74
+ number of temporal blocks in the network
75
+ kernel_size: int
76
+ kernel size of the convolutions
77
+ drop_prob: float
78
+ dropout probability
79
+ activation: nn.Module, default=nn.ReLU
80
+ Activation function class to apply. Should be a PyTorch activation
81
+ module class like ``nn.ReLU`` or ``nn.ELU``. Default is ``nn.ReLU``.
82
+
83
+ References
84
+ ----------
85
+ .. [gemein2020] Gemein, L. A., Schirrmeister, R. T., Chrabąszcz, P., Wilson, D.,
86
+ Boedecker, J., Schulze-Bonhage, A., ... & Ball, T. (2020). Machine-learning-based
87
+ diagnostics of EEG pathology. NeuroImage, 220, 117021.
88
+
89
+ .. rubric:: Hugging Face Hub integration
90
+
91
+ When the optional ``huggingface_hub`` package is installed, all models
92
+ automatically gain the ability to be pushed to and loaded from the
93
+ Hugging Face Hub. Install with::
94
+
95
+ pip install braindecode[hub]
96
+
97
+ **Pushing a model to the Hub:**
98
+
99
+ .. code::
100
+ from braindecode.models import BDTCN
101
+
102
+ # Train your model
103
+ model = BDTCN(n_chans=22, n_outputs=4, n_times=1000)
104
+ # ... training code ...
105
+
106
+ # Push to the Hub
107
+ model.push_to_hub(
108
+ repo_id="username/my-bdtcn-model",
109
+ commit_message="Initial model upload",
110
+ )
111
+
112
+ **Loading a model from the Hub:**
113
+
114
+ .. code::
115
+ from braindecode.models import BDTCN
116
+
117
+ # Load pretrained model
118
+ model = BDTCN.from_pretrained("username/my-bdtcn-model")
119
+
120
+ # Load with a different number of outputs (head is rebuilt automatically)
121
+ model = BDTCN.from_pretrained("username/my-bdtcn-model", n_outputs=4)
122
+
123
+ **Extracting features and replacing the head:**
124
+
125
+ .. code::
126
+ import torch
127
+
128
+ x = torch.randn(1, model.n_chans, model.n_times)
129
+ # Extract encoder features (consistent dict across all models)
130
+ out = model(x, return_features=True)
131
+ features = out["features"]
132
+
133
+ # Replace the classification head
134
+ model.reset_head(n_outputs=10)
135
+
136
+ **Saving and restoring full configuration:**
137
+
138
+ .. code::
139
+ import json
140
+
141
+ config = model.get_config() # all __init__ params
142
+ with open("config.json", "w") as f:
143
+ json.dump(config, f)
144
+
145
+ model2 = BDTCN.from_config(config) # reconstruct (no weights)
146
+
147
+ All model parameters (both EEG-specific and model-specific such as
148
+ dropout rates, activation functions, number of filters) are automatically
149
+ saved to the Hub and restored when loading.
150
+
151
+ See :ref:`load-pretrained-models` for a complete tutorial.</main>
152
+ </div>
153
+
154
+ ## Citation
155
+
156
+ Please cite both the original paper for this architecture (see the
157
+ *References* section above) and braindecode:
158
+
159
+ ```bibtex
160
+ @article{aristimunha2025braindecode,
161
+ title = {Braindecode: a deep learning library for raw electrophysiological data},
162
+ author = {Aristimunha, Bruno and others},
163
+ journal = {Zenodo},
164
+ year = {2025},
165
+ doi = {10.5281/zenodo.17699192},
166
+ }
167
+ ```
168
+
169
+ ## License
170
+
171
+ BSD-3-Clause for the model code (matching braindecode).
172
+ Pretraining-derived weights, if you fine-tune from a checkpoint,
173
+ inherit the licence of that checkpoint and its training corpus.