bruAristimunha commited on
Commit
812892c
·
verified ·
1 Parent(s): c4e2e6f

JungMAE encoder converted from GeoNIRS/GeoNIRS@81f8995 checkpoint/jung_mae.pt

Browse files
Files changed (4) hide show
  1. README.md +67 -0
  2. config.json +22 -0
  3. convert.py +35 -0
  4. model.safetensors +3 -0
README.md ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: other
3
+ library_name: braindecode
4
+ tags:
5
+ - braindecode
6
+ - pytorch
7
+ - safetensors
8
+ - fnirs
9
+ - masked-autoencoder
10
+ - foundation-model
11
+ ---
12
+
13
+ # JungMAE (pretrained encoder, GeoNIRS release)
14
+
15
+ Weights of the masked-autoencoder fNIRS foundation model of Jung, Lee and An (2025), as
16
+ implemented and trained by the GeoNIRS authors (Li et al., 2026), for
17
+ [`braindecode.models.JungMAE`](https://braindecode.org/stable/generated/braindecode.models.JungMAE.html).
18
+ They are the encoder of `checkpoint/jung_mae.pt` of
19
+ [GeoNIRS/GeoNIRS](https://github.com/GeoNIRS/GeoNIRS/tree/81f8995e5c3aa6b70e55812b194fc04e4e7ea5b7/checkpoint)
20
+ at commit `81f8995`, converted by `convert.py`.
21
+
22
+ ```python
23
+ from braindecode.models import JungMAE
24
+
25
+ model = JungMAE.from_pretrained(
26
+ "braindecode/jungmae-pretrained", n_chans=40, n_outputs=2, n_times=60
27
+ )
28
+ features = model(x, return_features=True)["features"]
29
+ ```
30
+
31
+ The classification head (`final_layer`) is not part of the release: it reads
32
+ `n_chans * n_patches * embed_dim` features, so `from_pretrained` builds it for your montage and
33
+ `n_outputs`. Fine-tune or linear-probe before use.
34
+
35
+ ## Intended input
36
+
37
+ The inputs of the GeoNIRS paper (Appendix B.1): HbO and HbR in µmol/L resampled to 5 Hz, each
38
+ chromophore z-scored per recording over all its valid channels and time points.
39
+
40
+ ## Changes from the original release
41
+
42
+ `convert.py` unwraps the `{"model", "model_config", ...}` payload (its configuration equals the
43
+ class defaults), drops the pretraining decoder (input projection, mask token, layers, prediction
44
+ layer) and writes the encoder with `save_pretrained`. No value is changed: the encoder gives the
45
+ features of the original file bit for bit on CPU in float32.
46
+
47
+ ## License and citation
48
+
49
+ The source repository has no licence file; the weights are by the GeoNIRS authors. Please cite
50
+ the method and the release:
51
+
52
+ ```bibtex
53
+ @inproceedings{jung2025mae,
54
+ author = {Jung, Euijin and Lee, Hyunmin and An, Jinung},
55
+ title = {{fNIRS} Foundation Model for Few-Shot Based {fNIRS} Classification},
56
+ booktitle = {2025 13th International Conference on Brain-Computer Interface (BCI)},
57
+ year = {2025},
58
+ doi = {10.1109/BCI65088.2025.10931275},
59
+ }
60
+
61
+ @article{li2026geonirs,
62
+ author = {Li, Zongsheng and Zhu, Shengyuan and Zhang, Zimo and Li, Hanyao and Wang, Shengming and Liu, Quanying},
63
+ title = {{GeoNIRS}: Geometry-Aware Pretraining for Heterogeneous {fNIRS} Representation Learning},
64
+ journal = {arXiv preprint arXiv:2610.17845},
65
+ year = {2026},
66
+ }
67
+ ```
config.json ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "n_outputs": 2,
3
+ "n_chans": 40,
4
+ "chs_info": null,
5
+ "n_times": 60,
6
+ "input_window_seconds": null,
7
+ "sfreq": 5.0,
8
+ "patch_size": 10,
9
+ "embed_dim": 192,
10
+ "depth": 4,
11
+ "num_heads": 8,
12
+ "mlp_ratio": 4.0,
13
+ "drop_prob": 0.1,
14
+ "head_drop_prob": 0.1,
15
+ "minimum_patch_valid_fraction": 0.8,
16
+ "activation": "torch.nn.modules.activation.GELU",
17
+ "channel_order": null,
18
+ "on_non_divisible": "error",
19
+ "channel_strategy": "native",
20
+ "channel_strategy_kwargs": null,
21
+ "braindecode_version": "2.1.0dev0"
22
+ }
convert.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Convert ``checkpoint/jung_mae.pt`` (GeoNIRS/GeoNIRS@81f8995) to braindecode's ``JungMAE``.
2
+
3
+ usage: python convert.py <jung_mae.pt> <out_dir>
4
+
5
+ Unwraps the ``{"model", "model_config", ...}`` payload (its configuration equals
6
+ the class defaults), drops the pretraining decoder (input projection, mask token,
7
+ layers, prediction layer) and writes ``config.json`` and ``model.safetensors``
8
+ with ``JungMAE.save_pretrained`` for the paper's 40 channels of 60 samples at
9
+ 5 Hz. The release holds the encoder only: the head reads ``C * P * D`` features,
10
+ so ``from_pretrained`` builds it for the caller's montage and ``n_outputs``.
11
+ """
12
+
13
+ import os
14
+ import sys
15
+
16
+ import torch
17
+ from safetensors.torch import save_file
18
+
19
+ from braindecode.models import JungMAE
20
+
21
+ DECODER = ("decoder_embed.", "mask_token", "decoder.", "prediction.")
22
+
23
+ if __name__ == "__main__":
24
+ src, out_dir = sys.argv[1:]
25
+ payload = torch.load(src, map_location="cpu", weights_only=True)
26
+ encoder = {k: v for k, v in payload["model"].items() if not k.startswith(DECODER)}
27
+ torch.manual_seed(0)
28
+ model = JungMAE(n_chans=40, n_outputs=2, n_times=60, sfreq=5.0)
29
+ missing, unexpected = model.load_state_dict(encoder, strict=False)
30
+ assert not unexpected, unexpected
31
+ assert all(key.startswith("final_layer.") for key in missing), missing
32
+ model.save_pretrained(out_dir)
33
+ os.remove(os.path.join(out_dir, "pytorch_model.bin"))
34
+ weights = {k: v for k, v in model.state_dict().items() if not k.startswith("final_layer.")}
35
+ save_file(weights, os.path.join(out_dir, "model.safetensors"))
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b36dcf5babad04f3488578a61276d20e6f711fb8e73d90bb23d7c38fac90b552
3
+ size 7140632