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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
# TSception
|
| 15 |
+
|
| 16 |
+
TSception model from Ding et al. (2020) from .
|
| 17 |
+
|
| 18 |
+
> **Architecture-only repository.** This repo documents the
|
| 19 |
+
> `braindecode.models.TSception` 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 TSception
|
| 32 |
+
|
| 33 |
+
model = TSception(
|
| 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.TSception.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/tsinception.py#L15>
|
| 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>TSception model from Ding et al. (2020) from [ding2020]_.</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 |
+
TSception: A deep learning framework for emotion detection using EEG.
|
| 64 |
+
|
| 65 |
+
.. figure:: https://user-images.githubusercontent.com/58539144/74716976-80415e00-526a-11ea-9433-02ab2b753f6b.PNG
|
| 66 |
+
:align: center
|
| 67 |
+
:alt: TSception Architecture
|
| 68 |
+
|
| 69 |
+
The model consists of temporal and spatial convolutional layers
|
| 70 |
+
(Tception and Sception) designed to learn temporal and spatial features
|
| 71 |
+
from EEG data.
|
| 72 |
+
|
| 73 |
+
Parameters
|
| 74 |
+
----------
|
| 75 |
+
number_filter_temp : int
|
| 76 |
+
Number of temporal convolutional filters.
|
| 77 |
+
number_filter_spat : int
|
| 78 |
+
Number of spatial convolutional filters.
|
| 79 |
+
hidden_size : int
|
| 80 |
+
Number of units in the hidden fully connected layer.
|
| 81 |
+
drop_prob : float
|
| 82 |
+
Dropout rate applied after the hidden layer.
|
| 83 |
+
activation : nn.Module, optional
|
| 84 |
+
Activation function class to apply. Should be a PyTorch activation
|
| 85 |
+
module like ``nn.ReLU`` or ``nn.LeakyReLU``. Default is ``nn.LeakyReLU``.
|
| 86 |
+
pool_size : int, optional
|
| 87 |
+
Pooling size for the average pooling layers. Default is 8.
|
| 88 |
+
inception_windows : list[float], optional
|
| 89 |
+
List of window sizes (in seconds) for the inception modules.
|
| 90 |
+
Default is [0.5, 0.25, 0.125].
|
| 91 |
+
|
| 92 |
+
Notes
|
| 93 |
+
-----
|
| 94 |
+
This implementation is not guaranteed to be correct, has not been checked
|
| 95 |
+
by original authors. The modifications are minimal and the model is expected
|
| 96 |
+
to work as intended. the original code from [code2020]_.
|
| 97 |
+
|
| 98 |
+
References
|
| 99 |
+
----------
|
| 100 |
+
.. [ding2020] Ding, Y., Robinson, N., Zeng, Q., Chen, D., Wai, A. A. P.,
|
| 101 |
+
Lee, T. S., & Guan, C. (2020, July). Tsception: a deep learning framework
|
| 102 |
+
for emotion detection using EEG. In 2020 international joint conference
|
| 103 |
+
on neural networks (IJCNN) (pp. 1-7). IEEE.
|
| 104 |
+
.. [code2020] Ding, Y., Robinson, N., Zeng, Q., Chen, D., Wai, A. A. P.,
|
| 105 |
+
Lee, T. S., & Guan, C. (2020, July). Tsception: a deep learning framework
|
| 106 |
+
for emotion detection using EEG.
|
| 107 |
+
https://github.com/deepBrains/TSception/blob/master/Models.py
|
| 108 |
+
|
| 109 |
+
.. rubric:: Hugging Face Hub integration
|
| 110 |
+
|
| 111 |
+
When the optional ``huggingface_hub`` package is installed, all models
|
| 112 |
+
automatically gain the ability to be pushed to and loaded from the
|
| 113 |
+
Hugging Face Hub. Install with::
|
| 114 |
+
|
| 115 |
+
pip install braindecode[hub]
|
| 116 |
+
|
| 117 |
+
**Pushing a model to the Hub:**
|
| 118 |
+
|
| 119 |
+
.. code::
|
| 120 |
+
from braindecode.models import TSception
|
| 121 |
+
|
| 122 |
+
# Train your model
|
| 123 |
+
model = TSception(n_chans=22, n_outputs=4, n_times=1000)
|
| 124 |
+
# ... training code ...
|
| 125 |
+
|
| 126 |
+
# Push to the Hub
|
| 127 |
+
model.push_to_hub(
|
| 128 |
+
repo_id="username/my-tsception-model",
|
| 129 |
+
commit_message="Initial model upload",
|
| 130 |
+
)
|
| 131 |
+
|
| 132 |
+
**Loading a model from the Hub:**
|
| 133 |
+
|
| 134 |
+
.. code::
|
| 135 |
+
from braindecode.models import TSception
|
| 136 |
+
|
| 137 |
+
# Load pretrained model
|
| 138 |
+
model = TSception.from_pretrained("username/my-tsception-model")
|
| 139 |
+
|
| 140 |
+
# Load with a different number of outputs (head is rebuilt automatically)
|
| 141 |
+
model = TSception.from_pretrained("username/my-tsception-model", n_outputs=4)
|
| 142 |
+
|
| 143 |
+
**Extracting features and replacing the head:**
|
| 144 |
+
|
| 145 |
+
.. code::
|
| 146 |
+
import torch
|
| 147 |
+
|
| 148 |
+
x = torch.randn(1, model.n_chans, model.n_times)
|
| 149 |
+
# Extract encoder features (consistent dict across all models)
|
| 150 |
+
out = model(x, return_features=True)
|
| 151 |
+
features = out["features"]
|
| 152 |
+
|
| 153 |
+
# Replace the classification head
|
| 154 |
+
model.reset_head(n_outputs=10)
|
| 155 |
+
|
| 156 |
+
**Saving and restoring full configuration:**
|
| 157 |
+
|
| 158 |
+
.. code::
|
| 159 |
+
import json
|
| 160 |
+
|
| 161 |
+
config = model.get_config() # all __init__ params
|
| 162 |
+
with open("config.json", "w") as f:
|
| 163 |
+
json.dump(config, f)
|
| 164 |
+
|
| 165 |
+
model2 = TSception.from_config(config) # reconstruct (no weights)
|
| 166 |
+
|
| 167 |
+
All model parameters (both EEG-specific and model-specific such as
|
| 168 |
+
dropout rates, activation functions, number of filters) are automatically
|
| 169 |
+
saved to the Hub and restored when loading.
|
| 170 |
+
|
| 171 |
+
See :ref:`load-pretrained-models` for a complete tutorial.</main>
|
| 172 |
+
</div>
|
| 173 |
+
|
| 174 |
+
## Citation
|
| 175 |
+
|
| 176 |
+
Please cite both the original paper for this architecture (see the
|
| 177 |
+
*References* section above) and braindecode:
|
| 178 |
+
|
| 179 |
+
```bibtex
|
| 180 |
+
@article{aristimunha2025braindecode,
|
| 181 |
+
title = {Braindecode: a deep learning library for raw electrophysiological data},
|
| 182 |
+
author = {Aristimunha, Bruno and others},
|
| 183 |
+
journal = {Zenodo},
|
| 184 |
+
year = {2025},
|
| 185 |
+
doi = {10.5281/zenodo.17699192},
|
| 186 |
+
}
|
| 187 |
+
```
|
| 188 |
+
|
| 189 |
+
## License
|
| 190 |
+
|
| 191 |
+
BSD-3-Clause for the model code (matching braindecode).
|
| 192 |
+
Pretraining-derived weights, if you fine-tune from a checkpoint,
|
| 193 |
+
inherit the licence of that checkpoint and its training corpus.
|