bruAristimunha's picture
Rename the 6 channel-compressor keys (ffn_norm, FeedForwardBlock) and list projection_dims as the inner widths (braindecode#1748)
95905fb verified
|
Raw History Blame Contribute Delete
5.11 kB
---
license: other
library_name: braindecode
tags:
- 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`.
```python
from 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=(192, 96)`). 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, each
chromophore z-scored per recording over all its valid channels and time points, in windows of at
most 150 samples (30 s, the 15 rows of the temporal position embedding). `chs_info` gives each
HbO/HbR pair the positions of its source and detector (`loc[3:9]`, where MNE stores them); a NaN
marks a missing sample.
## Changes from the original release
`convert.py` unwraps the `{"model", "config"}` payload, builds the model from its `config`, drops
the two pretraining decoders (`hbo_to_hbr_decoder`, `hbr_to_hbo_decoder`: 122 of the 381
tensors), renames 6 tensors of the channel compressor and writes the encoder with `save_pretrained`.
The renames are plain prefix replacements: braindecode builds the compressor's feed-forward block from
a LayerNorm (`ffn_norm`) and its shared `FeedForwardBlock` (Linear, activation, dropout, Linear).
| original key | this repository | keys |
|---|---|---|
| `channel_compressor.ffn.0.{weight,bias}` (LayerNorm) | `channel_compressor.ffn_norm.{weight,bias}` | 2 |
| `channel_compressor.ffn.1.{weight,bias}` (Linear) | `channel_compressor.ffn.0.{weight,bias}` | 2 |
| `channel_compressor.ffn.4.{weight,bias}` (Linear) | `channel_compressor.ffn.3.{weight,bias}` | 2 |
The other 253 keys keep their names. `config.json` lists `projection_dims=[192, 96]`, the inner
widths of the chromophore projections: they run over `(embed_dim, *projection_dims, feature_dim)`, which is
the `projection_dimensions` `[384, 192, 96, 128]` of the original config. It also lists, at their defaults, the
numbers the original code fixes: `geometry_mlp_ratio` and `compressor_mlp_ratio` (2.0), `geometry_scale`
(0.02546058255683924, that is 25.46 mm), `time_embedding_init_std` and `latent_init_std` (0.02) and
`residual_init_scale` (0.1).
No value is changed: each of the 259 tensors is bitwise equal to its tensor in the original file (the six
renamed ones under their new names). This layout replaces revision `f51061d5`, which holds the same
tensors under the authors' names.
## Verification
`GeoNIRS.from_pretrained` on these files (braindecode `32850d0b`) against braindecode's `GeoNIRS` on
revision `f51061d5` (master before the renames, `252a0172`), on CPU and the same seeded inputs: the pinned
input, a batch with NaN samples and a `ch_mask`, `pool="mean_std"` at 60 samples, MNE-ordered `chs_info`
and an explicit `geometry`. In float32 and in float64 the features, the outputs (same head), the tokens
and their validity, and the features and outputs in train mode under one seed (the dropout draws) are
bitwise equal: 60 of 60 comparisons, max abs difference 0.0. A change of 1e-3 in one value of each renamed
tensor shows as a difference of 1e-5 or more in the features.
## 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},
}
```
## Conversion
`convert.py` (in this repository) was run with braindecode at `32850d0b`:
```
python convert.py geonirs_large.pt <out_dir>
```
| file | sha256 |
|---|---|
| `model.safetensors` | `85d1d8134d414e921be39946d75f1560ec4e116161f389c01437af5cee133710` |
| `config.json` | `1e70306521d99e35815737ae19a15fa31415cd633e7d8f23c0e7e984f650edbc` |
| `convert.py` | `6e0e62f7f26b00143fed34aef3e6f95961598971df0fa66013654cf55747f8a5` |
| original `checkpoint/geonirs_large.pt` (GeoNIRS/GeoNIRS@81f8995, Git LFS) | `81c2d513ee835b0b9056fb9c1c0ce75e3fa5cdaf46fda24d2ddfaf4436e346ce` |