Self-contained stager export (braindecode PR #1106 @ b0ae1aa8)
Browse filesmodel.safetensors now holds the complete stager (180 tensors, bit-identical to upstream model_base/best.pt + model_sleep_staging/best.pth); config.json lists every constructor argument (channel_modalities null by design); card updated with a Revisions note. Licence fields unchanged. Previous revision 8681fbade497e2ce103e1b68b01fbb3d56e809f2 still loads.
- README.md +35 -9
- config.json +8 -1
- model.safetensors +2 -2
README.md
CHANGED
|
@@ -23,15 +23,17 @@ SleepFM is a multimodal polysomnography (PSG) foundation model introduced in:
|
|
| 23 |
|
| 24 |
| File | Description |
|
| 25 |
|------|-------------|
|
| 26 |
-
| `model.safetensors` | The
|
| 27 |
| `config.json` | Architecture of the checkpoint, read by `from_pretrained()` |
|
| 28 |
|
| 29 |
-
Upstream ships the stager in two pieces: the channel-agnostic tokenizer
|
| 30 |
-
|
| 31 |
-
`model_sleep_staging/best.pth`. This file **merges both**, so a single call
|
| 32 |
-
model that is pretrained end to end, its five-class output layer included.
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
| 35 |
|
| 36 |
The upstream artifacts themselves are kept, byte-for-byte, in
|
| 37 |
[`braindecode/SleepFM`](https://huggingface.co/braindecode/SleepFM).
|
|
@@ -41,17 +43,41 @@ The upstream artifacts themselves are kept, byte-for-byte, in
|
|
| 41 |
```python
|
| 42 |
from braindecode.models import SleepFMStager
|
| 43 |
|
| 44 |
-
# Defaults to this repository.
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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).**
|
|
|
|
| 23 |
|
| 24 |
| File | Description |
|
| 25 |
|------|-------------|
|
| 26 |
+
| `model.safetensors` | The complete stager (180 tensors: tokenizer, channel pooling, temporal Transformer and staging head), 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 encoder (channel-agnostic tokenizer,
|
| 30 |
+
channel pooling and temporal Transformer) lives in `model_base/best.pt` and the staging
|
| 31 |
+
head in `model_sleep_staging/best.pth`. This file **merges both**, so a single call
|
| 32 |
+
returns a model that is pretrained end to end, its five-class output layer included. It
|
| 33 |
+
holds the whole encoder except its trial-level temporal pooling, which sleep staging does
|
| 34 |
+
not use. The tensors are those of the upstream artifacts; only the keys were rewritten to
|
| 35 |
+
the library's parameter names. Loading this file or the two upstream ones gives
|
| 36 |
+
bit-identical outputs.
|
| 37 |
|
| 38 |
The upstream artifacts themselves are kept, byte-for-byte, in
|
| 39 |
[`braindecode/SleepFM`](https://huggingface.co/braindecode/SleepFM).
|
|
|
|
| 43 |
```python
|
| 44 |
from braindecode.models import SleepFMStager
|
| 45 |
|
| 46 |
+
# Defaults to this repository. The release encodes BAS, RESP, EKG and EMG
|
| 47 |
+
# channels as separate modalities; name the modality of each channel.
|
| 48 |
+
model = SleepFMStager.from_pretrained(
|
| 49 |
+
n_chans=7,
|
| 50 |
+
n_outputs=5,
|
| 51 |
+
n_times=38400,
|
| 52 |
+
sfreq=128,
|
| 53 |
+
channel_modalities=["BAS"] * 3 + ["RESP"] * 2 + ["EKG", "EMG"],
|
| 54 |
+
)
|
| 55 |
model.eval()
|
| 56 |
```
|
| 57 |
|
| 58 |
+
`config.json` leaves `channel_modalities` unset (`null`), because it depends on the
|
| 59 |
+
montage. Without it every channel is encoded as a single modality and `from_pretrained`
|
| 60 |
+
warns.
|
| 61 |
+
|
| 62 |
The output has shape `(batch, n_outputs, n_patches)`: one prediction per **5-second
|
| 63 |
patch**, not per 30-second scoring epoch, so six predictions cover one scored epoch. For
|
| 64 |
this checkpoint the five classes are Wake, N1, N2, N3 and REM. Input must be sampled at
|
| 65 |
**128 Hz**. Pass `n_outputs` different from 5 to reinitialise the output layer for another
|
| 66 |
label set.
|
| 67 |
|
| 68 |
+
## Revisions
|
| 69 |
+
|
| 70 |
+
- [`8681fba`](https://huggingface.co/braindecode/SleepFMStager/tree/8681fbade497e2ce103e1b68b01fbb3d56e809f2):
|
| 71 |
+
tokenizer and staging head only (93 tensors). `SleepFMStager.from_pretrained` reads the
|
| 72 |
+
encoder's channel pooling and temporal Transformer from
|
| 73 |
+
[`braindecode/SleepFM`](https://huggingface.co/braindecode/SleepFM) at load time.
|
| 74 |
+
- Current revision: the complete stager (180 tensors), bit-identical to the upstream
|
| 75 |
+
`model_base/best.pt` + `model_sleep_staging/best.pth`, re-exported with the fixed port of
|
| 76 |
+
braindecode PR #1106. `config.json` now lists every constructor argument; the defaults
|
| 77 |
+
(`n_chans=4`, `n_times=3840`, `sfreq=128`) are unchanged. Its outputs are bit-identical to
|
| 78 |
+
those of `8681fba` completed from `braindecode/SleepFM`, and both revisions load with
|
| 79 |
+
`SleepFMStager.from_pretrained` (pass `revision=` to pin one).
|
| 80 |
+
|
| 81 |
## License & attribution
|
| 82 |
|
| 83 |
- **License: Creative Commons Attribution-NonCommercial 4.0 International (CC BY-NC 4.0).**
|
config.json
CHANGED
|
@@ -5,12 +5,19 @@
|
|
| 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 |
}
|
|
|
|
| 5 |
"n_times": 3840,
|
| 6 |
"input_window_seconds": null,
|
| 7 |
"sfreq": 128.0,
|
| 8 |
+
"channel_modalities": null,
|
| 9 |
"patch_size": 640,
|
| 10 |
"embed_dim": 128,
|
| 11 |
+
"encoder_num_heads": 8,
|
| 12 |
+
"encoder_num_layers": 6,
|
| 13 |
+
"encoder_pooling_heads": 8,
|
| 14 |
+
"encoder_drop_prob": 0.0,
|
| 15 |
+
"encoder_chunk_patches": 60,
|
| 16 |
"staging_num_heads": 4,
|
| 17 |
"staging_num_layers": 1,
|
| 18 |
"staging_pooling_heads": 4,
|
| 19 |
"drop_prob": 0.3,
|
| 20 |
"max_seq_length": 8196,
|
| 21 |
+
"activation": "torch.nn.modules.activation.ELU",
|
| 22 |
+
"braindecode_version": "1.8.1"
|
| 23 |
}
|
model.safetensors
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6a0cdbee2fc6eaf5383cc85984f0b30f4911ac8ca6254ddd5bb1fbecdad3039a
|
| 3 |
+
size 26383332
|