Add the braindecode-format encoder (safetensors + config)
Browse files- README.md +26 -23
- config.json +16 -0
- model.safetensors +3 -0
README.md
CHANGED
|
@@ -9,9 +9,9 @@ tags:
|
|
| 9 |
- braindecode
|
| 10 |
---
|
| 11 |
|
| 12 |
-
# SleepFM — pretrained
|
| 13 |
|
| 14 |
-
Mirror of the official **SleepFM**
|
| 15 |
[Braindecode](https://github.com/braindecode/braindecode).
|
| 16 |
|
| 17 |
SleepFM is a multimodal polysomnography (PSG) foundation model introduced in:
|
|
@@ -19,37 +19,40 @@ SleepFM is a multimodal polysomnography (PSG) foundation model introduced in:
|
|
| 19 |
> R. Thapa et al., *"A multimodal sleep foundation model for disease prediction,"*
|
| 20 |
> **Nature Medicine** (2026). https://doi.org/10.1038/s41591-025-04133-4
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
## Files
|
| 23 |
|
| 24 |
-
| File | Description |
|
| 25 |
-
|------|-------------|
|
| 26 |
-
| `
|
| 27 |
-
| `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
| 31 |
|
| 32 |
## Usage
|
| 33 |
|
| 34 |
```python
|
| 35 |
-
import
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
"https://huggingface.co/braindecode/SleepFM/resolve/main/model_base/best.pt",
|
| 40 |
-
map_location="cpu",
|
| 41 |
-
)
|
| 42 |
-
staging = torch.hub.load_state_dict_from_url(
|
| 43 |
-
"https://huggingface.co/braindecode/SleepFM/resolve/main/model_sleep_staging/best.pth",
|
| 44 |
-
map_location="cpu",
|
| 45 |
-
)
|
| 46 |
-
|
| 47 |
-
model = SleepFMStager(n_chans=4, n_outputs=5, n_times=3840, sfreq=128)
|
| 48 |
-
model.load_pretrained_backbone(base)
|
| 49 |
-
model.load_pretrained_staging_head(staging)
|
| 50 |
model.eval()
|
| 51 |
```
|
| 52 |
|
|
|
|
|
|
|
|
|
|
| 53 |
## License & attribution
|
| 54 |
|
| 55 |
- **License: Creative Commons Attribution-NonCommercial 4.0 International (CC BY-NC 4.0).**
|
|
|
|
| 9 |
- braindecode
|
| 10 |
---
|
| 11 |
|
| 12 |
+
# SleepFM — pretrained encoder
|
| 13 |
|
| 14 |
+
Mirror of the official **SleepFM** encoder checkpoint, re-hosted for stable loading from
|
| 15 |
[Braindecode](https://github.com/braindecode/braindecode).
|
| 16 |
|
| 17 |
SleepFM is a multimodal polysomnography (PSG) foundation model introduced in:
|
|
|
|
| 19 |
> R. Thapa et al., *"A multimodal sleep foundation model for disease prediction,"*
|
| 20 |
> **Nature Medicine** (2026). https://doi.org/10.1038/s41591-025-04133-4
|
| 21 |
|
| 22 |
+
The downstream sleep stager lives in a separate repository,
|
| 23 |
+
[`braindecode/SleepFMStager`](https://huggingface.co/braindecode/SleepFMStager),
|
| 24 |
+
because a Braindecode `config.json` describes exactly one architecture.
|
| 25 |
+
|
| 26 |
## Files
|
| 27 |
|
| 28 |
+
| File | Description |
|
| 29 |
+
|------|-------------|
|
| 30 |
+
| `model.safetensors` | The encoder, with the parameter names of `braindecode.models.SleepFM` |
|
| 31 |
+
| `config.json` | Architecture of the checkpoint, read by `from_pretrained()` |
|
| 32 |
+
| `model_base/best.pt` | The upstream artifact, byte-for-byte, kept for provenance |
|
| 33 |
+
| `model_sleep_staging/best.pth` | The upstream staging artifact, byte-for-byte (see `SleepFMStager`) |
|
| 34 |
+
|
| 35 |
+
`model.safetensors` holds the **same tensors** as `model_base/best.pt`; only the keys were
|
| 36 |
+
rewritten (the `module.` prefix of the distributed training run stripped, and
|
| 37 |
+
`positional_encoding.pe` renamed) so that the library needs no remapping code at load
|
| 38 |
+
time. Loading either way gives bit-identical outputs.
|
| 39 |
|
| 40 |
+
Note that the released encoder is contrastive and carries **no classification head**:
|
| 41 |
+
`final_layer` is randomly initialised and must be fine-tuned.
|
| 42 |
|
| 43 |
## Usage
|
| 44 |
|
| 45 |
```python
|
| 46 |
+
from braindecode.models import SleepFM
|
| 47 |
+
|
| 48 |
+
# Defaults to this repository.
|
| 49 |
+
model = SleepFM.from_pretrained(n_chans=4, n_outputs=5, n_times=3840, sfreq=128)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
model.eval()
|
| 51 |
```
|
| 52 |
|
| 53 |
+
Input must be sampled at **128 Hz**; the reference `patch_size=640` is a 5-second patch at
|
| 54 |
+
that rate. A channel mask of shape `(batch, n_chans)` marks missing channels with `True`.
|
| 55 |
+
|
| 56 |
## License & attribution
|
| 57 |
|
| 58 |
- **License: Creative Commons Attribution-NonCommercial 4.0 International (CC BY-NC 4.0).**
|
config.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"n_outputs": 5,
|
| 3 |
+
"n_chans": 4,
|
| 4 |
+
"chs_info": null,
|
| 5 |
+
"n_times": 3840,
|
| 6 |
+
"input_window_seconds": null,
|
| 7 |
+
"sfreq": 128.0,
|
| 8 |
+
"patch_size": 640,
|
| 9 |
+
"embed_dim": 128,
|
| 10 |
+
"num_heads": 8,
|
| 11 |
+
"num_layers": 6,
|
| 12 |
+
"pooling_heads": 8,
|
| 13 |
+
"drop_prob": 0.3,
|
| 14 |
+
"max_seq_length": 128,
|
| 15 |
+
"activation": "torch.nn.modules.activation.ELU"
|
| 16 |
+
}
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1a8d02f16323e564b834f3f31ecf9995f4401ff1598459feaec7f3ab671366b2
|
| 3 |
+
size 19410992
|