GeoNIRS-Large encoder converted from GeoNIRS/GeoNIRS@81f8995
Browse filesFiles changed (4)
- README.mdAdded+65
- config.jsonAdded+34
- convert.pyAdded+57
- model.safetensorsAdded+3
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465---license: otherlibrary_name: braindecodetags:- braindecode- pytorch- safetensors- fnirs- geonirs- foundation-model---
# GeoNIRS-Large (pretrained encoder)
Weights of GeoNIRS-Large, the geometry-aware fNIRS foundation model of Li et al. (2026), for[`braindecode.models.GeoNIRS`](https://braindecode.org/stable/generated/braindecode.models.GeoNIRS.html).They are the encoder of `checkpoint/geonirs_large.pt` of[GeoNIRS/GeoNIRS](https://github.com/GeoNIRS/GeoNIRS/tree/81f8995e5c3aa6b70e55812b194fc04e4e7ea5b7/checkpoint)at commit `81f8995`, pretrained on 22 datasets (827.04 h), converted by `convert.py`.
```pythonfrom braindecode.models import GeoNIRS
model = GeoNIRS.from_pretrained( "braindecode/geonirs-large-pretrained", chs_info=raw.info["chs"], n_outputs=2, n_times=60,)features = model(x, return_features=True)["features"]```
`config.json` holds the sizes of GeoNIRS-Large (`embed_dim=384`, `depth=6`, `num_heads=12`,`feature_dim=128`, `projection_dims=(384, 192, 96, 128)`). The classification head(`final_layer`) is not part of the release: it reads `2 * n_latent_channels * n_patches *feature_dim` features, so `from_pretrained` builds it for your `n_times` and `n_outputs`.Fine-tune or linear-probe before use.
## Intended input
The inputs of the GeoNIRS paper (Appendix B.1): HbO and HbR in µmol/L resampled to 5 Hz, eachchromophore z-scored per recording over all its valid channels and time points, in windows of atmost 150 samples (30 s, the 15 rows of the temporal position embedding). `chs_info` gives eachHbO/HbR pair the positions of its source and detector (`loc[3:9]`, where MNE stores them); a NaNmarks a missing sample.
## Changes from the original release
`convert.py` unwraps the `{"model", "config"}` payload, builds the model from its `config`, dropsthe two pretraining decoders (`hbo_to_hbr_decoder`, `hbr_to_hbo_decoder`) and writes the encoderwith `save_pretrained`. No value is changed: the encoder gives the features of the original filebit for bit on CPU in float32.
## License and citation
The source repository has no licence file; the weights are by the GeoNIRS authors. Please cite:
```bibtex@article{li2026geonirs, author = {Li, Zongsheng and Zhu, Shengyuan and Zhang, Zimo and Li, Hanyao and Wang, Shengming and Liu, Quanying}, title = {{GeoNIRS}: Geometry-Aware Pretraining for Heterogeneous {fNIRS} Representation Learning}, journal = {arXiv preprint arXiv:2610.17845}, year = {2026},}```12345678910111213141516171819202122232425262728293031323334{ "n_outputs": 2, "n_chans": 2, "chs_info": null, "n_times": 150, "input_window_seconds": null, "sfreq": 5.0, "patch_size": 10, "max_patches": 15, "on_non_divisible": "error", "embed_dim": 384, "num_heads": 12, "depth": 6, "mlp_ratio": 4.0, "geometry_hidden_dim": 384, "geometry_heads": 12, "n_latent_channels": 16, "compressor_heads": 12, "feature_dim": 128, "projection_dims": [ 384, 192, 96, 128 ], "use_channel_geometry": true, "pool": "flatten", "channel_order": null, "drop_prob": 0.1, "head_drop_prob": 0.1, "minimum_patch_valid_fraction": 0.8, "activation": "torch.nn.modules.activation.GELU", "braindecode_version": "2.1.0dev0"}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657"""Convert ``checkpoint/geonirs_{base,large}.pt`` (GeoNIRS/GeoNIRS@81f8995) to braindecode's ``GeoNIRS``.
usage: python convert.py <geonirs_base.pt or geonirs_large.pt> <out_dir>
Unwraps the ``{"model", "config"}`` payload, builds the model from its``config`` for the 30 s pretraining windows (150 samples at 5 Hz), drops thetwo pretraining decoders (``hbo_to_hbr_decoder``, ``hbr_to_hbo_decoder``) andwrites ``config.json`` and ``model.safetensors`` with``GeoNIRS.save_pretrained``. The release holds the encoder only: the headreads ``2 * n_latent_channels * n_patches * feature_dim`` features, so``from_pretrained`` builds it for the caller's ``n_times`` and ``n_outputs``."""
import osimport sys
import torchfrom safetensors.torch import save_file
from braindecode.models import GeoNIRS
DECODERS = ("hbo_to_hbr_decoder.", "hbr_to_hbo_decoder.")
if __name__ == "__main__": src, out_dir = sys.argv[1:] payload = torch.load(src, map_location="cpu", weights_only=True) data, config = payload["config"]["data"], payload["config"]["model"] # braindecode's GeoNIRS has a 6-D geometry and one geometry layer assert config["geometry_dim"] == 6 and config["geometry_spatial_layers"] == 1 encoder = {k: v for k, v in payload["model"].items() if not k.startswith(DECODERS)} torch.manual_seed(0) model = GeoNIRS( n_chans=2, n_outputs=2, n_times=round(data["window_seconds"] * data["sampling_rate_hz"]), sfreq=data["sampling_rate_hz"], patch_size=data["patch_samples"], minimum_patch_valid_fraction=data["minimum_patch_valid_fraction"], embed_dim=config["embedding_dim"], depth=config["temporal_layers"], num_heads=config["num_heads"], mlp_ratio=config["mlp_ratio"], drop_prob=config["dropout"], geometry_hidden_dim=config["geometry_hidden_dim"], geometry_heads=config["geometry_heads"], n_latent_channels=config["num_latent_sources"], compressor_heads=config["spatial_heads"], feature_dim=config["output_feature_dim"], projection_dims=tuple(config["projection_dimensions"]), ) missing, unexpected = model.load_state_dict(encoder, strict=False) assert not unexpected, unexpected assert all(key.startswith("final_layer.") for key in missing), missing model.save_pretrained(out_dir) os.remove(os.path.join(out_dir, "pytorch_model.bin")) weights = {k: v for k, v in model.state_dict().items() if not k.startswith("final_layer.")} save_file(weights, os.path.join(out_dir, "model.safetensors"), metadata={"format": "pt"})123version https://git-lfs.github.com/spec/v1oid sha256:1ae128345816a6f72ac529ee8981260c63778e65d53f680240fffdc26ef45681size 97607816README.mdAdded+65
config.jsonAdded+34
convert.pyAdded+57
model.safetensorsAdded+3