bruAristimunha commited on
Commit
26f7a1f
·
verified ·
1 Parent(s): 63a503d

Add architecture-only model card

Browse files
Files changed (1) hide show
  1. README.md +188 -0
README.md ADDED
@@ -0,0 +1,188 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ - transformer
13
+ ---
14
+
15
+ # SPARCNet
16
+
17
+ Seizures, Periodic and Rhythmic pattern Continuum Neural Network (SPaRCNet) from Jing et al (2023) .
18
+
19
+ > **Architecture-only repository.** This repo documents the
20
+ > `braindecode.models.SPARCNet` 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 SPARCNet
33
+
34
+ model = SPARCNet(
35
+ n_chans=22,
36
+ sfreq=250,
37
+ input_window_seconds=4.0,
38
+ n_outputs=4,
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.SPARCNet.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/sparcnet.py#L13>
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>Seizures, Periodic and Rhythmic pattern Continuum Neural Network (SPaRCNet) from Jing et al (2023) [jing2023]_.</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
+ This is a temporal CNN model for biosignal classification based on the DenseNet
65
+ architecture.
66
+
67
+ The model is based on the unofficial implementation [Code2023]_.
68
+
69
+ .. versionadded:: 0.9
70
+
71
+ Notes
72
+ -----
73
+ This implementation is not guaranteed to be correct, has not been checked
74
+ by original authors.
75
+
76
+ Parameters
77
+ ----------
78
+ block_layers : int, optional
79
+ Number of layers per dense block. Default is 4.
80
+ growth_rate : int, optional
81
+ Growth rate of the DenseNet. Default is 16.
82
+ bn_size : int, optional
83
+ Bottleneck size. Default is 16.
84
+ drop_prob : float, optional
85
+ Dropout rate. Default is 0.5.
86
+ conv_bias : bool, optional
87
+ Whether to use bias in convolutional layers. Default is True.
88
+ batch_norm : bool, optional
89
+ Whether to use batch normalization. Default is True.
90
+ activation: nn.Module, default=nn.ELU
91
+ Activation function class to apply. Should be a PyTorch activation
92
+ module class like ``nn.ReLU`` or ``nn.ELU``. Default is ``nn.ELU``.
93
+
94
+ References
95
+ ----------
96
+ .. [jing2023] Jing, J., Ge, W., Hong, S., Fernandes, M. B., Lin, Z.,
97
+ Yang, C., ... & Westover, M. B. (2023). Development of expert-level
98
+ classification of seizures and rhythmic and periodic
99
+ patterns during eeg interpretation. Neurology, 100(17), e1750-e1762.
100
+ .. [Code2023] Yang, C., Westover, M.B. and Sun, J., 2023. BIOT
101
+ Biosignal Transformer for Cross-data Learning in the Wild.
102
+ GitHub https://github.com/ycq091044/BIOT (accessed 2024-02-13)
103
+
104
+ .. rubric:: Hugging Face Hub integration
105
+
106
+ When the optional ``huggingface_hub`` package is installed, all models
107
+ automatically gain the ability to be pushed to and loaded from the
108
+ Hugging Face Hub. Install with::
109
+
110
+ pip install braindecode[hub]
111
+
112
+ **Pushing a model to the Hub:**
113
+
114
+ .. code::
115
+ from braindecode.models import SPARCNet
116
+
117
+ # Train your model
118
+ model = SPARCNet(n_chans=22, n_outputs=4, n_times=1000)
119
+ # ... training code ...
120
+
121
+ # Push to the Hub
122
+ model.push_to_hub(
123
+ repo_id="username/my-sparcnet-model",
124
+ commit_message="Initial model upload",
125
+ )
126
+
127
+ **Loading a model from the Hub:**
128
+
129
+ .. code::
130
+ from braindecode.models import SPARCNet
131
+
132
+ # Load pretrained model
133
+ model = SPARCNet.from_pretrained("username/my-sparcnet-model")
134
+
135
+ # Load with a different number of outputs (head is rebuilt automatically)
136
+ model = SPARCNet.from_pretrained("username/my-sparcnet-model", n_outputs=4)
137
+
138
+ **Extracting features and replacing the head:**
139
+
140
+ .. code::
141
+ import torch
142
+
143
+ x = torch.randn(1, model.n_chans, model.n_times)
144
+ # Extract encoder features (consistent dict across all models)
145
+ out = model(x, return_features=True)
146
+ features = out["features"]
147
+
148
+ # Replace the classification head
149
+ model.reset_head(n_outputs=10)
150
+
151
+ **Saving and restoring full configuration:**
152
+
153
+ .. code::
154
+ import json
155
+
156
+ config = model.get_config() # all __init__ params
157
+ with open("config.json", "w") as f:
158
+ json.dump(config, f)
159
+
160
+ model2 = SPARCNet.from_config(config) # reconstruct (no weights)
161
+
162
+ All model parameters (both EEG-specific and model-specific such as
163
+ dropout rates, activation functions, number of filters) are automatically
164
+ saved to the Hub and restored when loading.
165
+
166
+ See :ref:`load-pretrained-models` for a complete tutorial.</main>
167
+ </div>
168
+
169
+ ## Citation
170
+
171
+ Please cite both the original paper for this architecture (see the
172
+ *References* section above) and braindecode:
173
+
174
+ ```bibtex
175
+ @article{aristimunha2025braindecode,
176
+ title = {Braindecode: a deep learning library for raw electrophysiological data},
177
+ author = {Aristimunha, Bruno and others},
178
+ journal = {Zenodo},
179
+ year = {2025},
180
+ doi = {10.5281/zenodo.17699192},
181
+ }
182
+ ```
183
+
184
+ ## License
185
+
186
+ BSD-3-Clause for the model code (matching braindecode).
187
+ Pretraining-derived weights, if you fine-tune from a checkpoint,
188
+ inherit the licence of that checkpoint and its training corpus.