adammnrr commited on
Commit
8681fba
·
verified ·
1 Parent(s): 6340e21

Mirror the SleepFM sleep stager in braindecode format

Browse files
Files changed (3) hide show
  1. README.md +63 -0
  2. config.json +16 -0
  3. model.safetensors +3 -0
README.md ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: cc-by-nc-4.0
3
+ library_name: braindecode
4
+ tags:
5
+ - eeg
6
+ - polysomnography
7
+ - sleep-staging
8
+ - foundation-model
9
+ - braindecode
10
+ ---
11
+
12
+ # SleepFMStager — pretrained sleep stager
13
+
14
+ Mirror of the official **SleepFM** sleep-staging model, 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:
18
+
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
+ | `model.safetensors` | The full stager, with the parameter names of `braindecode.models.SleepFMStager` |
27
+ | `config.json` | Architecture of the checkpoint, read by `from_pretrained()` |
28
+
29
+ Upstream ships the stager in two pieces: the channel-agnostic tokenizer lives in the
30
+ encoder checkpoint (`model_base/best.pt`) and the staging head in
31
+ `model_sleep_staging/best.pth`. This file **merges both**, so a single call returns a
32
+ model that is pretrained end to end, its five-class output layer included. The tensors are
33
+ those of the upstream artifacts; only the keys were rewritten to the library's parameter
34
+ names. Loading this file or the two upstream ones gives bit-identical outputs.
35
+
36
+ The upstream artifacts themselves are kept, byte-for-byte, in
37
+ [`braindecode/SleepFM`](https://huggingface.co/braindecode/SleepFM).
38
+
39
+ ## Usage
40
+
41
+ ```python
42
+ from braindecode.models import SleepFMStager
43
+
44
+ # Defaults to this repository.
45
+ model = SleepFMStager.from_pretrained(n_chans=4, n_outputs=5, n_times=3840, sfreq=128)
46
+ model.eval()
47
+ ```
48
+
49
+ The output has shape `(batch, n_outputs, n_patches)`: one prediction per **5-second
50
+ patch**, not per 30-second scoring epoch, so six predictions cover one scored epoch. For
51
+ this checkpoint the five classes are Wake, N1, N2, N3 and REM. Input must be sampled at
52
+ **128 Hz**. Pass `n_outputs` different from 5 to reinitialise the output layer for another
53
+ label set.
54
+
55
+ ## License & attribution
56
+
57
+ - **License: Creative Commons Attribution-NonCommercial 4.0 International (CC BY-NC 4.0).**
58
+ - Copyright (c) 2025 Rahul Thapa.
59
+ - Upstream source: https://github.com/zou-group/sleepfm-clinical
60
+
61
+ These weights are **not** covered by Braindecode's BSD-3 license and inherit the
62
+ upstream **noncommercial** terms. Re-hosted for reproducibility and stable
63
+ availability only; attribution and the CC BY-NC 4.0 restriction are preserved.
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
+ "staging_num_heads": 4,
11
+ "staging_num_layers": 1,
12
+ "staging_pooling_heads": 4,
13
+ "drop_prob": 0.3,
14
+ "max_seq_length": 8196,
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:b5caa06bad848f6b2b1c200263ba098954c920cc4505b411182ec47cb5888cd9
3
+ size 9702172